1 #include "graph_displayer_canvas.h"
4 const int minimum_node_radius=5;
6 int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Node node)
8 Graph::NodeMap<double> * actual_map;
10 min=(mytab.mapstorage).minOfNodeMap(mapname);
11 max=(mytab.mapstorage).maxOfNodeMap(mapname);
12 actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
16 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
18 double v=fabs((*actual_map)[i]);
24 w=(int)(node_property_defaults[N_RADIUS]);
28 w=(int)(minimum_node_radius+(v-min)/(max-min)*(radius_size-minimum_node_radius));
33 w=(int)(v*radius_size);
36 if(w<minimum_node_radius)
38 w=minimum_node_radius;
43 double actual_ppu=get_pixels_per_unit();
44 w=(int)(w/actual_ppu*fixed_zoom_factor);
49 double x1, y1, x2, y2;
50 x1=nodesmap[i]->property_x1().get_value();
51 x2=nodesmap[i]->property_x2().get_value();
52 y1=nodesmap[i]->property_y1().get_value();
53 y2=nodesmap[i]->property_y2().get_value();
54 nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
55 nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
56 nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
57 nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
63 //I think only new nodes use this case
64 //that has no own value, only the default one
65 //int w=(int)(*actual_map)[node];
66 int w=(int)(node_property_defaults[N_RADIUS]);
69 double x1, y1, x2, y2;
70 x1=nodesmap[node]->property_x1().get_value();
71 x2=nodesmap[node]->property_x2().get_value();
72 y1=nodesmap[node]->property_y1().get_value();
73 y2=nodesmap[node]->property_y2().get_value();
74 nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
75 nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
76 nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
77 nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
83 int GraphDisplayerCanvas::resetNodeRadius (Node node)
86 min=node_property_defaults[N_RADIUS];
87 max=node_property_defaults[N_RADIUS];
88 Graph::NodeMap<double> actual_map((mytab.mapstorage).graph,node_property_defaults[N_RADIUS]);
92 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
94 double v=fabs(actual_map[i]);
98 w=(int)(node_property_defaults[N_RADIUS]);
102 w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS));
106 double actual_ppu=get_pixels_per_unit();
107 w=(int)(w/actual_ppu*fixed_zoom_factor);
111 double x1, y1, x2, y2;
112 x1=nodesmap[i]->property_x1().get_value();
113 x2=nodesmap[i]->property_x2().get_value();
114 y1=nodesmap[i]->property_y1().get_value();
115 y2=nodesmap[i]->property_y2().get_value();
116 nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
117 nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
118 nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
119 nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
125 //I think only new nodes use this case
126 // int w=(int)actual_map[node];
127 int w=(int)(node_property_defaults[N_RADIUS]);
130 double x1, y1, x2, y2;
131 x1=nodesmap[node]->property_x1().get_value();
132 x2=nodesmap[node]->property_x2().get_value();
133 y1=nodesmap[node]->property_y1().get_value();
134 y2=nodesmap[node]->property_y2().get_value();
135 nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
136 nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
137 nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
138 nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
144 int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Node node)
147 //function maps the range of the maximum and
148 //the minimum of the nodemap to the range of
151 Graph::NodeMap<double> * actual_map;
152 actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
156 max=(mytab.mapstorage).maxOfNodeMap(mapname);
157 min=(mytab.mapstorage).minOfNodeMap(mapname);
162 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
166 double w=(*actual_map)[i];
170 color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
174 color.set_rgb_p (0, 0, 100);
177 nodesmap[i]->property_fill_color_gdk().set_value(color);
184 double w=(*actual_map)[node];
188 color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
192 color.set_rgb_p (0, 0, 100);
195 nodesmap[node]->property_fill_color_gdk().set_value(color);
200 int GraphDisplayerCanvas::resetNodeColor (Node node)
203 //function maps the range of the maximum and
204 //the minimum of the nodemap to the range of
207 Graph::NodeMap<double> actual_map((mytab.mapstorage).graph,node_property_defaults[N_COLOR]);
211 max=node_property_defaults[N_COLOR];
212 min=node_property_defaults[N_COLOR];
217 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
221 double w=actual_map[i];
225 color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
229 color.set_rgb_p (0, 0, 100);
232 nodesmap[i]->property_fill_color_gdk().set_value(color);
239 double w=actual_map[node];
243 color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
247 color.set_rgb_p (0, 0, 100);
250 nodesmap[node]->property_fill_color_gdk().set_value(color);
255 int GraphDisplayerCanvas::changeNodeText (std::string mapname, Node node)
258 //the number in the map will be written on the node
259 //EXCEPT when the name of the map is Text, because
260 //in that case empty string will be written, because
261 //that is the deleter map
263 Graph::NodeMap<double> * actual_map=NULL;
264 actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
268 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
270 nodemap_to_edit=mapname;
271 double number=(*actual_map)[i];
273 std::ostringstream ostr;
276 nodetextmap[i]->property_text().set_value(ostr.str());
281 double number=(*actual_map)[node];
283 std::ostringstream ostr;
286 nodetextmap[node]->property_text().set_value(ostr.str());
291 int GraphDisplayerCanvas::resetNodeText (Node node)
294 //the number in the map will be written on the node
295 //EXCEPT when the name of the map is Text, because
296 //in that case empty string will be written, because
297 //that is the deleter map
301 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
304 nodetextmap[i]->property_text().set_value("");
309 nodetextmap[node]->property_text().set_value("");