No segmentation fault caused by zero long edges.
1 #include "graph_displayer_canvas.h"
5 int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Node node)
7 Graph::NodeMap<double> * actual_map;
9 min=mapstorage.minOfNodeMap(mapname);
10 max=mapstorage.maxOfNodeMap(mapname);
11 actual_map=(mapstorage.nodemap_storage)[mapname];
15 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
17 double v=fabs((*actual_map)[i]);
21 w=(int)(node_property_defaults[N_RADIUS]);
25 w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS));
29 double x1, y1, x2, y2;
30 x1=nodesmap[i]->property_x1().get_value();
31 x2=nodesmap[i]->property_x2().get_value();
32 y1=nodesmap[i]->property_y1().get_value();
33 y2=nodesmap[i]->property_y2().get_value();
34 nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
35 nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
36 nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
37 nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
43 //I think only new nodes use this case
44 // int w=(int)(*actual_map)[node];
45 int w=(int)(node_property_defaults[N_RADIUS]);
48 double x1, y1, x2, y2;
49 x1=nodesmap[node]->property_x1().get_value();
50 x2=nodesmap[node]->property_x2().get_value();
51 y1=nodesmap[node]->property_y1().get_value();
52 y2=nodesmap[node]->property_y2().get_value();
53 nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
54 nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
55 nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
56 nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
62 int GraphDisplayerCanvas::resetNodeRadius (Node node)
65 min=node_property_defaults[N_RADIUS];
66 max=node_property_defaults[N_RADIUS];
67 Graph::NodeMap<double> actual_map(mapstorage.graph,node_property_defaults[N_RADIUS]);
71 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
73 double v=fabs(actual_map[i]);
77 w=(int)(node_property_defaults[N_RADIUS]);
81 w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS));
85 double x1, y1, x2, y2;
86 x1=nodesmap[i]->property_x1().get_value();
87 x2=nodesmap[i]->property_x2().get_value();
88 y1=nodesmap[i]->property_y1().get_value();
89 y2=nodesmap[i]->property_y2().get_value();
90 nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
91 nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
92 nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
93 nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
99 //I think only new nodes use this case
100 // int w=(int)actual_map[node];
101 int w=(int)(node_property_defaults[N_RADIUS]);
104 double x1, y1, x2, y2;
105 x1=nodesmap[node]->property_x1().get_value();
106 x2=nodesmap[node]->property_x2().get_value();
107 y1=nodesmap[node]->property_y1().get_value();
108 y2=nodesmap[node]->property_y2().get_value();
109 nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
110 nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
111 nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
112 nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
118 int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Node node)
121 //function maps the range of the maximum and
122 //the minimum of the nodemap to the range of
125 Graph::NodeMap<double> * actual_map;
126 actual_map=(mapstorage.nodemap_storage)[mapname];
130 max=mapstorage.maxOfNodeMap(mapname);
131 min=mapstorage.minOfNodeMap(mapname);
136 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
140 double w=(*actual_map)[i];
144 color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
148 color.set_rgb_p (0, 0, 100);
151 nodesmap[i]->property_fill_color_gdk().set_value(color);
158 double w=(*actual_map)[node];
162 color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
166 color.set_rgb_p (0, 0, 100);
169 nodesmap[node]->property_fill_color_gdk().set_value(color);
174 int GraphDisplayerCanvas::resetNodeColor (Node node)
177 //function maps the range of the maximum and
178 //the minimum of the nodemap to the range of
181 Graph::NodeMap<double> actual_map(mapstorage.graph,node_property_defaults[N_COLOR]);
185 max=node_property_defaults[N_COLOR];
186 min=node_property_defaults[N_COLOR];
191 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
195 double w=actual_map[i];
199 color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
203 color.set_rgb_p (0, 0, 100);
206 nodesmap[i]->property_fill_color_gdk().set_value(color);
213 double w=actual_map[node];
217 color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
221 color.set_rgb_p (0, 0, 100);
224 nodesmap[node]->property_fill_color_gdk().set_value(color);
229 int GraphDisplayerCanvas::changeNodeText (std::string mapname, Node node)
232 //the number in the map will be written on the node
233 //EXCEPT when the name of the map is Text, because
234 //in that case empty string will be written, because
235 //that is the deleter map
237 Graph::NodeMap<double> * actual_map=NULL;
238 actual_map=(mapstorage.nodemap_storage)[mapname];
242 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
244 nodemap_to_edit=mapname;
245 double number=(*actual_map)[i];
247 std::ostringstream ostr;
250 nodetextmap[i]->property_text().set_value(ostr.str());
255 double number=(*actual_map)[node];
257 std::ostringstream ostr;
260 nodetextmap[node]->property_text().set_value(ostr.str());
265 int GraphDisplayerCanvas::resetNodeText (Node node)
268 //the number in the map will be written on the node
269 //EXCEPT when the name of the map is Text, because
270 //in that case empty string will be written, because
271 //that is the deleter map
275 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
278 nodetextmap[i]->property_text().set_value("");
283 nodetextmap[node]->property_text().set_value("");