ladanyi@53
|
1 |
#include "graph_displayer_canvas.h"
|
alpar@59
|
2 |
#include <cmath>
|
hegyi@28
|
3 |
|
hegyi@28
|
4 |
|
alpar@62
|
5 |
int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Node node)
|
hegyi@28
|
6 |
{
|
hegyi@31
|
7 |
Graph::NodeMap<double> * actual_map;
|
hegyi@48
|
8 |
double min, max;
|
hegyi@96
|
9 |
min=(mytab.mapstorage).minOfNodeMap(mapname);
|
hegyi@96
|
10 |
max=(mytab.mapstorage).maxOfNodeMap(mapname);
|
hegyi@96
|
11 |
actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
|
hegyi@81
|
12 |
|
hegyi@81
|
13 |
if(node==INVALID)
|
hegyi@31
|
14 |
{
|
hegyi@96
|
15 |
for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
|
hegyi@81
|
16 |
{
|
hegyi@81
|
17 |
double v=fabs((*actual_map)[i]);
|
hegyi@81
|
18 |
int w;
|
hegyi@81
|
19 |
if(min==max)
|
hegyi@81
|
20 |
{
|
hegyi@81
|
21 |
w=(int)(node_property_defaults[N_RADIUS]);
|
hegyi@81
|
22 |
}
|
hegyi@81
|
23 |
else
|
hegyi@81
|
24 |
{
|
hegyi@81
|
25 |
w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS));
|
hegyi@81
|
26 |
}
|
hegyi@81
|
27 |
if(w>=0)
|
hegyi@81
|
28 |
{
|
hegyi@81
|
29 |
double x1, y1, x2, y2;
|
hegyi@81
|
30 |
x1=nodesmap[i]->property_x1().get_value();
|
hegyi@81
|
31 |
x2=nodesmap[i]->property_x2().get_value();
|
hegyi@81
|
32 |
y1=nodesmap[i]->property_y1().get_value();
|
hegyi@81
|
33 |
y2=nodesmap[i]->property_y2().get_value();
|
hegyi@81
|
34 |
nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
|
hegyi@81
|
35 |
nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
|
hegyi@81
|
36 |
nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
|
hegyi@81
|
37 |
nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
|
hegyi@81
|
38 |
}
|
hegyi@81
|
39 |
}
|
hegyi@31
|
40 |
}
|
hegyi@31
|
41 |
else
|
hegyi@31
|
42 |
{
|
hegyi@81
|
43 |
//I think only new nodes use this case
|
hegyi@81
|
44 |
// int w=(int)(*actual_map)[node];
|
hegyi@81
|
45 |
int w=(int)(node_property_defaults[N_RADIUS]);
|
hegyi@81
|
46 |
if(w>=0)
|
hegyi@81
|
47 |
{
|
hegyi@81
|
48 |
double x1, y1, x2, y2;
|
hegyi@81
|
49 |
x1=nodesmap[node]->property_x1().get_value();
|
hegyi@81
|
50 |
x2=nodesmap[node]->property_x2().get_value();
|
hegyi@81
|
51 |
y1=nodesmap[node]->property_y1().get_value();
|
hegyi@81
|
52 |
y2=nodesmap[node]->property_y2().get_value();
|
hegyi@81
|
53 |
nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
|
hegyi@81
|
54 |
nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
|
hegyi@81
|
55 |
nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
|
hegyi@81
|
56 |
nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
|
hegyi@81
|
57 |
}
|
hegyi@31
|
58 |
}
|
hegyi@81
|
59 |
return 0;
|
hegyi@81
|
60 |
};
|
hegyi@31
|
61 |
|
hegyi@81
|
62 |
int GraphDisplayerCanvas::resetNodeRadius (Node node)
|
hegyi@81
|
63 |
{
|
hegyi@81
|
64 |
double min, max;
|
hegyi@81
|
65 |
min=node_property_defaults[N_RADIUS];
|
hegyi@81
|
66 |
max=node_property_defaults[N_RADIUS];
|
hegyi@96
|
67 |
Graph::NodeMap<double> actual_map((mytab.mapstorage).graph,node_property_defaults[N_RADIUS]);
|
hegyi@81
|
68 |
|
hegyi@28
|
69 |
if(node==INVALID)
|
hegyi@28
|
70 |
{
|
hegyi@96
|
71 |
for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
|
hegyi@28
|
72 |
{
|
ladanyi@91
|
73 |
double v=fabs(actual_map[i]);
|
hegyi@48
|
74 |
int w;
|
hegyi@48
|
75 |
if(min==max)
|
hegyi@48
|
76 |
{
|
hegyi@48
|
77 |
w=(int)(node_property_defaults[N_RADIUS]);
|
hegyi@48
|
78 |
}
|
hegyi@48
|
79 |
else
|
hegyi@48
|
80 |
{
|
hegyi@48
|
81 |
w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS));
|
hegyi@48
|
82 |
}
|
hegyi@28
|
83 |
if(w>=0)
|
hegyi@28
|
84 |
{
|
hegyi@28
|
85 |
double x1, y1, x2, y2;
|
hegyi@31
|
86 |
x1=nodesmap[i]->property_x1().get_value();
|
hegyi@31
|
87 |
x2=nodesmap[i]->property_x2().get_value();
|
hegyi@31
|
88 |
y1=nodesmap[i]->property_y1().get_value();
|
hegyi@31
|
89 |
y2=nodesmap[i]->property_y2().get_value();
|
hegyi@28
|
90 |
nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
|
hegyi@28
|
91 |
nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
|
hegyi@28
|
92 |
nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
|
hegyi@28
|
93 |
nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
|
hegyi@28
|
94 |
}
|
hegyi@28
|
95 |
}
|
hegyi@28
|
96 |
}
|
hegyi@28
|
97 |
else
|
hegyi@28
|
98 |
{
|
hegyi@31
|
99 |
//I think only new nodes use this case
|
ladanyi@91
|
100 |
// int w=(int)actual_map[node];
|
hegyi@31
|
101 |
int w=(int)(node_property_defaults[N_RADIUS]);
|
hegyi@28
|
102 |
if(w>=0)
|
hegyi@28
|
103 |
{
|
hegyi@28
|
104 |
double x1, y1, x2, y2;
|
hegyi@31
|
105 |
x1=nodesmap[node]->property_x1().get_value();
|
hegyi@31
|
106 |
x2=nodesmap[node]->property_x2().get_value();
|
hegyi@31
|
107 |
y1=nodesmap[node]->property_y1().get_value();
|
hegyi@31
|
108 |
y2=nodesmap[node]->property_y2().get_value();
|
hegyi@28
|
109 |
nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
|
hegyi@28
|
110 |
nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
|
hegyi@28
|
111 |
nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
|
hegyi@28
|
112 |
nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
|
hegyi@28
|
113 |
}
|
hegyi@28
|
114 |
}
|
hegyi@28
|
115 |
return 0;
|
hegyi@28
|
116 |
};
|
hegyi@28
|
117 |
|
alpar@62
|
118 |
int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Node node)
|
hegyi@28
|
119 |
{
|
hegyi@28
|
120 |
|
hegyi@28
|
121 |
//function maps the range of the maximum and
|
hegyi@28
|
122 |
//the minimum of the nodemap to the range of
|
hegyi@28
|
123 |
//green in RGB
|
hegyi@28
|
124 |
|
hegyi@31
|
125 |
Graph::NodeMap<double> * actual_map;
|
hegyi@96
|
126 |
actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
|
hegyi@81
|
127 |
|
hegyi@81
|
128 |
double max, min;
|
hegyi@81
|
129 |
|
hegyi@96
|
130 |
max=(mytab.mapstorage).maxOfNodeMap(mapname);
|
hegyi@96
|
131 |
min=(mytab.mapstorage).minOfNodeMap(mapname);
|
hegyi@81
|
132 |
|
hegyi@81
|
133 |
if(node==INVALID)
|
hegyi@31
|
134 |
{
|
hegyi@81
|
135 |
|
hegyi@96
|
136 |
for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
|
hegyi@81
|
137 |
{
|
hegyi@81
|
138 |
Gdk::Color color;
|
hegyi@81
|
139 |
|
hegyi@81
|
140 |
double w=(*actual_map)[i];
|
hegyi@81
|
141 |
|
hegyi@81
|
142 |
if(max!=min)
|
hegyi@81
|
143 |
{
|
hegyi@81
|
144 |
color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
|
hegyi@81
|
145 |
}
|
hegyi@81
|
146 |
else
|
hegyi@81
|
147 |
{
|
hegyi@81
|
148 |
color.set_rgb_p (0, 0, 100);
|
hegyi@81
|
149 |
}
|
hegyi@81
|
150 |
|
hegyi@81
|
151 |
nodesmap[i]->property_fill_color_gdk().set_value(color);
|
hegyi@81
|
152 |
}
|
hegyi@31
|
153 |
}
|
hegyi@31
|
154 |
else
|
hegyi@31
|
155 |
{
|
hegyi@81
|
156 |
Gdk::Color color;
|
hegyi@81
|
157 |
|
hegyi@81
|
158 |
double w=(*actual_map)[node];
|
hegyi@81
|
159 |
|
hegyi@81
|
160 |
if(max!=min)
|
hegyi@81
|
161 |
{
|
hegyi@81
|
162 |
color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
|
hegyi@81
|
163 |
}
|
hegyi@81
|
164 |
else
|
hegyi@81
|
165 |
{
|
hegyi@81
|
166 |
color.set_rgb_p (0, 0, 100);
|
hegyi@81
|
167 |
}
|
hegyi@81
|
168 |
|
hegyi@81
|
169 |
nodesmap[node]->property_fill_color_gdk().set_value(color);
|
hegyi@31
|
170 |
}
|
hegyi@81
|
171 |
return 0;
|
hegyi@81
|
172 |
};
|
hegyi@81
|
173 |
|
hegyi@81
|
174 |
int GraphDisplayerCanvas::resetNodeColor (Node node)
|
hegyi@81
|
175 |
{
|
hegyi@81
|
176 |
|
hegyi@81
|
177 |
//function maps the range of the maximum and
|
hegyi@81
|
178 |
//the minimum of the nodemap to the range of
|
hegyi@81
|
179 |
//green in RGB
|
hegyi@81
|
180 |
|
hegyi@96
|
181 |
Graph::NodeMap<double> actual_map((mytab.mapstorage).graph,node_property_defaults[N_COLOR]);
|
hegyi@31
|
182 |
|
hegyi@31
|
183 |
double max, min;
|
hegyi@31
|
184 |
|
hegyi@81
|
185 |
max=node_property_defaults[N_COLOR];
|
hegyi@81
|
186 |
min=node_property_defaults[N_COLOR];
|
hegyi@31
|
187 |
|
hegyi@28
|
188 |
if(node==INVALID)
|
hegyi@28
|
189 |
{
|
hegyi@28
|
190 |
|
hegyi@96
|
191 |
for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
|
hegyi@28
|
192 |
{
|
hegyi@28
|
193 |
Gdk::Color color;
|
hegyi@31
|
194 |
|
ladanyi@91
|
195 |
double w=actual_map[i];
|
hegyi@31
|
196 |
|
hegyi@28
|
197 |
if(max!=min)
|
hegyi@28
|
198 |
{
|
hegyi@28
|
199 |
color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
|
hegyi@28
|
200 |
}
|
hegyi@28
|
201 |
else
|
hegyi@28
|
202 |
{
|
hegyi@28
|
203 |
color.set_rgb_p (0, 0, 100);
|
hegyi@28
|
204 |
}
|
hegyi@28
|
205 |
|
hegyi@28
|
206 |
nodesmap[i]->property_fill_color_gdk().set_value(color);
|
hegyi@28
|
207 |
}
|
hegyi@28
|
208 |
}
|
hegyi@28
|
209 |
else
|
hegyi@28
|
210 |
{
|
hegyi@28
|
211 |
Gdk::Color color;
|
hegyi@31
|
212 |
|
ladanyi@91
|
213 |
double w=actual_map[node];
|
hegyi@31
|
214 |
|
hegyi@28
|
215 |
if(max!=min)
|
hegyi@28
|
216 |
{
|
hegyi@28
|
217 |
color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
|
hegyi@28
|
218 |
}
|
hegyi@28
|
219 |
else
|
hegyi@28
|
220 |
{
|
hegyi@28
|
221 |
color.set_rgb_p (0, 0, 100);
|
hegyi@28
|
222 |
}
|
hegyi@28
|
223 |
|
hegyi@28
|
224 |
nodesmap[node]->property_fill_color_gdk().set_value(color);
|
hegyi@28
|
225 |
}
|
hegyi@28
|
226 |
return 0;
|
hegyi@28
|
227 |
};
|
hegyi@28
|
228 |
|
alpar@62
|
229 |
int GraphDisplayerCanvas::changeNodeText (std::string mapname, Node node)
|
hegyi@28
|
230 |
{
|
hegyi@28
|
231 |
|
hegyi@28
|
232 |
//the number in the map will be written on the node
|
hegyi@28
|
233 |
//EXCEPT when the name of the map is Text, because
|
hegyi@28
|
234 |
//in that case empty string will be written, because
|
hegyi@28
|
235 |
//that is the deleter map
|
hegyi@31
|
236 |
|
hegyi@36
|
237 |
Graph::NodeMap<double> * actual_map=NULL;
|
hegyi@96
|
238 |
actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
|
hegyi@28
|
239 |
|
hegyi@28
|
240 |
if(node==INVALID)
|
hegyi@28
|
241 |
{
|
hegyi@96
|
242 |
for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
|
hegyi@28
|
243 |
{
|
hegyi@81
|
244 |
nodemap_to_edit=mapname;
|
hegyi@81
|
245 |
double number=(*actual_map)[i];
|
hegyi@45
|
246 |
|
hegyi@81
|
247 |
std::ostringstream ostr;
|
hegyi@81
|
248 |
ostr << number;
|
hegyi@45
|
249 |
|
hegyi@81
|
250 |
nodetextmap[i]->property_text().set_value(ostr.str());
|
hegyi@28
|
251 |
}
|
hegyi@28
|
252 |
}
|
hegyi@28
|
253 |
else
|
hegyi@28
|
254 |
{
|
hegyi@81
|
255 |
double number=(*actual_map)[node];
|
hegyi@45
|
256 |
|
hegyi@81
|
257 |
std::ostringstream ostr;
|
hegyi@81
|
258 |
ostr << number;
|
hegyi@45
|
259 |
|
hegyi@81
|
260 |
nodetextmap[node]->property_text().set_value(ostr.str());
|
hegyi@28
|
261 |
}
|
hegyi@28
|
262 |
return 0;
|
hegyi@28
|
263 |
};
|
hegyi@81
|
264 |
|
hegyi@81
|
265 |
int GraphDisplayerCanvas::resetNodeText (Node node)
|
hegyi@81
|
266 |
{
|
hegyi@81
|
267 |
|
hegyi@81
|
268 |
//the number in the map will be written on the node
|
hegyi@81
|
269 |
//EXCEPT when the name of the map is Text, because
|
hegyi@81
|
270 |
//in that case empty string will be written, because
|
hegyi@81
|
271 |
//that is the deleter map
|
hegyi@81
|
272 |
|
hegyi@81
|
273 |
if(node==INVALID)
|
hegyi@81
|
274 |
{
|
hegyi@96
|
275 |
for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
|
hegyi@81
|
276 |
{
|
hegyi@81
|
277 |
nodemap_to_edit="";
|
hegyi@81
|
278 |
nodetextmap[i]->property_text().set_value("");
|
hegyi@81
|
279 |
}
|
hegyi@81
|
280 |
}
|
hegyi@81
|
281 |
else
|
hegyi@81
|
282 |
{
|
hegyi@81
|
283 |
nodetextmap[node]->property_text().set_value("");
|
hegyi@81
|
284 |
}
|
hegyi@81
|
285 |
return 0;
|
hegyi@81
|
286 |
};
|