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