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