ladanyi@1606
|
1 |
#include "graph_displayer_canvas.h"
|
ladanyi@1606
|
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@1599
|
9 |
double min, max;
|
hegyi@1599
|
10 |
|
hegyi@1525
|
11 |
if(mapname=="Default")
|
hegyi@1525
|
12 |
{
|
hegyi@1599
|
13 |
min=edge_property_defaults[E_WIDTH];
|
hegyi@1599
|
14 |
max=edge_property_defaults[E_WIDTH];
|
ladanyi@1606
|
15 |
actual_map=new Graph::EdgeMap<double>(mapstorage.graph,edge_property_defaults[E_WIDTH]);
|
hegyi@1525
|
16 |
}
|
hegyi@1525
|
17 |
else
|
hegyi@1525
|
18 |
{
|
hegyi@1599
|
19 |
min=mapstorage.minOfEdgeMap(mapname);
|
hegyi@1599
|
20 |
max=mapstorage.maxOfEdgeMap(mapname);
|
hegyi@1525
|
21 |
actual_map=(mapstorage.edgemap_storage)[mapname];
|
hegyi@1525
|
22 |
}
|
hegyi@1525
|
23 |
|
hegyi@1512
|
24 |
if(edge==INVALID)
|
hegyi@1510
|
25 |
{
|
ladanyi@1606
|
26 |
for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
|
hegyi@1512
|
27 |
{
|
hegyi@1614
|
28 |
double v=fabs((*actual_map)[i]);
|
hegyi@1599
|
29 |
int w;
|
hegyi@1599
|
30 |
if(min==max)
|
hegyi@1512
|
31 |
{
|
hegyi@1599
|
32 |
w=(int)(edge_property_defaults[E_WIDTH]);
|
hegyi@1512
|
33 |
}
|
hegyi@1599
|
34 |
else
|
hegyi@1599
|
35 |
{
|
hegyi@1599
|
36 |
w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH));
|
hegyi@1599
|
37 |
}
|
hegyi@1599
|
38 |
edgesmap[i]->property_width_units().set_value(w);
|
hegyi@1512
|
39 |
}
|
hegyi@1512
|
40 |
}
|
hegyi@1512
|
41 |
else
|
hegyi@1512
|
42 |
{
|
hegyi@1525
|
43 |
int w=(int)(*actual_map)[edge];
|
hegyi@1510
|
44 |
if(w>=0)
|
hegyi@1510
|
45 |
{
|
hegyi@1598
|
46 |
edgesmap[edge]->property_width_units().set_value(w);
|
hegyi@1510
|
47 |
}
|
hegyi@1510
|
48 |
}
|
hegyi@1510
|
49 |
return 0;
|
hegyi@1510
|
50 |
};
|
hegyi@1510
|
51 |
|
hegyi@1512
|
52 |
int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Graph::Edge edge)
|
hegyi@1510
|
53 |
{
|
hegyi@1510
|
54 |
|
hegyi@1510
|
55 |
//function maps the range of the maximum and
|
hegyi@1510
|
56 |
//the minimum of the nodemap to the range of
|
hegyi@1510
|
57 |
//green in RGB
|
hegyi@1525
|
58 |
Graph::EdgeMap<double> * actual_map;
|
hegyi@1525
|
59 |
if(mapname=="Default")
|
hegyi@1525
|
60 |
{
|
ladanyi@1606
|
61 |
actual_map=new Graph::EdgeMap<double>(mapstorage.graph,edge_property_defaults[E_COLOR]);
|
hegyi@1525
|
62 |
}
|
hegyi@1525
|
63 |
else
|
hegyi@1525
|
64 |
{
|
hegyi@1525
|
65 |
actual_map=(mapstorage.edgemap_storage)[mapname];
|
hegyi@1525
|
66 |
}
|
hegyi@1525
|
67 |
|
hegyi@1525
|
68 |
double max, min;
|
hegyi@1525
|
69 |
|
hegyi@1525
|
70 |
if(mapname!="Default")
|
hegyi@1525
|
71 |
{
|
hegyi@1525
|
72 |
max=mapstorage.maxOfEdgeMap(mapname);
|
hegyi@1525
|
73 |
min=mapstorage.minOfEdgeMap(mapname);
|
hegyi@1525
|
74 |
}
|
hegyi@1525
|
75 |
else
|
hegyi@1525
|
76 |
{
|
hegyi@1525
|
77 |
max=edge_property_defaults[E_COLOR];
|
hegyi@1525
|
78 |
min=edge_property_defaults[E_COLOR];
|
hegyi@1525
|
79 |
}
|
hegyi@1525
|
80 |
|
hegyi@1512
|
81 |
if(edge==INVALID)
|
hegyi@1512
|
82 |
{
|
ladanyi@1606
|
83 |
for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
|
hegyi@1512
|
84 |
{
|
hegyi@1525
|
85 |
double w=(*actual_map)[i];
|
hegyi@1525
|
86 |
|
hegyi@1512
|
87 |
Gdk::Color color;
|
hegyi@1512
|
88 |
if(max!=min)
|
hegyi@1512
|
89 |
{
|
hegyi@1512
|
90 |
color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
|
hegyi@1512
|
91 |
}
|
hegyi@1512
|
92 |
else
|
hegyi@1512
|
93 |
{
|
hegyi@1512
|
94 |
color.set_rgb_p (0, 100, 0);
|
hegyi@1512
|
95 |
}
|
hegyi@1512
|
96 |
edgesmap[i]->property_fill_color_gdk().set_value(color);
|
hegyi@1512
|
97 |
}
|
hegyi@1512
|
98 |
}
|
hegyi@1512
|
99 |
else
|
hegyi@1510
|
100 |
{
|
hegyi@1512
|
101 |
Gdk::Color color;
|
hegyi@1525
|
102 |
|
hegyi@1525
|
103 |
double w=(*actual_map)[edge];
|
hegyi@1525
|
104 |
|
hegyi@1512
|
105 |
if(max!=min)
|
hegyi@1512
|
106 |
{
|
hegyi@1512
|
107 |
color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
|
hegyi@1512
|
108 |
}
|
hegyi@1512
|
109 |
else
|
hegyi@1512
|
110 |
{
|
hegyi@1512
|
111 |
color.set_rgb_p (0, 100, 0);
|
hegyi@1512
|
112 |
}
|
hegyi@1512
|
113 |
|
hegyi@1512
|
114 |
edgesmap[edge]->property_fill_color_gdk().set_value(color);
|
hegyi@1510
|
115 |
}
|
hegyi@1510
|
116 |
return 0;
|
hegyi@1510
|
117 |
};
|
hegyi@1510
|
118 |
|
hegyi@1512
|
119 |
int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Graph::Edge edge)
|
hegyi@1510
|
120 |
{
|
hegyi@1510
|
121 |
//the number in the map will be written on the edge
|
hegyi@1589
|
122 |
//EXCEPT when the name of the map is Default, because
|
hegyi@1510
|
123 |
//in that case empty string will be written, because
|
hegyi@1510
|
124 |
//that is the deleter map
|
hegyi@1510
|
125 |
|
hegyi@1512
|
126 |
if(edge==INVALID)
|
hegyi@1510
|
127 |
{
|
ladanyi@1606
|
128 |
for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
|
hegyi@1510
|
129 |
{
|
hegyi@1525
|
130 |
if(mapname!="Default")
|
hegyi@1512
|
131 |
{
|
hegyi@1579
|
132 |
edgemap_to_edit=mapname;
|
hegyi@1512
|
133 |
double number=(*(mapstorage.edgemap_storage)[mapname])[i];
|
hegyi@1595
|
134 |
|
hegyi@1595
|
135 |
std::ostringstream ostr;
|
hegyi@1595
|
136 |
ostr << number;
|
hegyi@1596
|
137 |
|
hegyi@1595
|
138 |
edgetextmap[i]->property_text().set_value(ostr.str());
|
hegyi@1512
|
139 |
}
|
hegyi@1512
|
140 |
else
|
hegyi@1512
|
141 |
{
|
hegyi@1579
|
142 |
edgemap_to_edit="";
|
hegyi@1512
|
143 |
edgetextmap[i]->property_text().set_value("");
|
hegyi@1512
|
144 |
}
|
hegyi@1512
|
145 |
}
|
hegyi@1512
|
146 |
|
hegyi@1512
|
147 |
}
|
hegyi@1512
|
148 |
else
|
hegyi@1512
|
149 |
{
|
hegyi@1525
|
150 |
if(mapname!="Default")
|
hegyi@1512
|
151 |
{
|
hegyi@1512
|
152 |
double number=(*(mapstorage.edgemap_storage)[mapname])[edge];
|
hegyi@1596
|
153 |
|
hegyi@1596
|
154 |
std::ostringstream ostr;
|
hegyi@1596
|
155 |
ostr << number;
|
hegyi@1596
|
156 |
|
hegyi@1596
|
157 |
edgetextmap[edge]->property_text().set_value(ostr.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 |
};
|