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