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