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=NULL;
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 // std::cout << (number) << "-" << (int)number << "=" << (number)-(int)number << std::endl;
169 if((number-(int)number)>ALMOST_ONE)
171 // std::cout<<"rounding: " <<number<<std::endl;
172 number=round(number);
174 int digit=(int)(number/maxpos);
175 // std::cout << number << "/" << maxpos << "=" << digit << std::endl;
177 number-=digit*maxpos;
182 nodetextmap[i]->property_text().set_value(str);
187 nodetextmap[i]->property_text().set_value("");
193 if(mapname!="Default")
195 double number=(*actual_map)[node];
197 //if number is smaller than one, length would be negative, or invalid
200 length=(int)(floor(log(number)/log(10)))+1;
202 int maxpos=(int)(pow(10,length-1));
203 int strl=length+1+RANGE;
204 char * str=new char[strl];
208 for(int j=0;j<strl;j++)
212 if((number-(int)number)>ALMOST_ONE)
214 number=round(number);
216 int digit=(int)(number/maxpos);
218 number-=digit*maxpos;
223 nodetextmap[node]->property_text().set_value(str);
227 nodetextmap[node]->property_text().set_value("");