ladanyi@1606
|
1 |
#include "graph_displayer_canvas.h"
|
ladanyi@1606
|
2 |
#include "broken_edge.h"
|
alpar@1632
|
3 |
#include <cmath>
|
hegyi@1512
|
4 |
|
hegyi@1512
|
5 |
|
alpar@1643
|
6 |
int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Node node)
|
hegyi@1512
|
7 |
{
|
hegyi@1525
|
8 |
Graph::NodeMap<double> * actual_map;
|
hegyi@1599
|
9 |
double min, max;
|
hegyi@1525
|
10 |
if(mapname=="Default")
|
hegyi@1525
|
11 |
{
|
hegyi@1599
|
12 |
min=node_property_defaults[N_RADIUS];
|
hegyi@1599
|
13 |
max=node_property_defaults[N_RADIUS];
|
ladanyi@1606
|
14 |
actual_map=new Graph::NodeMap<double>(mapstorage.graph,node_property_defaults[N_RADIUS]);
|
hegyi@1525
|
15 |
}
|
hegyi@1525
|
16 |
else
|
hegyi@1525
|
17 |
{
|
hegyi@1599
|
18 |
min=mapstorage.minOfNodeMap(mapname);
|
hegyi@1599
|
19 |
max=mapstorage.maxOfNodeMap(mapname);
|
hegyi@1525
|
20 |
actual_map=(mapstorage.nodemap_storage)[mapname];
|
hegyi@1525
|
21 |
}
|
hegyi@1525
|
22 |
|
hegyi@1512
|
23 |
if(node==INVALID)
|
hegyi@1512
|
24 |
{
|
ladanyi@1606
|
25 |
for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
|
hegyi@1512
|
26 |
{
|
hegyi@1614
|
27 |
double v=fabs((*actual_map)[i]);
|
hegyi@1599
|
28 |
int w;
|
hegyi@1599
|
29 |
if(min==max)
|
hegyi@1599
|
30 |
{
|
hegyi@1599
|
31 |
w=(int)(node_property_defaults[N_RADIUS]);
|
hegyi@1599
|
32 |
}
|
hegyi@1599
|
33 |
else
|
hegyi@1599
|
34 |
{
|
hegyi@1599
|
35 |
w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS));
|
hegyi@1599
|
36 |
}
|
hegyi@1512
|
37 |
if(w>=0)
|
hegyi@1512
|
38 |
{
|
hegyi@1512
|
39 |
double x1, y1, x2, y2;
|
hegyi@1525
|
40 |
x1=nodesmap[i]->property_x1().get_value();
|
hegyi@1525
|
41 |
x2=nodesmap[i]->property_x2().get_value();
|
hegyi@1525
|
42 |
y1=nodesmap[i]->property_y1().get_value();
|
hegyi@1525
|
43 |
y2=nodesmap[i]->property_y2().get_value();
|
hegyi@1512
|
44 |
nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
|
hegyi@1512
|
45 |
nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
|
hegyi@1512
|
46 |
nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
|
hegyi@1512
|
47 |
nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
|
hegyi@1512
|
48 |
}
|
hegyi@1512
|
49 |
}
|
hegyi@1512
|
50 |
}
|
hegyi@1512
|
51 |
else
|
hegyi@1512
|
52 |
{
|
hegyi@1525
|
53 |
//I think only new nodes use this case
|
hegyi@1525
|
54 |
// int w=(int)(*actual_map)[node];
|
hegyi@1525
|
55 |
int w=(int)(node_property_defaults[N_RADIUS]);
|
hegyi@1512
|
56 |
if(w>=0)
|
hegyi@1512
|
57 |
{
|
hegyi@1512
|
58 |
double x1, y1, x2, y2;
|
hegyi@1525
|
59 |
x1=nodesmap[node]->property_x1().get_value();
|
hegyi@1525
|
60 |
x2=nodesmap[node]->property_x2().get_value();
|
hegyi@1525
|
61 |
y1=nodesmap[node]->property_y1().get_value();
|
hegyi@1525
|
62 |
y2=nodesmap[node]->property_y2().get_value();
|
hegyi@1512
|
63 |
nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
|
hegyi@1512
|
64 |
nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
|
hegyi@1512
|
65 |
nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
|
hegyi@1512
|
66 |
nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
|
hegyi@1512
|
67 |
}
|
hegyi@1512
|
68 |
}
|
hegyi@1512
|
69 |
return 0;
|
hegyi@1512
|
70 |
};
|
hegyi@1512
|
71 |
|
alpar@1643
|
72 |
int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Node node)
|
hegyi@1512
|
73 |
{
|
hegyi@1512
|
74 |
|
hegyi@1512
|
75 |
//function maps the range of the maximum and
|
hegyi@1512
|
76 |
//the minimum of the nodemap to the range of
|
hegyi@1512
|
77 |
//green in RGB
|
hegyi@1512
|
78 |
|
hegyi@1525
|
79 |
Graph::NodeMap<double> * actual_map;
|
hegyi@1525
|
80 |
if(mapname=="Default")
|
hegyi@1525
|
81 |
{
|
ladanyi@1606
|
82 |
actual_map=new Graph::NodeMap<double>(mapstorage.graph,node_property_defaults[N_COLOR]);
|
hegyi@1525
|
83 |
}
|
hegyi@1525
|
84 |
else
|
hegyi@1525
|
85 |
{
|
hegyi@1525
|
86 |
actual_map=(mapstorage.nodemap_storage)[mapname];
|
hegyi@1525
|
87 |
}
|
hegyi@1525
|
88 |
|
hegyi@1525
|
89 |
double max, min;
|
hegyi@1525
|
90 |
|
hegyi@1525
|
91 |
if(mapname!="Default")
|
hegyi@1525
|
92 |
{
|
hegyi@1525
|
93 |
max=mapstorage.maxOfNodeMap(mapname);
|
hegyi@1525
|
94 |
min=mapstorage.minOfNodeMap(mapname);
|
hegyi@1525
|
95 |
}
|
hegyi@1525
|
96 |
else
|
hegyi@1525
|
97 |
{
|
hegyi@1525
|
98 |
max=node_property_defaults[N_COLOR];
|
hegyi@1525
|
99 |
min=node_property_defaults[N_COLOR];
|
hegyi@1525
|
100 |
}
|
hegyi@1525
|
101 |
|
hegyi@1525
|
102 |
|
hegyi@1512
|
103 |
if(node==INVALID)
|
hegyi@1512
|
104 |
{
|
hegyi@1512
|
105 |
|
ladanyi@1606
|
106 |
for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
|
hegyi@1512
|
107 |
{
|
hegyi@1512
|
108 |
Gdk::Color color;
|
hegyi@1525
|
109 |
|
hegyi@1525
|
110 |
double w=(*actual_map)[i];
|
hegyi@1525
|
111 |
|
hegyi@1512
|
112 |
if(max!=min)
|
hegyi@1512
|
113 |
{
|
hegyi@1512
|
114 |
color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
|
hegyi@1512
|
115 |
}
|
hegyi@1512
|
116 |
else
|
hegyi@1512
|
117 |
{
|
hegyi@1512
|
118 |
color.set_rgb_p (0, 0, 100);
|
hegyi@1512
|
119 |
}
|
hegyi@1512
|
120 |
|
hegyi@1512
|
121 |
nodesmap[i]->property_fill_color_gdk().set_value(color);
|
hegyi@1512
|
122 |
}
|
hegyi@1512
|
123 |
}
|
hegyi@1512
|
124 |
else
|
hegyi@1512
|
125 |
{
|
hegyi@1512
|
126 |
Gdk::Color color;
|
hegyi@1525
|
127 |
|
hegyi@1525
|
128 |
double w=(*actual_map)[node];
|
hegyi@1525
|
129 |
|
hegyi@1512
|
130 |
if(max!=min)
|
hegyi@1512
|
131 |
{
|
hegyi@1512
|
132 |
color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
|
hegyi@1512
|
133 |
}
|
hegyi@1512
|
134 |
else
|
hegyi@1512
|
135 |
{
|
hegyi@1512
|
136 |
color.set_rgb_p (0, 0, 100);
|
hegyi@1512
|
137 |
}
|
hegyi@1512
|
138 |
|
hegyi@1512
|
139 |
nodesmap[node]->property_fill_color_gdk().set_value(color);
|
hegyi@1512
|
140 |
}
|
hegyi@1512
|
141 |
return 0;
|
hegyi@1512
|
142 |
};
|
hegyi@1512
|
143 |
|
alpar@1643
|
144 |
int GraphDisplayerCanvas::changeNodeText (std::string mapname, Node node)
|
hegyi@1512
|
145 |
{
|
hegyi@1512
|
146 |
|
hegyi@1512
|
147 |
//the number in the map will be written on the node
|
hegyi@1512
|
148 |
//EXCEPT when the name of the map is Text, because
|
hegyi@1512
|
149 |
//in that case empty string will be written, because
|
hegyi@1512
|
150 |
//that is the deleter map
|
hegyi@1525
|
151 |
|
hegyi@1581
|
152 |
Graph::NodeMap<double> * actual_map=NULL;
|
hegyi@1579
|
153 |
if(mapname!="Default")
|
hegyi@1525
|
154 |
{
|
hegyi@1525
|
155 |
actual_map=(mapstorage.nodemap_storage)[mapname];
|
hegyi@1525
|
156 |
}
|
hegyi@1512
|
157 |
|
hegyi@1512
|
158 |
if(node==INVALID)
|
hegyi@1512
|
159 |
{
|
ladanyi@1606
|
160 |
for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
|
hegyi@1512
|
161 |
{
|
hegyi@1525
|
162 |
if(mapname!="Default")
|
hegyi@1512
|
163 |
{
|
hegyi@1579
|
164 |
nodemap_to_edit=mapname;
|
hegyi@1525
|
165 |
double number=(*actual_map)[i];
|
hegyi@1596
|
166 |
|
hegyi@1596
|
167 |
std::ostringstream ostr;
|
hegyi@1596
|
168 |
ostr << number;
|
hegyi@1596
|
169 |
|
hegyi@1596
|
170 |
nodetextmap[i]->property_text().set_value(ostr.str());
|
hegyi@1512
|
171 |
}
|
hegyi@1512
|
172 |
else
|
hegyi@1512
|
173 |
{
|
hegyi@1579
|
174 |
nodemap_to_edit="";
|
hegyi@1512
|
175 |
nodetextmap[i]->property_text().set_value("");
|
hegyi@1512
|
176 |
}
|
hegyi@1512
|
177 |
}
|
hegyi@1512
|
178 |
}
|
hegyi@1512
|
179 |
else
|
hegyi@1512
|
180 |
{
|
hegyi@1525
|
181 |
if(mapname!="Default")
|
hegyi@1512
|
182 |
{
|
hegyi@1525
|
183 |
double number=(*actual_map)[node];
|
hegyi@1596
|
184 |
|
hegyi@1596
|
185 |
std::ostringstream ostr;
|
hegyi@1596
|
186 |
ostr << number;
|
hegyi@1596
|
187 |
|
hegyi@1596
|
188 |
nodetextmap[node]->property_text().set_value(ostr.str());
|
hegyi@1512
|
189 |
}
|
hegyi@1512
|
190 |
else
|
hegyi@1512
|
191 |
{
|
hegyi@1512
|
192 |
nodetextmap[node]->property_text().set_value("");
|
hegyi@1512
|
193 |
}
|
hegyi@1512
|
194 |
}
|
hegyi@1512
|
195 |
return 0;
|
hegyi@1512
|
196 |
};
|