Zoom is now available with mouse-wheel.
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"
22 const int minimum_edge_width=0;
24 int GraphDisplayerCanvas::resetEdgeWidth (Edge edge)
28 min=edge_property_defaults[E_WIDTH];
29 max=edge_property_defaults[E_WIDTH];
30 Graph::EdgeMap<double> actual_map((mytab.mapstorage).graph,edge_property_defaults[E_WIDTH]);
34 for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
36 double v=fabs(actual_map[i]);
40 w=(int)(edge_property_defaults[E_WIDTH]);
44 w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH));
48 double actual_ppu=get_pixels_per_unit();
49 w=(int)(w/actual_ppu*fixed_zoom_factor);
51 edgesmap[i]->setLineWidth(w);
56 int w=(int)actual_map[edge];
59 edgesmap[edge]->setLineWidth(w);
66 int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Edge edge)
68 Graph::EdgeMap<double> * actual_map;
71 min=(mytab.mapstorage).minOfEdgeMap(mapname);
72 max=(mytab.mapstorage).maxOfEdgeMap(mapname);
73 actual_map=((mytab.mapstorage).edgemap_storage)[mapname];
77 for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
79 double v=(*actual_map)[i];
85 w=(int)(edge_property_defaults[E_WIDTH]);
89 w=(int)(minimum_edge_width+(v-min)/(max-min)*(edge_width-minimum_edge_width));
94 w=(int)(v*edge_width);
103 if(w<minimum_edge_width)
105 w=minimum_edge_width;
109 double actual_ppu=get_pixels_per_unit();
110 w=(int)(w/actual_ppu*fixed_zoom_factor);
112 edgesmap[i]->setLineWidth(w);
118 int w=(int)(*actual_map)[edge];
121 edgesmap[edge]->setLineWidth(w);
127 int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Edge edge)
130 //function maps the range of the maximum and
131 //the minimum of the nodemap to the range of
133 Graph::EdgeMap<double> * actual_map;
134 actual_map=((mytab.mapstorage).edgemap_storage)[mapname];
138 max=(mytab.mapstorage).maxOfEdgeMap(mapname);
139 min=(mytab.mapstorage).minOfEdgeMap(mapname);
143 for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
145 double w=(*actual_map)[i];
150 color=rainbowColorCounter(min, max, w);
154 color.set_rgb_p (0, 1, 0);
156 edgesmap[i]->setFillColor(color);
163 double w=(*actual_map)[edge];
167 color=rainbowColorCounter(min, max, w);
171 color.set_rgb_p (0, 1, 0);
174 edgesmap[edge]->setFillColor(color);
179 int GraphDisplayerCanvas::resetEdgeColor (Edge edge)
182 //function maps the range of the maximum and
183 //the minimum of the nodemap to the range of
185 Graph::EdgeMap<double> actual_map((mytab.mapstorage).graph,edge_property_defaults[E_COLOR]);
189 max=edge_property_defaults[E_COLOR];
190 min=edge_property_defaults[E_COLOR];
194 for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
196 double w=actual_map[i];
201 color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
205 color.set_rgb_p (0, 100, 0);
207 edgesmap[i]->setFillColor(color);
214 double w=actual_map[edge];
218 color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
222 color.set_rgb_p (0, 100, 0);
225 edgesmap[edge]->setFillColor(color);
230 int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Edge edge)
232 //the number in the map will be written on the edge
233 //EXCEPT when the name of the map is Default, because
234 //in that case empty string will be written, because
235 //that is the deleter map
239 for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
241 edgemap_to_edit=mapname;
242 double number=(*((mytab.mapstorage).edgemap_storage)[mapname])[i];
244 std::ostringstream ostr;
247 edgetextmap[i]->property_text().set_value(ostr.str());
253 double number=(*((mytab.mapstorage).edgemap_storage)[mapname])[edge];
255 std::ostringstream ostr;
258 edgetextmap[edge]->property_text().set_value(ostr.str());
265 int GraphDisplayerCanvas::resetEdgeText (Edge edge)
267 //the number in the map will be written on the edge
268 //EXCEPT when the name of the map is Default, because
269 //in that case empty string will be written, because
270 //that is the deleter map
274 for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
277 edgetextmap[i]->property_text().set_value("");
283 edgetextmap[edge]->property_text().set_value("");