|
1 #include <graph_displayer_canvas.h> |
|
2 #include <broken_edge.h> |
|
3 #include <math.h> |
|
4 |
|
5 |
|
6 int GraphDisplayerCanvas::changeLineWidth (std::string mapname) |
|
7 { |
|
8 for (EdgeIt i(g); i!=INVALID; ++i) |
|
9 { |
|
10 int w=(int)(*(mapstorage.edgemap_storage)[mapname])[i]; |
|
11 if(w>=0) |
|
12 { |
|
13 edgesmap[i]->property_width_pixels().set_value(w); |
|
14 } |
|
15 } |
|
16 return 0; |
|
17 }; |
|
18 |
|
19 int GraphDisplayerCanvas::changeColor (std::string mapname) |
|
20 { |
|
21 |
|
22 //function maps the range of the maximum and |
|
23 //the minimum of the nodemap to the range of |
|
24 //green in RGB |
|
25 |
|
26 for (EdgeIt i(g); i!=INVALID; ++i) |
|
27 { |
|
28 double w=(*(mapstorage.edgemap_storage)[mapname])[i]; |
|
29 double max=mapstorage.maxOfEdgeMap(mapname); |
|
30 double min=mapstorage.minOfEdgeMap(mapname); |
|
31 |
|
32 //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl; |
|
33 Gdk::Color color; |
|
34 if(max!=min) |
|
35 { |
|
36 color.set_rgb_p (0, 100*(w-min)/(max-min), 0); |
|
37 } |
|
38 else |
|
39 { |
|
40 color.set_rgb_p (0, 100, 0); |
|
41 } |
|
42 |
|
43 edgesmap[i]->property_fill_color_gdk().set_value(color); |
|
44 } |
|
45 return 0; |
|
46 }; |
|
47 |
|
48 int GraphDisplayerCanvas::changeText (std::string mapname) |
|
49 { |
|
50 |
|
51 //the number in the map will be written on the edge |
|
52 //EXCEPT when the name of the map is Text, because |
|
53 //in that case empty string will be written, because |
|
54 //that is the deleter map |
|
55 //\todo isn't it a bit woodcutter? |
|
56 |
|
57 for (EdgeIt i(g); i!=INVALID; ++i) |
|
58 { |
|
59 if(mapname!="Text") |
|
60 { |
|
61 double number=(*(mapstorage.edgemap_storage)[mapname])[i]; |
|
62 int length=1; |
|
63 //if number is smaller than one, length would be negative, or invalid |
|
64 if(number>=1) |
|
65 { |
|
66 length=(int)(floor(log(number)/log(10)))+1; |
|
67 } |
|
68 int maxpos=(int)(pow(10,length-1)); |
|
69 int strl=length+1+RANGE; |
|
70 char * str=new char[strl]; |
|
71 str[length]='.'; |
|
72 str[strl]='\0'; |
|
73 |
|
74 for(int j=0;j<strl;j++) |
|
75 { |
|
76 if(j!=length) |
|
77 { |
|
78 int digit=(int)(number/maxpos); |
|
79 str[j]=(digit+'0'); |
|
80 number-=digit*maxpos; |
|
81 number*=10; |
|
82 } |
|
83 } |
|
84 |
|
85 edgetextmap[i]->property_text().set_value(str); |
|
86 } |
|
87 else |
|
88 { |
|
89 edgetextmap[i]->property_text().set_value(""); |
|
90 } |
|
91 } |
|
92 return 0; |
|
93 }; |