[1606] | 1 | #include "graph_displayer_canvas.h" |
---|
[1632] | 2 | #include <cmath> |
---|
[1512] | 3 | |
---|
| 4 | |
---|
[1643] | 5 | int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Node node) |
---|
[1512] | 6 | { |
---|
[1525] | 7 | Graph::NodeMap<double> * actual_map; |
---|
[1599] | 8 | double min, max; |
---|
[1731] | 9 | min=mapstorage.minOfNodeMap(mapname); |
---|
| 10 | max=mapstorage.maxOfNodeMap(mapname); |
---|
| 11 | actual_map=(mapstorage.nodemap_storage)[mapname]; |
---|
| 12 | |
---|
| 13 | if(node==INVALID) |
---|
[1525] | 14 | { |
---|
[1731] | 15 | for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) |
---|
| 16 | { |
---|
| 17 | double v=fabs((*actual_map)[i]); |
---|
| 18 | int w; |
---|
| 19 | if(min==max) |
---|
| 20 | { |
---|
| 21 | w=(int)(node_property_defaults[N_RADIUS]); |
---|
| 22 | } |
---|
| 23 | else |
---|
| 24 | { |
---|
| 25 | w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS)); |
---|
| 26 | } |
---|
| 27 | if(w>=0) |
---|
| 28 | { |
---|
| 29 | double x1, y1, x2, y2; |
---|
| 30 | x1=nodesmap[i]->property_x1().get_value(); |
---|
| 31 | x2=nodesmap[i]->property_x2().get_value(); |
---|
| 32 | y1=nodesmap[i]->property_y1().get_value(); |
---|
| 33 | y2=nodesmap[i]->property_y2().get_value(); |
---|
| 34 | nodesmap[i]->property_x1().set_value((x1+x2)/2-w); |
---|
| 35 | nodesmap[i]->property_x2().set_value((x1+x2)/2+w); |
---|
| 36 | nodesmap[i]->property_y1().set_value((y1+y2)/2-w); |
---|
| 37 | nodesmap[i]->property_y2().set_value((y1+y2)/2+w); |
---|
| 38 | } |
---|
| 39 | } |
---|
[1525] | 40 | } |
---|
| 41 | else |
---|
| 42 | { |
---|
[1731] | 43 | //I think only new nodes use this case |
---|
| 44 | // int w=(int)(*actual_map)[node]; |
---|
| 45 | int w=(int)(node_property_defaults[N_RADIUS]); |
---|
| 46 | if(w>=0) |
---|
| 47 | { |
---|
| 48 | double x1, y1, x2, y2; |
---|
| 49 | x1=nodesmap[node]->property_x1().get_value(); |
---|
| 50 | x2=nodesmap[node]->property_x2().get_value(); |
---|
| 51 | y1=nodesmap[node]->property_y1().get_value(); |
---|
| 52 | y2=nodesmap[node]->property_y2().get_value(); |
---|
| 53 | nodesmap[node]->property_x1().set_value((x1+x2)/2-w); |
---|
| 54 | nodesmap[node]->property_x2().set_value((x1+x2)/2+w); |
---|
| 55 | nodesmap[node]->property_y1().set_value((y1+y2)/2-w); |
---|
| 56 | nodesmap[node]->property_y2().set_value((y1+y2)/2+w); |
---|
| 57 | } |
---|
[1525] | 58 | } |
---|
[1731] | 59 | return 0; |
---|
| 60 | }; |
---|
[1525] | 61 | |
---|
[1731] | 62 | int GraphDisplayerCanvas::resetNodeRadius (Node node) |
---|
| 63 | { |
---|
| 64 | Graph::NodeMap<double> * actual_map; |
---|
| 65 | double min, max; |
---|
| 66 | min=node_property_defaults[N_RADIUS]; |
---|
| 67 | max=node_property_defaults[N_RADIUS]; |
---|
| 68 | actual_map=new Graph::NodeMap<double>(mapstorage.graph,node_property_defaults[N_RADIUS]); |
---|
| 69 | |
---|
[1512] | 70 | if(node==INVALID) |
---|
| 71 | { |
---|
[1606] | 72 | for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) |
---|
[1512] | 73 | { |
---|
[1614] | 74 | double v=fabs((*actual_map)[i]); |
---|
[1599] | 75 | int w; |
---|
| 76 | if(min==max) |
---|
| 77 | { |
---|
| 78 | w=(int)(node_property_defaults[N_RADIUS]); |
---|
| 79 | } |
---|
| 80 | else |
---|
| 81 | { |
---|
| 82 | w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS)); |
---|
| 83 | } |
---|
[1512] | 84 | if(w>=0) |
---|
| 85 | { |
---|
| 86 | double x1, y1, x2, y2; |
---|
[1525] | 87 | x1=nodesmap[i]->property_x1().get_value(); |
---|
| 88 | x2=nodesmap[i]->property_x2().get_value(); |
---|
| 89 | y1=nodesmap[i]->property_y1().get_value(); |
---|
| 90 | y2=nodesmap[i]->property_y2().get_value(); |
---|
[1512] | 91 | nodesmap[i]->property_x1().set_value((x1+x2)/2-w); |
---|
| 92 | nodesmap[i]->property_x2().set_value((x1+x2)/2+w); |
---|
| 93 | nodesmap[i]->property_y1().set_value((y1+y2)/2-w); |
---|
| 94 | nodesmap[i]->property_y2().set_value((y1+y2)/2+w); |
---|
| 95 | } |
---|
| 96 | } |
---|
| 97 | } |
---|
| 98 | else |
---|
| 99 | { |
---|
[1525] | 100 | //I think only new nodes use this case |
---|
| 101 | // int w=(int)(*actual_map)[node]; |
---|
| 102 | int w=(int)(node_property_defaults[N_RADIUS]); |
---|
[1512] | 103 | if(w>=0) |
---|
| 104 | { |
---|
| 105 | double x1, y1, x2, y2; |
---|
[1525] | 106 | x1=nodesmap[node]->property_x1().get_value(); |
---|
| 107 | x2=nodesmap[node]->property_x2().get_value(); |
---|
| 108 | y1=nodesmap[node]->property_y1().get_value(); |
---|
| 109 | y2=nodesmap[node]->property_y2().get_value(); |
---|
[1512] | 110 | nodesmap[node]->property_x1().set_value((x1+x2)/2-w); |
---|
| 111 | nodesmap[node]->property_x2().set_value((x1+x2)/2+w); |
---|
| 112 | nodesmap[node]->property_y1().set_value((y1+y2)/2-w); |
---|
| 113 | nodesmap[node]->property_y2().set_value((y1+y2)/2+w); |
---|
| 114 | } |
---|
| 115 | } |
---|
| 116 | return 0; |
---|
| 117 | }; |
---|
| 118 | |
---|
[1643] | 119 | int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Node node) |
---|
[1512] | 120 | { |
---|
| 121 | |
---|
| 122 | //function maps the range of the maximum and |
---|
| 123 | //the minimum of the nodemap to the range of |
---|
| 124 | //green in RGB |
---|
| 125 | |
---|
[1525] | 126 | Graph::NodeMap<double> * actual_map; |
---|
[1731] | 127 | actual_map=(mapstorage.nodemap_storage)[mapname]; |
---|
| 128 | |
---|
| 129 | double max, min; |
---|
| 130 | |
---|
| 131 | max=mapstorage.maxOfNodeMap(mapname); |
---|
| 132 | min=mapstorage.minOfNodeMap(mapname); |
---|
| 133 | |
---|
| 134 | if(node==INVALID) |
---|
[1525] | 135 | { |
---|
[1731] | 136 | |
---|
| 137 | for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) |
---|
| 138 | { |
---|
| 139 | Gdk::Color color; |
---|
| 140 | |
---|
| 141 | double w=(*actual_map)[i]; |
---|
| 142 | |
---|
| 143 | if(max!=min) |
---|
| 144 | { |
---|
| 145 | color.set_rgb_p (0, 0, 100*(w-min)/(max-min)); |
---|
| 146 | } |
---|
| 147 | else |
---|
| 148 | { |
---|
| 149 | color.set_rgb_p (0, 0, 100); |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | nodesmap[i]->property_fill_color_gdk().set_value(color); |
---|
| 153 | } |
---|
[1525] | 154 | } |
---|
| 155 | else |
---|
| 156 | { |
---|
[1731] | 157 | Gdk::Color color; |
---|
| 158 | |
---|
| 159 | double w=(*actual_map)[node]; |
---|
| 160 | |
---|
| 161 | if(max!=min) |
---|
| 162 | { |
---|
| 163 | color.set_rgb_p (0, 0, 100*(w-min)/(max-min)); |
---|
| 164 | } |
---|
| 165 | else |
---|
| 166 | { |
---|
| 167 | color.set_rgb_p (0, 0, 100); |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | nodesmap[node]->property_fill_color_gdk().set_value(color); |
---|
[1525] | 171 | } |
---|
[1731] | 172 | return 0; |
---|
| 173 | }; |
---|
| 174 | |
---|
| 175 | int GraphDisplayerCanvas::resetNodeColor (Node node) |
---|
| 176 | { |
---|
| 177 | |
---|
| 178 | //function maps the range of the maximum and |
---|
| 179 | //the minimum of the nodemap to the range of |
---|
| 180 | //green in RGB |
---|
| 181 | |
---|
| 182 | Graph::NodeMap<double> * actual_map; |
---|
| 183 | actual_map=new Graph::NodeMap<double>(mapstorage.graph,node_property_defaults[N_COLOR]); |
---|
[1525] | 184 | |
---|
| 185 | double max, min; |
---|
| 186 | |
---|
[1731] | 187 | max=node_property_defaults[N_COLOR]; |
---|
| 188 | min=node_property_defaults[N_COLOR]; |
---|
[1525] | 189 | |
---|
[1512] | 190 | if(node==INVALID) |
---|
| 191 | { |
---|
| 192 | |
---|
[1606] | 193 | for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) |
---|
[1512] | 194 | { |
---|
| 195 | Gdk::Color color; |
---|
[1525] | 196 | |
---|
| 197 | double w=(*actual_map)[i]; |
---|
| 198 | |
---|
[1512] | 199 | if(max!=min) |
---|
| 200 | { |
---|
| 201 | color.set_rgb_p (0, 0, 100*(w-min)/(max-min)); |
---|
| 202 | } |
---|
| 203 | else |
---|
| 204 | { |
---|
| 205 | color.set_rgb_p (0, 0, 100); |
---|
| 206 | } |
---|
| 207 | |
---|
| 208 | nodesmap[i]->property_fill_color_gdk().set_value(color); |
---|
| 209 | } |
---|
| 210 | } |
---|
| 211 | else |
---|
| 212 | { |
---|
| 213 | Gdk::Color color; |
---|
[1525] | 214 | |
---|
| 215 | double w=(*actual_map)[node]; |
---|
| 216 | |
---|
[1512] | 217 | if(max!=min) |
---|
| 218 | { |
---|
| 219 | color.set_rgb_p (0, 0, 100*(w-min)/(max-min)); |
---|
| 220 | } |
---|
| 221 | else |
---|
| 222 | { |
---|
| 223 | color.set_rgb_p (0, 0, 100); |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | nodesmap[node]->property_fill_color_gdk().set_value(color); |
---|
| 227 | } |
---|
| 228 | return 0; |
---|
| 229 | }; |
---|
| 230 | |
---|
[1643] | 231 | int GraphDisplayerCanvas::changeNodeText (std::string mapname, Node node) |
---|
[1512] | 232 | { |
---|
| 233 | |
---|
| 234 | //the number in the map will be written on the node |
---|
| 235 | //EXCEPT when the name of the map is Text, because |
---|
| 236 | //in that case empty string will be written, because |
---|
| 237 | //that is the deleter map |
---|
[1525] | 238 | |
---|
[1581] | 239 | Graph::NodeMap<double> * actual_map=NULL; |
---|
[1731] | 240 | actual_map=(mapstorage.nodemap_storage)[mapname]; |
---|
[1512] | 241 | |
---|
| 242 | if(node==INVALID) |
---|
| 243 | { |
---|
[1606] | 244 | for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) |
---|
[1512] | 245 | { |
---|
[1731] | 246 | nodemap_to_edit=mapname; |
---|
| 247 | double number=(*actual_map)[i]; |
---|
[1596] | 248 | |
---|
[1731] | 249 | std::ostringstream ostr; |
---|
| 250 | ostr << number; |
---|
[1596] | 251 | |
---|
[1731] | 252 | nodetextmap[i]->property_text().set_value(ostr.str()); |
---|
[1512] | 253 | } |
---|
| 254 | } |
---|
| 255 | else |
---|
| 256 | { |
---|
[1731] | 257 | double number=(*actual_map)[node]; |
---|
[1596] | 258 | |
---|
[1731] | 259 | std::ostringstream ostr; |
---|
| 260 | ostr << number; |
---|
[1596] | 261 | |
---|
[1731] | 262 | nodetextmap[node]->property_text().set_value(ostr.str()); |
---|
[1512] | 263 | } |
---|
| 264 | return 0; |
---|
| 265 | }; |
---|
[1731] | 266 | |
---|
| 267 | int GraphDisplayerCanvas::resetNodeText (Node node) |
---|
| 268 | { |
---|
| 269 | |
---|
| 270 | //the number in the map will be written on the node |
---|
| 271 | //EXCEPT when the name of the map is Text, because |
---|
| 272 | //in that case empty string will be written, because |
---|
| 273 | //that is the deleter map |
---|
| 274 | |
---|
| 275 | if(node==INVALID) |
---|
| 276 | { |
---|
| 277 | for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) |
---|
| 278 | { |
---|
| 279 | nodemap_to_edit=""; |
---|
| 280 | nodetextmap[i]->property_text().set_value(""); |
---|
| 281 | } |
---|
| 282 | } |
---|
| 283 | else |
---|
| 284 | { |
---|
| 285 | nodetextmap[node]->property_text().set_value(""); |
---|
| 286 | } |
---|
| 287 | return 0; |
---|
| 288 | }; |
---|