3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2006
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
19 #include <graph_displayer_canvas.h>
20 #include <mapstorage.h>
24 const int minimum_edge_width=0;
26 int GraphDisplayerCanvas::resetEdgeWidth (Edge edge)
30 min=edge_property_defaults[E_WIDTH];
31 max=edge_property_defaults[E_WIDTH];
32 Graph::EdgeMap<double> actual_map((mytab.mapstorage)->graph,edge_property_defaults[E_WIDTH]);
36 for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
38 double v=fabs(actual_map[i]);
42 w=(int)(edge_property_defaults[E_WIDTH]);
46 w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH));
50 double actual_ppu=get_pixels_per_unit();
51 w=(int)(w/actual_ppu*fixed_zoom_factor);
53 edgesmap[i]->setLineWidth(w);
58 int w=(int)actual_map[edge];
61 edgesmap[edge]->setLineWidth(w);
68 int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Edge edge)
70 Graph::EdgeMap<double> * actual_map;
73 min=(mytab.mapstorage)->minOfEdgeMap(mapname);
74 max=(mytab.mapstorage)->maxOfEdgeMap(mapname);
75 actual_map=((mytab.mapstorage)->edgemap_storage)[mapname];
79 for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
81 double v=(*actual_map)[i];
87 w=(int)(edge_property_defaults[E_WIDTH]);
91 w=(int)(minimum_edge_width+(v-min)/(max-min)*(edge_width-minimum_edge_width));
96 w=(int)(v*edge_width);
105 if(w<minimum_edge_width)
107 w=minimum_edge_width;
111 double actual_ppu=get_pixels_per_unit();
112 w=(int)(w/actual_ppu*fixed_zoom_factor);
114 edgesmap[i]->setLineWidth(w);
120 int w=(int)(*actual_map)[edge];
123 edgesmap[edge]->setLineWidth(w);
129 int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Edge edge)
132 //function maps the range of the maximum and
133 //the minimum of the nodemap to the range of
135 Graph::EdgeMap<double> * actual_map;
136 actual_map=((mytab.mapstorage)->edgemap_storage)[mapname];
140 max=(mytab.mapstorage)->maxOfEdgeMap(mapname);
141 min=(mytab.mapstorage)->minOfEdgeMap(mapname);
145 for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
147 double w=(*actual_map)[i];
152 color=rainbowColorCounter(min, max, w);
156 color.set_rgb_p (0, 1, 0);
158 edgesmap[i]->setFillColor(color);
165 double w=(*actual_map)[edge];
169 color=rainbowColorCounter(min, max, w);
173 color.set_rgb_p (0, 1, 0);
176 edgesmap[edge]->setFillColor(color);
181 int GraphDisplayerCanvas::resetEdgeColor (Edge edge)
184 //function maps the range of the maximum and
185 //the minimum of the nodemap to the range of
187 Graph::EdgeMap<double> actual_map((mytab.mapstorage)->graph,edge_property_defaults[E_COLOR]);
191 max=edge_property_defaults[E_COLOR];
192 min=edge_property_defaults[E_COLOR];
196 for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
198 double w=actual_map[i];
203 color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
207 color.set_rgb_p (0, 100, 0);
209 edgesmap[i]->setFillColor(color);
216 double w=actual_map[edge];
220 color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
224 color.set_rgb_p (0, 100, 0);
227 edgesmap[edge]->setFillColor(color);
232 int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Edge edge)
234 //the number in the map will be written on the edge
235 //EXCEPT when the name of the map is Default, because
236 //in that case empty string will be written, because
237 //that is the deleter map
241 for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
243 edgemap_to_edit=mapname;
244 double number=(*((mytab.mapstorage)->edgemap_storage)[mapname])[i];
246 std::ostringstream ostr;
249 edgetextmap[i]->property_text().set_value(ostr.str());
255 double number=(*((mytab.mapstorage)->edgemap_storage)[mapname])[edge];
257 std::ostringstream ostr;
260 edgetextmap[edge]->property_text().set_value(ostr.str());
267 int GraphDisplayerCanvas::resetEdgeText (Edge edge)
269 //the number in the map will be written on the edge
270 //EXCEPT when the name of the map is Default, because
271 //in that case empty string will be written, because
272 //that is the deleter map
276 for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
279 edgetextmap[i]->property_text().set_value("");
285 edgetextmap[edge]->property_text().set_value("");