COIN-OR::LEMON - Graph Library

source: glemon-0.x/graph_displayer_canvas-edge.cc @ 161:aef1fbfd9d60

Last change on this file since 161:aef1fbfd9d60 was 157:7e6ad28aeb9e, checked in by Hegyi Péter, 18 years ago

View settings also for edges.

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