Edge and nodemap edition is done.
1 #include <graph_displayer_canvas.h>
2 #include <broken_edge.h>
6 int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Graph::Node node)
8 Graph::NodeMap<double> * actual_map;
11 actual_map=new Graph::NodeMap<double>(g,node_property_defaults[N_RADIUS]);
15 actual_map=(mapstorage.nodemap_storage)[mapname];
20 for (NodeIt i(g); i!=INVALID; ++i)
22 int w=(int)(*actual_map)[i];
25 double x1, y1, x2, y2;
26 x1=nodesmap[i]->property_x1().get_value();
27 x2=nodesmap[i]->property_x2().get_value();
28 y1=nodesmap[i]->property_y1().get_value();
29 y2=nodesmap[i]->property_y2().get_value();
30 nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
31 nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
32 nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
33 nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
39 //I think only new nodes use this case
40 // int w=(int)(*actual_map)[node];
41 int w=(int)(node_property_defaults[N_RADIUS]);
44 double x1, y1, x2, y2;
45 x1=nodesmap[node]->property_x1().get_value();
46 x2=nodesmap[node]->property_x2().get_value();
47 y1=nodesmap[node]->property_y1().get_value();
48 y2=nodesmap[node]->property_y2().get_value();
49 nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
50 nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
51 nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
52 nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
58 int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Graph::Node node)
61 //function maps the range of the maximum and
62 //the minimum of the nodemap to the range of
65 Graph::NodeMap<double> * actual_map;
66 if(mapname=="Default")
68 actual_map=new Graph::NodeMap<double>(g,node_property_defaults[N_COLOR]);
72 actual_map=(mapstorage.nodemap_storage)[mapname];
77 if(mapname!="Default")
79 max=mapstorage.maxOfNodeMap(mapname);
80 min=mapstorage.minOfNodeMap(mapname);
84 max=node_property_defaults[N_COLOR];
85 min=node_property_defaults[N_COLOR];
92 for (NodeIt i(g); i!=INVALID; ++i)
96 double w=(*actual_map)[i];
100 color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
104 color.set_rgb_p (0, 0, 100);
107 nodesmap[i]->property_fill_color_gdk().set_value(color);
114 double w=(*actual_map)[node];
118 color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
122 color.set_rgb_p (0, 0, 100);
125 nodesmap[node]->property_fill_color_gdk().set_value(color);
130 int GraphDisplayerCanvas::changeNodeText (std::string mapname, Graph::Node node)
133 //the number in the map will be written on the node
134 //EXCEPT when the name of the map is Text, because
135 //in that case empty string will be written, because
136 //that is the deleter map
138 Graph::NodeMap<double> * actual_map;
139 if(mapname!="Default")
141 actual_map=(mapstorage.nodemap_storage)[mapname];
146 for (NodeIt i(g); i!=INVALID; ++i)
148 if(mapname!="Default")
150 nodemap_to_edit=mapname;
151 double number=(*actual_map)[i];
153 //if number is smaller than one, length would be negative, or invalid
156 length=(int)(floor(log(number)/log(10)))+1;
158 int maxpos=(int)(pow(10,length-1));
159 int strl=length+1+RANGE;
160 char * str=new char[strl];
164 for(int j=0;j<strl;j++)
168 int digit=(int)round(number/maxpos);
170 number-=digit*maxpos;
175 nodetextmap[i]->property_text().set_value(str);
180 nodetextmap[i]->property_text().set_value("");
186 if(mapname!="Default")
188 double number=(*actual_map)[node];
190 //if number is smaller than one, length would be negative, or invalid
193 length=(int)(floor(log(number)/log(10)))+1;
195 int maxpos=(int)(pow(10,length-1));
196 int strl=length+1+RANGE;
197 char * str=new char[strl];
201 for(int j=0;j<strl;j++)
205 int digit=(int)(number/maxpos);
207 number-=digit*maxpos;
212 nodetextmap[node]->property_text().set_value(str);
216 nodetextmap[node]->property_text().set_value("");