[1606] | 1 | #include "graph_displayer_canvas.h" |
---|
| 2 | #include "broken_edge.h" |
---|
[1632] | 3 | #include <cmath> |
---|
[1510] | 4 | |
---|
| 5 | |
---|
[1731] | 6 | int GraphDisplayerCanvas::resetEdgeWidth (Edge edge) |
---|
| 7 | { |
---|
| 8 | Graph::EdgeMap<double> * actual_map; |
---|
| 9 | double min, max; |
---|
| 10 | |
---|
| 11 | min=edge_property_defaults[E_WIDTH]; |
---|
| 12 | max=edge_property_defaults[E_WIDTH]; |
---|
| 13 | actual_map=new Graph::EdgeMap<double>(mapstorage.graph,edge_property_defaults[E_WIDTH]); |
---|
| 14 | |
---|
| 15 | if(edge==INVALID) |
---|
| 16 | { |
---|
| 17 | for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) |
---|
| 18 | { |
---|
| 19 | double v=fabs((*actual_map)[i]); |
---|
| 20 | int w; |
---|
| 21 | if(min==max) |
---|
| 22 | { |
---|
| 23 | w=(int)(edge_property_defaults[E_WIDTH]); |
---|
| 24 | } |
---|
| 25 | else |
---|
| 26 | { |
---|
| 27 | w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH)); |
---|
| 28 | } |
---|
| 29 | edgesmap[i]->property_width_units().set_value(w); |
---|
| 30 | } |
---|
| 31 | } |
---|
| 32 | else |
---|
| 33 | { |
---|
| 34 | int w=(int)(*actual_map)[edge]; |
---|
| 35 | if(w>=0) |
---|
| 36 | { |
---|
| 37 | edgesmap[edge]->property_width_units().set_value(w); |
---|
| 38 | } |
---|
| 39 | } |
---|
| 40 | return 0; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | |
---|
[1643] | 44 | int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Edge edge) |
---|
[1510] | 45 | { |
---|
[1525] | 46 | Graph::EdgeMap<double> * actual_map; |
---|
[1599] | 47 | double min, max; |
---|
| 48 | |
---|
[1731] | 49 | min=mapstorage.minOfEdgeMap(mapname); |
---|
| 50 | max=mapstorage.maxOfEdgeMap(mapname); |
---|
| 51 | actual_map=(mapstorage.edgemap_storage)[mapname]; |
---|
[1525] | 52 | |
---|
[1512] | 53 | if(edge==INVALID) |
---|
[1510] | 54 | { |
---|
[1606] | 55 | for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) |
---|
[1512] | 56 | { |
---|
[1614] | 57 | double v=fabs((*actual_map)[i]); |
---|
[1599] | 58 | int w; |
---|
| 59 | if(min==max) |
---|
[1512] | 60 | { |
---|
[1599] | 61 | w=(int)(edge_property_defaults[E_WIDTH]); |
---|
[1512] | 62 | } |
---|
[1599] | 63 | else |
---|
| 64 | { |
---|
| 65 | w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH)); |
---|
| 66 | } |
---|
| 67 | edgesmap[i]->property_width_units().set_value(w); |
---|
[1512] | 68 | } |
---|
| 69 | } |
---|
| 70 | else |
---|
| 71 | { |
---|
[1525] | 72 | int w=(int)(*actual_map)[edge]; |
---|
[1510] | 73 | if(w>=0) |
---|
| 74 | { |
---|
[1598] | 75 | edgesmap[edge]->property_width_units().set_value(w); |
---|
[1510] | 76 | } |
---|
| 77 | } |
---|
| 78 | return 0; |
---|
| 79 | }; |
---|
| 80 | |
---|
[1643] | 81 | int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Edge edge) |
---|
[1510] | 82 | { |
---|
| 83 | |
---|
| 84 | //function maps the range of the maximum and |
---|
| 85 | //the minimum of the nodemap to the range of |
---|
| 86 | //green in RGB |
---|
[1525] | 87 | Graph::EdgeMap<double> * actual_map; |
---|
[1731] | 88 | actual_map=(mapstorage.edgemap_storage)[mapname]; |
---|
| 89 | |
---|
| 90 | double max, min; |
---|
| 91 | |
---|
| 92 | max=mapstorage.maxOfEdgeMap(mapname); |
---|
| 93 | min=mapstorage.minOfEdgeMap(mapname); |
---|
| 94 | |
---|
| 95 | if(edge==INVALID) |
---|
[1525] | 96 | { |
---|
[1731] | 97 | for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) |
---|
| 98 | { |
---|
| 99 | double w=(*actual_map)[i]; |
---|
| 100 | |
---|
| 101 | Gdk::Color color; |
---|
| 102 | if(max!=min) |
---|
| 103 | { |
---|
| 104 | color.set_rgb_p (0, 100*(w-min)/(max-min), 0); |
---|
| 105 | } |
---|
| 106 | else |
---|
| 107 | { |
---|
| 108 | color.set_rgb_p (0, 100, 0); |
---|
| 109 | } |
---|
| 110 | edgesmap[i]->property_fill_color_gdk().set_value(color); |
---|
| 111 | } |
---|
[1525] | 112 | } |
---|
| 113 | else |
---|
| 114 | { |
---|
[1731] | 115 | Gdk::Color color; |
---|
| 116 | |
---|
| 117 | double w=(*actual_map)[edge]; |
---|
| 118 | |
---|
| 119 | if(max!=min) |
---|
| 120 | { |
---|
| 121 | color.set_rgb_p (0, 100*(w-min)/(max-min), 0); |
---|
| 122 | } |
---|
| 123 | else |
---|
| 124 | { |
---|
| 125 | color.set_rgb_p (0, 100, 0); |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | edgesmap[edge]->property_fill_color_gdk().set_value(color); |
---|
[1525] | 129 | } |
---|
[1731] | 130 | return 0; |
---|
| 131 | }; |
---|
| 132 | |
---|
| 133 | int GraphDisplayerCanvas::resetEdgeColor (Edge edge) |
---|
| 134 | { |
---|
| 135 | |
---|
| 136 | //function maps the range of the maximum and |
---|
| 137 | //the minimum of the nodemap to the range of |
---|
| 138 | //green in RGB |
---|
| 139 | Graph::EdgeMap<double> * actual_map; |
---|
| 140 | actual_map=new Graph::EdgeMap<double>(mapstorage.graph,edge_property_defaults[E_COLOR]); |
---|
[1525] | 141 | |
---|
| 142 | double max, min; |
---|
| 143 | |
---|
[1731] | 144 | max=edge_property_defaults[E_COLOR]; |
---|
| 145 | min=edge_property_defaults[E_COLOR]; |
---|
[1525] | 146 | |
---|
[1512] | 147 | if(edge==INVALID) |
---|
| 148 | { |
---|
[1606] | 149 | for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) |
---|
[1512] | 150 | { |
---|
[1525] | 151 | double w=(*actual_map)[i]; |
---|
| 152 | |
---|
[1512] | 153 | Gdk::Color color; |
---|
| 154 | if(max!=min) |
---|
| 155 | { |
---|
| 156 | color.set_rgb_p (0, 100*(w-min)/(max-min), 0); |
---|
| 157 | } |
---|
| 158 | else |
---|
| 159 | { |
---|
| 160 | color.set_rgb_p (0, 100, 0); |
---|
| 161 | } |
---|
| 162 | edgesmap[i]->property_fill_color_gdk().set_value(color); |
---|
| 163 | } |
---|
| 164 | } |
---|
| 165 | else |
---|
[1510] | 166 | { |
---|
[1512] | 167 | Gdk::Color color; |
---|
[1525] | 168 | |
---|
| 169 | double w=(*actual_map)[edge]; |
---|
| 170 | |
---|
[1512] | 171 | if(max!=min) |
---|
| 172 | { |
---|
| 173 | color.set_rgb_p (0, 100*(w-min)/(max-min), 0); |
---|
| 174 | } |
---|
| 175 | else |
---|
| 176 | { |
---|
| 177 | color.set_rgb_p (0, 100, 0); |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | edgesmap[edge]->property_fill_color_gdk().set_value(color); |
---|
[1510] | 181 | } |
---|
| 182 | return 0; |
---|
| 183 | }; |
---|
| 184 | |
---|
[1643] | 185 | int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Edge edge) |
---|
[1510] | 186 | { |
---|
| 187 | //the number in the map will be written on the edge |
---|
[1589] | 188 | //EXCEPT when the name of the map is Default, because |
---|
[1510] | 189 | //in that case empty string will be written, because |
---|
| 190 | //that is the deleter map |
---|
[1645] | 191 | |
---|
[1512] | 192 | if(edge==INVALID) |
---|
[1510] | 193 | { |
---|
[1606] | 194 | for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) |
---|
[1510] | 195 | { |
---|
[1731] | 196 | edgemap_to_edit=mapname; |
---|
| 197 | double number=(*(mapstorage.edgemap_storage)[mapname])[i]; |
---|
| 198 | |
---|
| 199 | std::ostringstream ostr; |
---|
| 200 | ostr << number; |
---|
| 201 | |
---|
| 202 | edgetextmap[i]->property_text().set_value(ostr.str()); |
---|
[1512] | 203 | } |
---|
| 204 | |
---|
| 205 | } |
---|
| 206 | else |
---|
| 207 | { |
---|
| 208 | double number=(*(mapstorage.edgemap_storage)[mapname])[edge]; |
---|
[1596] | 209 | |
---|
| 210 | std::ostringstream ostr; |
---|
| 211 | ostr << number; |
---|
| 212 | |
---|
| 213 | edgetextmap[edge]->property_text().set_value(ostr.str()); |
---|
[1510] | 214 | } |
---|
[1512] | 215 | |
---|
[1510] | 216 | return 0; |
---|
[1512] | 217 | |
---|
[1510] | 218 | }; |
---|
[1731] | 219 | |
---|
| 220 | int GraphDisplayerCanvas::resetEdgeText (Edge edge) |
---|
| 221 | { |
---|
| 222 | //the number in the map will be written on the edge |
---|
| 223 | //EXCEPT when the name of the map is Default, because |
---|
| 224 | //in that case empty string will be written, because |
---|
| 225 | //that is the deleter map |
---|
| 226 | |
---|
| 227 | if(edge==INVALID) |
---|
| 228 | { |
---|
| 229 | for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) |
---|
| 230 | { |
---|
| 231 | edgemap_to_edit=""; |
---|
| 232 | edgetextmap[i]->property_text().set_value(""); |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | } |
---|
| 236 | else |
---|
| 237 | { |
---|
| 238 | edgetextmap[edge]->property_text().set_value(""); |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | return 0; |
---|
| 242 | |
---|
| 243 | }; |
---|