1 | #include <graph_displayer_canvas.h> |
---|
2 | #include <broken_edge.h> |
---|
3 | #include <math.h> |
---|
4 | |
---|
5 | |
---|
6 | int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Graph::Edge edge) |
---|
7 | { |
---|
8 | if(edge==INVALID) |
---|
9 | { |
---|
10 | for (EdgeIt i(g); i!=INVALID; ++i) |
---|
11 | { |
---|
12 | int w=(int)(*(mapstorage.edgemap_storage)[mapname])[i]; |
---|
13 | if(w>=0) |
---|
14 | { |
---|
15 | edgesmap[i]->property_width_pixels().set_value(w); |
---|
16 | } |
---|
17 | } |
---|
18 | } |
---|
19 | else |
---|
20 | { |
---|
21 | int w=(int)(*(mapstorage.edgemap_storage)[mapname])[edge]; |
---|
22 | if(w>=0) |
---|
23 | { |
---|
24 | edgesmap[edge]->property_width_pixels().set_value(w); |
---|
25 | } |
---|
26 | } |
---|
27 | return 0; |
---|
28 | }; |
---|
29 | |
---|
30 | int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Graph::Edge edge) |
---|
31 | { |
---|
32 | |
---|
33 | //function maps the range of the maximum and |
---|
34 | //the minimum of the nodemap to the range of |
---|
35 | //green in RGB |
---|
36 | if(edge==INVALID) |
---|
37 | { |
---|
38 | |
---|
39 | for (EdgeIt i(g); i!=INVALID; ++i) |
---|
40 | { |
---|
41 | double w=(*(mapstorage.edgemap_storage)[mapname])[i]; |
---|
42 | double max=mapstorage.maxOfEdgeMap(mapname); |
---|
43 | double min=mapstorage.minOfEdgeMap(mapname); |
---|
44 | |
---|
45 | //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl; |
---|
46 | Gdk::Color color; |
---|
47 | if(max!=min) |
---|
48 | { |
---|
49 | color.set_rgb_p (0, 100*(w-min)/(max-min), 0); |
---|
50 | } |
---|
51 | else |
---|
52 | { |
---|
53 | color.set_rgb_p (0, 100, 0); |
---|
54 | } |
---|
55 | |
---|
56 | edgesmap[i]->property_fill_color_gdk().set_value(color); |
---|
57 | } |
---|
58 | } |
---|
59 | else |
---|
60 | { |
---|
61 | double w=(*(mapstorage.edgemap_storage)[mapname])[edge]; |
---|
62 | double max=mapstorage.maxOfEdgeMap(mapname); |
---|
63 | double min=mapstorage.minOfEdgeMap(mapname); |
---|
64 | |
---|
65 | //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl; |
---|
66 | Gdk::Color color; |
---|
67 | if(max!=min) |
---|
68 | { |
---|
69 | color.set_rgb_p (0, 100*(w-min)/(max-min), 0); |
---|
70 | } |
---|
71 | else |
---|
72 | { |
---|
73 | color.set_rgb_p (0, 100, 0); |
---|
74 | } |
---|
75 | |
---|
76 | edgesmap[edge]->property_fill_color_gdk().set_value(color); |
---|
77 | } |
---|
78 | return 0; |
---|
79 | }; |
---|
80 | |
---|
81 | int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Graph::Edge edge) |
---|
82 | { |
---|
83 | |
---|
84 | //the number in the map will be written on the edge |
---|
85 | //EXCEPT when the name of the map is Text, because |
---|
86 | //in that case empty string will be written, because |
---|
87 | //that is the deleter map |
---|
88 | //\todo isn't it a bit woodcutter? |
---|
89 | |
---|
90 | if(edge==INVALID) |
---|
91 | { |
---|
92 | for (EdgeIt i(g); i!=INVALID; ++i) |
---|
93 | { |
---|
94 | if(mapname!=edge_property_strings[E_TEXT]) |
---|
95 | { |
---|
96 | double number=(*(mapstorage.edgemap_storage)[mapname])[i]; |
---|
97 | int length=1; |
---|
98 | //if number is smaller than one, length would be negative, or invalid |
---|
99 | if(number>=1) |
---|
100 | { |
---|
101 | length=(int)(floor(log(number)/log(10)))+1; |
---|
102 | } |
---|
103 | int maxpos=(int)(pow(10,length-1)); |
---|
104 | int strl=length+1+RANGE; |
---|
105 | char * str=new char[strl]; |
---|
106 | str[length]='.'; |
---|
107 | str[strl]='\0'; |
---|
108 | |
---|
109 | for(int j=0;j<strl;j++) |
---|
110 | { |
---|
111 | if(j!=length) |
---|
112 | { |
---|
113 | int digit=(int)(number/maxpos); |
---|
114 | str[j]=(digit+'0'); |
---|
115 | number-=digit*maxpos; |
---|
116 | number*=10; |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | edgetextmap[i]->property_text().set_value(str); |
---|
121 | } |
---|
122 | else |
---|
123 | { |
---|
124 | edgetextmap[i]->property_text().set_value(""); |
---|
125 | } |
---|
126 | } |
---|
127 | |
---|
128 | } |
---|
129 | else |
---|
130 | { |
---|
131 | if(mapname!=edge_property_strings[E_TEXT]) |
---|
132 | { |
---|
133 | double number=(*(mapstorage.edgemap_storage)[mapname])[edge]; |
---|
134 | int length=1; |
---|
135 | //if number is smaller than one, length would be negative, or invalid |
---|
136 | if(number>=1) |
---|
137 | { |
---|
138 | length=(int)(floor(log(number)/log(10)))+1; |
---|
139 | } |
---|
140 | int maxpos=(int)(pow(10,length-1)); |
---|
141 | int strl=length+1+RANGE; |
---|
142 | char * str=new char[strl]; |
---|
143 | str[length]='.'; |
---|
144 | str[strl]='\0'; |
---|
145 | |
---|
146 | for(int j=0;j<strl;j++) |
---|
147 | { |
---|
148 | if(j!=length) |
---|
149 | { |
---|
150 | int digit=(int)(number/maxpos); |
---|
151 | str[j]=(digit+'0'); |
---|
152 | number-=digit*maxpos; |
---|
153 | number*=10; |
---|
154 | } |
---|
155 | } |
---|
156 | |
---|
157 | edgetextmap[edge]->property_text().set_value(str); |
---|
158 | } |
---|
159 | else |
---|
160 | { |
---|
161 | edgetextmap[edge]->property_text().set_value(""); |
---|
162 | } |
---|
163 | |
---|
164 | } |
---|
165 | |
---|
166 | return 0; |
---|
167 | |
---|
168 | }; |
---|