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