ladanyi@1606
|
1 |
#include "graph_displayer_canvas.h"
|
alpar@1632
|
2 |
#include <cmath>
|
hegyi@1510
|
3 |
|
hegyi@1510
|
4 |
|
hegyi@1731
|
5 |
int GraphDisplayerCanvas::resetEdgeWidth (Edge edge)
|
hegyi@1731
|
6 |
{
|
hegyi@1731
|
7 |
double min, max;
|
hegyi@1731
|
8 |
|
hegyi@1731
|
9 |
min=edge_property_defaults[E_WIDTH];
|
hegyi@1731
|
10 |
max=edge_property_defaults[E_WIDTH];
|
hegyi@1837
|
11 |
Graph::EdgeMap<double> actual_map((mainwin.mapstorage).graph,edge_property_defaults[E_WIDTH]);
|
hegyi@1731
|
12 |
|
hegyi@1731
|
13 |
if(edge==INVALID)
|
hegyi@1731
|
14 |
{
|
hegyi@1837
|
15 |
for (EdgeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
|
hegyi@1731
|
16 |
{
|
ladanyi@1825
|
17 |
double v=fabs(actual_map[i]);
|
hegyi@1731
|
18 |
int w;
|
hegyi@1731
|
19 |
if(min==max)
|
hegyi@1731
|
20 |
{
|
hegyi@1731
|
21 |
w=(int)(edge_property_defaults[E_WIDTH]);
|
hegyi@1731
|
22 |
}
|
hegyi@1731
|
23 |
else
|
hegyi@1731
|
24 |
{
|
hegyi@1731
|
25 |
w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH));
|
hegyi@1731
|
26 |
}
|
hegyi@1731
|
27 |
edgesmap[i]->property_width_units().set_value(w);
|
hegyi@1731
|
28 |
}
|
hegyi@1731
|
29 |
}
|
hegyi@1731
|
30 |
else
|
hegyi@1731
|
31 |
{
|
ladanyi@1825
|
32 |
int w=(int)actual_map[edge];
|
hegyi@1731
|
33 |
if(w>=0)
|
hegyi@1731
|
34 |
{
|
hegyi@1731
|
35 |
edgesmap[edge]->property_width_units().set_value(w);
|
hegyi@1731
|
36 |
}
|
hegyi@1731
|
37 |
}
|
hegyi@1731
|
38 |
return 0;
|
hegyi@1731
|
39 |
}
|
hegyi@1731
|
40 |
|
hegyi@1731
|
41 |
|
alpar@1643
|
42 |
int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Edge edge)
|
hegyi@1510
|
43 |
{
|
hegyi@1525
|
44 |
Graph::EdgeMap<double> * actual_map;
|
hegyi@1599
|
45 |
double min, max;
|
hegyi@1599
|
46 |
|
hegyi@1837
|
47 |
min=(mainwin.mapstorage).minOfEdgeMap(mapname);
|
hegyi@1837
|
48 |
max=(mainwin.mapstorage).maxOfEdgeMap(mapname);
|
hegyi@1837
|
49 |
actual_map=((mainwin.mapstorage).edgemap_storage)[mapname];
|
hegyi@1525
|
50 |
|
hegyi@1512
|
51 |
if(edge==INVALID)
|
hegyi@1510
|
52 |
{
|
hegyi@1837
|
53 |
for (EdgeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
|
hegyi@1512
|
54 |
{
|
hegyi@1614
|
55 |
double v=fabs((*actual_map)[i]);
|
hegyi@1599
|
56 |
int w;
|
hegyi@1599
|
57 |
if(min==max)
|
hegyi@1512
|
58 |
{
|
hegyi@1599
|
59 |
w=(int)(edge_property_defaults[E_WIDTH]);
|
hegyi@1512
|
60 |
}
|
hegyi@1599
|
61 |
else
|
hegyi@1599
|
62 |
{
|
hegyi@1599
|
63 |
w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH));
|
hegyi@1599
|
64 |
}
|
hegyi@1599
|
65 |
edgesmap[i]->property_width_units().set_value(w);
|
hegyi@1512
|
66 |
}
|
hegyi@1512
|
67 |
}
|
hegyi@1512
|
68 |
else
|
hegyi@1512
|
69 |
{
|
hegyi@1525
|
70 |
int w=(int)(*actual_map)[edge];
|
hegyi@1510
|
71 |
if(w>=0)
|
hegyi@1510
|
72 |
{
|
hegyi@1598
|
73 |
edgesmap[edge]->property_width_units().set_value(w);
|
hegyi@1510
|
74 |
}
|
hegyi@1510
|
75 |
}
|
hegyi@1510
|
76 |
return 0;
|
hegyi@1510
|
77 |
};
|
hegyi@1510
|
78 |
|
alpar@1643
|
79 |
int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Edge edge)
|
hegyi@1510
|
80 |
{
|
hegyi@1510
|
81 |
|
hegyi@1510
|
82 |
//function maps the range of the maximum and
|
hegyi@1510
|
83 |
//the minimum of the nodemap to the range of
|
hegyi@1510
|
84 |
//green in RGB
|
hegyi@1525
|
85 |
Graph::EdgeMap<double> * actual_map;
|
hegyi@1837
|
86 |
actual_map=((mainwin.mapstorage).edgemap_storage)[mapname];
|
hegyi@1731
|
87 |
|
hegyi@1731
|
88 |
double max, min;
|
hegyi@1731
|
89 |
|
hegyi@1837
|
90 |
max=(mainwin.mapstorage).maxOfEdgeMap(mapname);
|
hegyi@1837
|
91 |
min=(mainwin.mapstorage).minOfEdgeMap(mapname);
|
hegyi@1731
|
92 |
|
hegyi@1731
|
93 |
if(edge==INVALID)
|
hegyi@1525
|
94 |
{
|
hegyi@1837
|
95 |
for (EdgeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
|
hegyi@1731
|
96 |
{
|
hegyi@1731
|
97 |
double w=(*actual_map)[i];
|
hegyi@1731
|
98 |
|
hegyi@1731
|
99 |
Gdk::Color color;
|
hegyi@1731
|
100 |
if(max!=min)
|
hegyi@1731
|
101 |
{
|
hegyi@1731
|
102 |
color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
|
hegyi@1731
|
103 |
}
|
hegyi@1731
|
104 |
else
|
hegyi@1731
|
105 |
{
|
hegyi@1731
|
106 |
color.set_rgb_p (0, 100, 0);
|
hegyi@1731
|
107 |
}
|
hegyi@1731
|
108 |
edgesmap[i]->property_fill_color_gdk().set_value(color);
|
hegyi@1731
|
109 |
}
|
hegyi@1525
|
110 |
}
|
hegyi@1525
|
111 |
else
|
hegyi@1525
|
112 |
{
|
hegyi@1731
|
113 |
Gdk::Color color;
|
hegyi@1731
|
114 |
|
hegyi@1731
|
115 |
double w=(*actual_map)[edge];
|
hegyi@1731
|
116 |
|
hegyi@1731
|
117 |
if(max!=min)
|
hegyi@1731
|
118 |
{
|
hegyi@1731
|
119 |
color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
|
hegyi@1731
|
120 |
}
|
hegyi@1731
|
121 |
else
|
hegyi@1731
|
122 |
{
|
hegyi@1731
|
123 |
color.set_rgb_p (0, 100, 0);
|
hegyi@1731
|
124 |
}
|
hegyi@1731
|
125 |
|
hegyi@1731
|
126 |
edgesmap[edge]->property_fill_color_gdk().set_value(color);
|
hegyi@1525
|
127 |
}
|
hegyi@1731
|
128 |
return 0;
|
hegyi@1731
|
129 |
};
|
hegyi@1731
|
130 |
|
hegyi@1731
|
131 |
int GraphDisplayerCanvas::resetEdgeColor (Edge edge)
|
hegyi@1731
|
132 |
{
|
hegyi@1731
|
133 |
|
hegyi@1731
|
134 |
//function maps the range of the maximum and
|
hegyi@1731
|
135 |
//the minimum of the nodemap to the range of
|
hegyi@1731
|
136 |
//green in RGB
|
hegyi@1837
|
137 |
Graph::EdgeMap<double> actual_map((mainwin.mapstorage).graph,edge_property_defaults[E_COLOR]);
|
hegyi@1525
|
138 |
|
hegyi@1525
|
139 |
double max, min;
|
hegyi@1525
|
140 |
|
hegyi@1731
|
141 |
max=edge_property_defaults[E_COLOR];
|
hegyi@1731
|
142 |
min=edge_property_defaults[E_COLOR];
|
hegyi@1525
|
143 |
|
hegyi@1512
|
144 |
if(edge==INVALID)
|
hegyi@1512
|
145 |
{
|
hegyi@1837
|
146 |
for (EdgeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
|
hegyi@1512
|
147 |
{
|
ladanyi@1825
|
148 |
double w=actual_map[i];
|
hegyi@1525
|
149 |
|
hegyi@1512
|
150 |
Gdk::Color color;
|
hegyi@1512
|
151 |
if(max!=min)
|
hegyi@1512
|
152 |
{
|
hegyi@1512
|
153 |
color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
|
hegyi@1512
|
154 |
}
|
hegyi@1512
|
155 |
else
|
hegyi@1512
|
156 |
{
|
hegyi@1512
|
157 |
color.set_rgb_p (0, 100, 0);
|
hegyi@1512
|
158 |
}
|
hegyi@1512
|
159 |
edgesmap[i]->property_fill_color_gdk().set_value(color);
|
hegyi@1512
|
160 |
}
|
hegyi@1512
|
161 |
}
|
hegyi@1512
|
162 |
else
|
hegyi@1510
|
163 |
{
|
hegyi@1512
|
164 |
Gdk::Color color;
|
hegyi@1525
|
165 |
|
ladanyi@1825
|
166 |
double w=actual_map[edge];
|
hegyi@1525
|
167 |
|
hegyi@1512
|
168 |
if(max!=min)
|
hegyi@1512
|
169 |
{
|
hegyi@1512
|
170 |
color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
|
hegyi@1512
|
171 |
}
|
hegyi@1512
|
172 |
else
|
hegyi@1512
|
173 |
{
|
hegyi@1512
|
174 |
color.set_rgb_p (0, 100, 0);
|
hegyi@1512
|
175 |
}
|
hegyi@1512
|
176 |
|
hegyi@1512
|
177 |
edgesmap[edge]->property_fill_color_gdk().set_value(color);
|
hegyi@1510
|
178 |
}
|
hegyi@1510
|
179 |
return 0;
|
hegyi@1510
|
180 |
};
|
hegyi@1510
|
181 |
|
alpar@1643
|
182 |
int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Edge edge)
|
hegyi@1510
|
183 |
{
|
hegyi@1510
|
184 |
//the number in the map will be written on the edge
|
hegyi@1589
|
185 |
//EXCEPT when the name of the map is Default, because
|
hegyi@1510
|
186 |
//in that case empty string will be written, because
|
hegyi@1510
|
187 |
//that is the deleter map
|
ladanyi@1645
|
188 |
|
hegyi@1512
|
189 |
if(edge==INVALID)
|
hegyi@1510
|
190 |
{
|
hegyi@1837
|
191 |
for (EdgeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
|
hegyi@1510
|
192 |
{
|
hegyi@1731
|
193 |
edgemap_to_edit=mapname;
|
hegyi@1837
|
194 |
double number=(*((mainwin.mapstorage).edgemap_storage)[mapname])[i];
|
hegyi@1731
|
195 |
|
hegyi@1731
|
196 |
std::ostringstream ostr;
|
hegyi@1731
|
197 |
ostr << number;
|
hegyi@1731
|
198 |
|
hegyi@1731
|
199 |
edgetextmap[i]->property_text().set_value(ostr.str());
|
hegyi@1512
|
200 |
}
|
hegyi@1512
|
201 |
|
hegyi@1512
|
202 |
}
|
hegyi@1512
|
203 |
else
|
hegyi@1512
|
204 |
{
|
hegyi@1837
|
205 |
double number=(*((mainwin.mapstorage).edgemap_storage)[mapname])[edge];
|
hegyi@1596
|
206 |
|
hegyi@1596
|
207 |
std::ostringstream ostr;
|
hegyi@1596
|
208 |
ostr << number;
|
hegyi@1596
|
209 |
|
hegyi@1596
|
210 |
edgetextmap[edge]->property_text().set_value(ostr.str());
|
hegyi@1510
|
211 |
}
|
hegyi@1512
|
212 |
|
hegyi@1510
|
213 |
return 0;
|
hegyi@1512
|
214 |
|
hegyi@1510
|
215 |
};
|
hegyi@1731
|
216 |
|
hegyi@1731
|
217 |
int GraphDisplayerCanvas::resetEdgeText (Edge edge)
|
hegyi@1731
|
218 |
{
|
hegyi@1731
|
219 |
//the number in the map will be written on the edge
|
hegyi@1731
|
220 |
//EXCEPT when the name of the map is Default, because
|
hegyi@1731
|
221 |
//in that case empty string will be written, because
|
hegyi@1731
|
222 |
//that is the deleter map
|
hegyi@1731
|
223 |
|
hegyi@1731
|
224 |
if(edge==INVALID)
|
hegyi@1731
|
225 |
{
|
hegyi@1837
|
226 |
for (EdgeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
|
hegyi@1731
|
227 |
{
|
hegyi@1731
|
228 |
edgemap_to_edit="";
|
hegyi@1731
|
229 |
edgetextmap[i]->property_text().set_value("");
|
hegyi@1731
|
230 |
}
|
hegyi@1731
|
231 |
|
hegyi@1731
|
232 |
}
|
hegyi@1731
|
233 |
else
|
hegyi@1731
|
234 |
{
|
hegyi@1731
|
235 |
edgetextmap[edge]->property_text().set_value("");
|
hegyi@1731
|
236 |
}
|
hegyi@1731
|
237 |
|
hegyi@1731
|
238 |
return 0;
|
hegyi@1731
|
239 |
|
hegyi@1731
|
240 |
};
|