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@1512
|
8 |
if(edge==INVALID)
|
hegyi@1510
|
9 |
{
|
hegyi@1512
|
10 |
for (EdgeIt i(g); i!=INVALID; ++i)
|
hegyi@1512
|
11 |
{
|
hegyi@1512
|
12 |
int w=(int)(*(mapstorage.edgemap_storage)[mapname])[i];
|
hegyi@1512
|
13 |
if(w>=0)
|
hegyi@1512
|
14 |
{
|
hegyi@1512
|
15 |
edgesmap[i]->property_width_pixels().set_value(w);
|
hegyi@1512
|
16 |
}
|
hegyi@1512
|
17 |
}
|
hegyi@1512
|
18 |
}
|
hegyi@1512
|
19 |
else
|
hegyi@1512
|
20 |
{
|
hegyi@1512
|
21 |
int w=(int)(*(mapstorage.edgemap_storage)[mapname])[edge];
|
hegyi@1510
|
22 |
if(w>=0)
|
hegyi@1510
|
23 |
{
|
hegyi@1512
|
24 |
edgesmap[edge]->property_width_pixels().set_value(w);
|
hegyi@1510
|
25 |
}
|
hegyi@1510
|
26 |
}
|
hegyi@1510
|
27 |
return 0;
|
hegyi@1510
|
28 |
};
|
hegyi@1510
|
29 |
|
hegyi@1512
|
30 |
int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Graph::Edge edge)
|
hegyi@1510
|
31 |
{
|
hegyi@1510
|
32 |
|
hegyi@1510
|
33 |
//function maps the range of the maximum and
|
hegyi@1510
|
34 |
//the minimum of the nodemap to the range of
|
hegyi@1510
|
35 |
//green in RGB
|
hegyi@1512
|
36 |
if(edge==INVALID)
|
hegyi@1512
|
37 |
{
|
hegyi@1510
|
38 |
|
hegyi@1512
|
39 |
for (EdgeIt i(g); i!=INVALID; ++i)
|
hegyi@1512
|
40 |
{
|
hegyi@1512
|
41 |
double w=(*(mapstorage.edgemap_storage)[mapname])[i];
|
hegyi@1512
|
42 |
double max=mapstorage.maxOfEdgeMap(mapname);
|
hegyi@1512
|
43 |
double min=mapstorage.minOfEdgeMap(mapname);
|
hegyi@1510
|
44 |
|
hegyi@1512
|
45 |
//std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
|
hegyi@1512
|
46 |
Gdk::Color color;
|
hegyi@1512
|
47 |
if(max!=min)
|
hegyi@1512
|
48 |
{
|
hegyi@1512
|
49 |
color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
|
hegyi@1512
|
50 |
}
|
hegyi@1512
|
51 |
else
|
hegyi@1512
|
52 |
{
|
hegyi@1512
|
53 |
color.set_rgb_p (0, 100, 0);
|
hegyi@1512
|
54 |
}
|
hegyi@1512
|
55 |
|
hegyi@1512
|
56 |
edgesmap[i]->property_fill_color_gdk().set_value(color);
|
hegyi@1512
|
57 |
}
|
hegyi@1512
|
58 |
}
|
hegyi@1512
|
59 |
else
|
hegyi@1510
|
60 |
{
|
hegyi@1512
|
61 |
double w=(*(mapstorage.edgemap_storage)[mapname])[edge];
|
hegyi@1512
|
62 |
double max=mapstorage.maxOfEdgeMap(mapname);
|
hegyi@1512
|
63 |
double min=mapstorage.minOfEdgeMap(mapname);
|
hegyi@1512
|
64 |
|
hegyi@1512
|
65 |
//std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
|
hegyi@1512
|
66 |
Gdk::Color color;
|
hegyi@1512
|
67 |
if(max!=min)
|
hegyi@1512
|
68 |
{
|
hegyi@1512
|
69 |
color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
|
hegyi@1512
|
70 |
}
|
hegyi@1512
|
71 |
else
|
hegyi@1512
|
72 |
{
|
hegyi@1512
|
73 |
color.set_rgb_p (0, 100, 0);
|
hegyi@1512
|
74 |
}
|
hegyi@1512
|
75 |
|
hegyi@1512
|
76 |
edgesmap[edge]->property_fill_color_gdk().set_value(color);
|
hegyi@1510
|
77 |
}
|
hegyi@1510
|
78 |
return 0;
|
hegyi@1510
|
79 |
};
|
hegyi@1510
|
80 |
|
hegyi@1512
|
81 |
int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Graph::Edge edge)
|
hegyi@1510
|
82 |
{
|
hegyi@1510
|
83 |
|
hegyi@1510
|
84 |
//the number in the map will be written on the edge
|
hegyi@1510
|
85 |
//EXCEPT when the name of the map is Text, because
|
hegyi@1510
|
86 |
//in that case empty string will be written, because
|
hegyi@1510
|
87 |
//that is the deleter map
|
hegyi@1510
|
88 |
//\todo isn't it a bit woodcutter?
|
hegyi@1510
|
89 |
|
hegyi@1512
|
90 |
if(edge==INVALID)
|
hegyi@1510
|
91 |
{
|
hegyi@1512
|
92 |
for (EdgeIt i(g); i!=INVALID; ++i)
|
hegyi@1510
|
93 |
{
|
hegyi@1512
|
94 |
if(mapname!=edge_property_strings[E_TEXT])
|
hegyi@1512
|
95 |
{
|
hegyi@1512
|
96 |
double number=(*(mapstorage.edgemap_storage)[mapname])[i];
|
hegyi@1512
|
97 |
int length=1;
|
hegyi@1512
|
98 |
//if number is smaller than one, length would be negative, or invalid
|
hegyi@1512
|
99 |
if(number>=1)
|
hegyi@1512
|
100 |
{
|
hegyi@1512
|
101 |
length=(int)(floor(log(number)/log(10)))+1;
|
hegyi@1512
|
102 |
}
|
hegyi@1512
|
103 |
int maxpos=(int)(pow(10,length-1));
|
hegyi@1512
|
104 |
int strl=length+1+RANGE;
|
hegyi@1512
|
105 |
char * str=new char[strl];
|
hegyi@1512
|
106 |
str[length]='.';
|
hegyi@1512
|
107 |
str[strl]='\0';
|
hegyi@1512
|
108 |
|
hegyi@1512
|
109 |
for(int j=0;j<strl;j++)
|
hegyi@1512
|
110 |
{
|
hegyi@1512
|
111 |
if(j!=length)
|
hegyi@1512
|
112 |
{
|
hegyi@1512
|
113 |
int digit=(int)(number/maxpos);
|
hegyi@1512
|
114 |
str[j]=(digit+'0');
|
hegyi@1512
|
115 |
number-=digit*maxpos;
|
hegyi@1512
|
116 |
number*=10;
|
hegyi@1512
|
117 |
}
|
hegyi@1512
|
118 |
}
|
hegyi@1512
|
119 |
|
hegyi@1512
|
120 |
edgetextmap[i]->property_text().set_value(str);
|
hegyi@1512
|
121 |
}
|
hegyi@1512
|
122 |
else
|
hegyi@1512
|
123 |
{
|
hegyi@1512
|
124 |
edgetextmap[i]->property_text().set_value("");
|
hegyi@1512
|
125 |
}
|
hegyi@1512
|
126 |
}
|
hegyi@1512
|
127 |
|
hegyi@1512
|
128 |
}
|
hegyi@1512
|
129 |
else
|
hegyi@1512
|
130 |
{
|
hegyi@1512
|
131 |
if(mapname!=edge_property_strings[E_TEXT])
|
hegyi@1512
|
132 |
{
|
hegyi@1512
|
133 |
double number=(*(mapstorage.edgemap_storage)[mapname])[edge];
|
hegyi@1510
|
134 |
int length=1;
|
hegyi@1510
|
135 |
//if number is smaller than one, length would be negative, or invalid
|
hegyi@1510
|
136 |
if(number>=1)
|
hegyi@1510
|
137 |
{
|
hegyi@1510
|
138 |
length=(int)(floor(log(number)/log(10)))+1;
|
hegyi@1510
|
139 |
}
|
hegyi@1510
|
140 |
int maxpos=(int)(pow(10,length-1));
|
hegyi@1510
|
141 |
int strl=length+1+RANGE;
|
hegyi@1510
|
142 |
char * str=new char[strl];
|
hegyi@1510
|
143 |
str[length]='.';
|
hegyi@1510
|
144 |
str[strl]='\0';
|
hegyi@1510
|
145 |
|
hegyi@1510
|
146 |
for(int j=0;j<strl;j++)
|
hegyi@1510
|
147 |
{
|
hegyi@1510
|
148 |
if(j!=length)
|
hegyi@1510
|
149 |
{
|
hegyi@1510
|
150 |
int digit=(int)(number/maxpos);
|
hegyi@1510
|
151 |
str[j]=(digit+'0');
|
hegyi@1510
|
152 |
number-=digit*maxpos;
|
hegyi@1510
|
153 |
number*=10;
|
hegyi@1510
|
154 |
}
|
hegyi@1510
|
155 |
}
|
hegyi@1510
|
156 |
|
hegyi@1512
|
157 |
edgetextmap[edge]->property_text().set_value(str);
|
hegyi@1510
|
158 |
}
|
hegyi@1510
|
159 |
else
|
hegyi@1510
|
160 |
{
|
hegyi@1512
|
161 |
edgetextmap[edge]->property_text().set_value("");
|
hegyi@1510
|
162 |
}
|
hegyi@1512
|
163 |
|
hegyi@1510
|
164 |
}
|
hegyi@1512
|
165 |
|
hegyi@1510
|
166 |
return 0;
|
hegyi@1512
|
167 |
|
hegyi@1510
|
168 |
};
|