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