hegyi@1510
|
1 |
#include <graph_displayer_canvas.h>
|
hegyi@1510
|
2 |
#include <broken_edge.h>
|
hegyi@1510
|
3 |
#include <math.h>
|
hegyi@1510
|
4 |
|
hegyi@1510
|
5 |
|
hegyi@1512
|
6 |
int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Graph::Edge edge)
|
hegyi@1510
|
7 |
{
|
hegyi@1525
|
8 |
Graph::EdgeMap<double> * actual_map;
|
hegyi@1525
|
9 |
if(mapname=="Default")
|
hegyi@1525
|
10 |
{
|
hegyi@1525
|
11 |
actual_map=new Graph::EdgeMap<double>(g,edge_property_defaults[E_WIDTH]);
|
hegyi@1525
|
12 |
}
|
hegyi@1525
|
13 |
else
|
hegyi@1525
|
14 |
{
|
hegyi@1525
|
15 |
actual_map=(mapstorage.edgemap_storage)[mapname];
|
hegyi@1525
|
16 |
}
|
hegyi@1525
|
17 |
|
hegyi@1512
|
18 |
if(edge==INVALID)
|
hegyi@1510
|
19 |
{
|
hegyi@1512
|
20 |
for (EdgeIt i(g); i!=INVALID; ++i)
|
hegyi@1512
|
21 |
{
|
hegyi@1525
|
22 |
int w=(int)(*actual_map)[i];
|
hegyi@1512
|
23 |
if(w>=0)
|
hegyi@1512
|
24 |
{
|
hegyi@1512
|
25 |
edgesmap[i]->property_width_pixels().set_value(w);
|
hegyi@1512
|
26 |
}
|
hegyi@1512
|
27 |
}
|
hegyi@1512
|
28 |
}
|
hegyi@1512
|
29 |
else
|
hegyi@1512
|
30 |
{
|
hegyi@1525
|
31 |
int w=(int)(*actual_map)[edge];
|
hegyi@1510
|
32 |
if(w>=0)
|
hegyi@1510
|
33 |
{
|
hegyi@1512
|
34 |
edgesmap[edge]->property_width_pixels().set_value(w);
|
hegyi@1510
|
35 |
}
|
hegyi@1510
|
36 |
}
|
hegyi@1510
|
37 |
return 0;
|
hegyi@1510
|
38 |
};
|
hegyi@1510
|
39 |
|
hegyi@1512
|
40 |
int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Graph::Edge edge)
|
hegyi@1510
|
41 |
{
|
hegyi@1510
|
42 |
|
hegyi@1510
|
43 |
//function maps the range of the maximum and
|
hegyi@1510
|
44 |
//the minimum of the nodemap to the range of
|
hegyi@1510
|
45 |
//green in RGB
|
hegyi@1525
|
46 |
Graph::EdgeMap<double> * actual_map;
|
hegyi@1525
|
47 |
if(mapname=="Default")
|
hegyi@1525
|
48 |
{
|
hegyi@1525
|
49 |
actual_map=new Graph::EdgeMap<double>(g,edge_property_defaults[E_COLOR]);
|
hegyi@1525
|
50 |
}
|
hegyi@1525
|
51 |
else
|
hegyi@1525
|
52 |
{
|
hegyi@1525
|
53 |
actual_map=(mapstorage.edgemap_storage)[mapname];
|
hegyi@1525
|
54 |
}
|
hegyi@1525
|
55 |
|
hegyi@1525
|
56 |
double max, min;
|
hegyi@1525
|
57 |
|
hegyi@1525
|
58 |
if(mapname!="Default")
|
hegyi@1525
|
59 |
{
|
hegyi@1525
|
60 |
max=mapstorage.maxOfEdgeMap(mapname);
|
hegyi@1525
|
61 |
min=mapstorage.minOfEdgeMap(mapname);
|
hegyi@1525
|
62 |
}
|
hegyi@1525
|
63 |
else
|
hegyi@1525
|
64 |
{
|
hegyi@1525
|
65 |
max=edge_property_defaults[E_COLOR];
|
hegyi@1525
|
66 |
min=edge_property_defaults[E_COLOR];
|
hegyi@1525
|
67 |
}
|
hegyi@1525
|
68 |
|
hegyi@1512
|
69 |
if(edge==INVALID)
|
hegyi@1512
|
70 |
{
|
hegyi@1512
|
71 |
for (EdgeIt i(g); i!=INVALID; ++i)
|
hegyi@1512
|
72 |
{
|
hegyi@1525
|
73 |
double w=(*actual_map)[i];
|
hegyi@1525
|
74 |
|
hegyi@1512
|
75 |
Gdk::Color color;
|
hegyi@1512
|
76 |
if(max!=min)
|
hegyi@1512
|
77 |
{
|
hegyi@1512
|
78 |
color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
|
hegyi@1512
|
79 |
}
|
hegyi@1512
|
80 |
else
|
hegyi@1512
|
81 |
{
|
hegyi@1512
|
82 |
color.set_rgb_p (0, 100, 0);
|
hegyi@1512
|
83 |
}
|
hegyi@1512
|
84 |
edgesmap[i]->property_fill_color_gdk().set_value(color);
|
hegyi@1512
|
85 |
}
|
hegyi@1512
|
86 |
}
|
hegyi@1512
|
87 |
else
|
hegyi@1510
|
88 |
{
|
hegyi@1512
|
89 |
Gdk::Color color;
|
hegyi@1525
|
90 |
|
hegyi@1525
|
91 |
double w=(*actual_map)[edge];
|
hegyi@1525
|
92 |
|
hegyi@1512
|
93 |
if(max!=min)
|
hegyi@1512
|
94 |
{
|
hegyi@1512
|
95 |
color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
|
hegyi@1512
|
96 |
}
|
hegyi@1512
|
97 |
else
|
hegyi@1512
|
98 |
{
|
hegyi@1512
|
99 |
color.set_rgb_p (0, 100, 0);
|
hegyi@1512
|
100 |
}
|
hegyi@1512
|
101 |
|
hegyi@1512
|
102 |
edgesmap[edge]->property_fill_color_gdk().set_value(color);
|
hegyi@1510
|
103 |
}
|
hegyi@1510
|
104 |
return 0;
|
hegyi@1510
|
105 |
};
|
hegyi@1510
|
106 |
|
hegyi@1512
|
107 |
int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Graph::Edge edge)
|
hegyi@1510
|
108 |
{
|
hegyi@1510
|
109 |
//the number in the map will be written on the edge
|
hegyi@1589
|
110 |
//EXCEPT when the name of the map is Default, because
|
hegyi@1510
|
111 |
//in that case empty string will be written, because
|
hegyi@1510
|
112 |
//that is the deleter map
|
hegyi@1510
|
113 |
|
hegyi@1512
|
114 |
if(edge==INVALID)
|
hegyi@1510
|
115 |
{
|
hegyi@1512
|
116 |
for (EdgeIt i(g); i!=INVALID; ++i)
|
hegyi@1510
|
117 |
{
|
hegyi@1525
|
118 |
if(mapname!="Default")
|
hegyi@1512
|
119 |
{
|
hegyi@1579
|
120 |
edgemap_to_edit=mapname;
|
hegyi@1512
|
121 |
double number=(*(mapstorage.edgemap_storage)[mapname])[i];
|
hegyi@1512
|
122 |
int length=1;
|
hegyi@1512
|
123 |
//if number is smaller than one, length would be negative, or invalid
|
hegyi@1512
|
124 |
if(number>=1)
|
hegyi@1512
|
125 |
{
|
hegyi@1512
|
126 |
length=(int)(floor(log(number)/log(10)))+1;
|
hegyi@1512
|
127 |
}
|
hegyi@1512
|
128 |
int maxpos=(int)(pow(10,length-1));
|
hegyi@1512
|
129 |
int strl=length+1+RANGE;
|
hegyi@1512
|
130 |
char * str=new char[strl];
|
hegyi@1512
|
131 |
str[length]='.';
|
hegyi@1512
|
132 |
str[strl]='\0';
|
hegyi@1512
|
133 |
|
hegyi@1512
|
134 |
for(int j=0;j<strl;j++)
|
hegyi@1512
|
135 |
{
|
hegyi@1512
|
136 |
if(j!=length)
|
hegyi@1512
|
137 |
{
|
hegyi@1581
|
138 |
if((number-(int)number)>ALMOST_ONE)
|
hegyi@1581
|
139 |
{
|
hegyi@1581
|
140 |
number=round(number);
|
hegyi@1581
|
141 |
}
|
hegyi@1512
|
142 |
int digit=(int)(number/maxpos);
|
hegyi@1512
|
143 |
str[j]=(digit+'0');
|
hegyi@1512
|
144 |
number-=digit*maxpos;
|
hegyi@1512
|
145 |
number*=10;
|
hegyi@1512
|
146 |
}
|
hegyi@1512
|
147 |
}
|
hegyi@1512
|
148 |
|
hegyi@1512
|
149 |
edgetextmap[i]->property_text().set_value(str);
|
hegyi@1512
|
150 |
}
|
hegyi@1512
|
151 |
else
|
hegyi@1512
|
152 |
{
|
hegyi@1579
|
153 |
edgemap_to_edit="";
|
hegyi@1512
|
154 |
edgetextmap[i]->property_text().set_value("");
|
hegyi@1512
|
155 |
}
|
hegyi@1512
|
156 |
}
|
hegyi@1512
|
157 |
|
hegyi@1512
|
158 |
}
|
hegyi@1512
|
159 |
else
|
hegyi@1512
|
160 |
{
|
hegyi@1525
|
161 |
if(mapname!="Default")
|
hegyi@1512
|
162 |
{
|
hegyi@1512
|
163 |
double number=(*(mapstorage.edgemap_storage)[mapname])[edge];
|
hegyi@1510
|
164 |
int length=1;
|
hegyi@1510
|
165 |
//if number is smaller than one, length would be negative, or invalid
|
hegyi@1510
|
166 |
if(number>=1)
|
hegyi@1510
|
167 |
{
|
hegyi@1510
|
168 |
length=(int)(floor(log(number)/log(10)))+1;
|
hegyi@1510
|
169 |
}
|
hegyi@1510
|
170 |
int maxpos=(int)(pow(10,length-1));
|
hegyi@1510
|
171 |
int strl=length+1+RANGE;
|
hegyi@1510
|
172 |
char * str=new char[strl];
|
hegyi@1510
|
173 |
str[length]='.';
|
hegyi@1510
|
174 |
str[strl]='\0';
|
hegyi@1510
|
175 |
|
hegyi@1510
|
176 |
for(int j=0;j<strl;j++)
|
hegyi@1510
|
177 |
{
|
hegyi@1510
|
178 |
if(j!=length)
|
hegyi@1510
|
179 |
{
|
hegyi@1581
|
180 |
if((number-(int)number)>ALMOST_ONE)
|
hegyi@1581
|
181 |
{
|
hegyi@1581
|
182 |
number=round(number);
|
hegyi@1581
|
183 |
}
|
hegyi@1510
|
184 |
int digit=(int)(number/maxpos);
|
hegyi@1510
|
185 |
str[j]=(digit+'0');
|
hegyi@1510
|
186 |
number-=digit*maxpos;
|
hegyi@1510
|
187 |
number*=10;
|
hegyi@1510
|
188 |
}
|
hegyi@1510
|
189 |
}
|
hegyi@1510
|
190 |
|
hegyi@1512
|
191 |
edgetextmap[edge]->property_text().set_value(str);
|
hegyi@1510
|
192 |
}
|
hegyi@1510
|
193 |
else
|
hegyi@1510
|
194 |
{
|
hegyi@1512
|
195 |
edgetextmap[edge]->property_text().set_value("");
|
hegyi@1510
|
196 |
}
|
hegyi@1512
|
197 |
|
hegyi@1510
|
198 |
}
|
hegyi@1512
|
199 |
|
hegyi@1510
|
200 |
return 0;
|
hegyi@1512
|
201 |
|
hegyi@1510
|
202 |
};
|