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 |
|
hegyi@1510
|
110 |
//the number in the map will be written on the edge
|
hegyi@1510
|
111 |
//EXCEPT when the name of the map is Text, because
|
hegyi@1510
|
112 |
//in that case empty string will be written, because
|
hegyi@1510
|
113 |
//that is the deleter map
|
hegyi@1510
|
114 |
|
hegyi@1512
|
115 |
if(edge==INVALID)
|
hegyi@1510
|
116 |
{
|
hegyi@1512
|
117 |
for (EdgeIt i(g); i!=INVALID; ++i)
|
hegyi@1510
|
118 |
{
|
hegyi@1525
|
119 |
if(mapname!="Default")
|
hegyi@1512
|
120 |
{
|
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@1512
|
138 |
int digit=(int)(number/maxpos);
|
hegyi@1512
|
139 |
str[j]=(digit+'0');
|
hegyi@1512
|
140 |
number-=digit*maxpos;
|
hegyi@1512
|
141 |
number*=10;
|
hegyi@1512
|
142 |
}
|
hegyi@1512
|
143 |
}
|
hegyi@1512
|
144 |
|
hegyi@1512
|
145 |
edgetextmap[i]->property_text().set_value(str);
|
hegyi@1512
|
146 |
}
|
hegyi@1512
|
147 |
else
|
hegyi@1512
|
148 |
{
|
hegyi@1512
|
149 |
edgetextmap[i]->property_text().set_value("");
|
hegyi@1512
|
150 |
}
|
hegyi@1512
|
151 |
}
|
hegyi@1512
|
152 |
|
hegyi@1512
|
153 |
}
|
hegyi@1512
|
154 |
else
|
hegyi@1512
|
155 |
{
|
hegyi@1525
|
156 |
if(mapname!="Default")
|
hegyi@1512
|
157 |
{
|
hegyi@1512
|
158 |
double number=(*(mapstorage.edgemap_storage)[mapname])[edge];
|
hegyi@1510
|
159 |
int length=1;
|
hegyi@1510
|
160 |
//if number is smaller than one, length would be negative, or invalid
|
hegyi@1510
|
161 |
if(number>=1)
|
hegyi@1510
|
162 |
{
|
hegyi@1510
|
163 |
length=(int)(floor(log(number)/log(10)))+1;
|
hegyi@1510
|
164 |
}
|
hegyi@1510
|
165 |
int maxpos=(int)(pow(10,length-1));
|
hegyi@1510
|
166 |
int strl=length+1+RANGE;
|
hegyi@1510
|
167 |
char * str=new char[strl];
|
hegyi@1510
|
168 |
str[length]='.';
|
hegyi@1510
|
169 |
str[strl]='\0';
|
hegyi@1510
|
170 |
|
hegyi@1510
|
171 |
for(int j=0;j<strl;j++)
|
hegyi@1510
|
172 |
{
|
hegyi@1510
|
173 |
if(j!=length)
|
hegyi@1510
|
174 |
{
|
hegyi@1510
|
175 |
int digit=(int)(number/maxpos);
|
hegyi@1510
|
176 |
str[j]=(digit+'0');
|
hegyi@1510
|
177 |
number-=digit*maxpos;
|
hegyi@1510
|
178 |
number*=10;
|
hegyi@1510
|
179 |
}
|
hegyi@1510
|
180 |
}
|
hegyi@1510
|
181 |
|
hegyi@1512
|
182 |
edgetextmap[edge]->property_text().set_value(str);
|
hegyi@1510
|
183 |
}
|
hegyi@1510
|
184 |
else
|
hegyi@1510
|
185 |
{
|
hegyi@1512
|
186 |
edgetextmap[edge]->property_text().set_value("");
|
hegyi@1510
|
187 |
}
|
hegyi@1512
|
188 |
|
hegyi@1510
|
189 |
}
|
hegyi@1512
|
190 |
|
hegyi@1510
|
191 |
return 0;
|
hegyi@1512
|
192 |
|
hegyi@1510
|
193 |
};
|