COIN-OR::LEMON - Graph Library

Changeset 1604:4d037c2b66aa in lemon-0.x for lemon/graph_to_eps.h


Ignore:
Timestamp:
07/28/05 21:05:45 (14 years ago)
Author:
Alpar Juttner
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2109
Message:

Edge width and node size autoscaling added.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/graph_to_eps.h

    r1588 r1604  
    235235  ConstMap<typename Graph::Node,Color > _nodeTextColors;
    236236
     237  bool _autoNodeScale;
     238  bool _autoEdgeWidthScale;
     239
    237240  ///Constructor
    238241
     
    259262    _undir(false),
    260263    _pleaseRemoveOsStream(_pros), _scaleToA4(false),
    261     _nodeTextColorType(SAME_COL), _nodeTextColors(Color(0,0,0))
     264    _nodeTextColorType(SAME_COL), _nodeTextColors(Color(0,0,0)),
     265    _autoNodeScale(false),
     266    _autoEdgeWidthScale(false)
    262267  {}
    263268};
     
    325330  using T::_nodeTextColorType;
    326331  using T::_nodeTextColors;
     332
     333  using T::_autoNodeScale;
     334  using T::_autoEdgeWidthScale;
     335
    327336  // dradnats ++C eht yb deriuqer si ti eveileb t'naC
    328337
     
    552561  ///Sets a global scale factor for node sizes
    553562
    554   ///Sets a global scale factor for node sizes
    555   ///
     563  ///Sets a global scale factor for node sizes.
     564  ///
     565  /// If nodeSizes() is not given, this function simply sets the node
     566  /// sizes to \c d.  If nodeSizes() is given, but
     567  /// autoNodeScale() is not, then the node size given by
     568  /// nodeSizes() will be multiplied by the value \c d.
     569  /// If both nodeSizes() and autoNodeScale() are used, then the
     570  /// node sizes will be scaled in such a way that the greatest size will be
     571  /// equal to \c d.
    556572  GraphToEps<T> &nodeScale(double d) {_nodeScale=d;return *this;}
     573  ///Turns on/off the automatic node width scaling.
     574
     575  ///Turns on/off the automatic node width scaling.
     576  ///
     577  ///\sa nodeScale()
     578  ///
     579  GraphToEps<T> &autoNodeScale(bool b=true) {
     580    _autoNodeScale=b;return *this;
     581  }
    557582  ///Sets a global scale factor for edge widths
    558583
    559   ///Sets a global scale factor for edge widths
    560   ///
     584  /// Sets a global scale factor for edge widths.
     585  ///
     586  /// If edgeWidths() is not given, this function simply sets the edge
     587  /// widths to \c d.  If edgeWidths() is given, but
     588  /// autoEdgeWidthScale() is not, then the edge withs given by
     589  /// edgeWidths() will be multiplied by the value \c d.
     590  /// If both edgeWidths() and autoEdgeWidthScale() are used, then the
     591  /// edge withs will be scaled in such a way that the greatest width will be
     592  /// equal to \c d.
    561593  GraphToEps<T> &edgeWidthScale(double d) {_edgeWidthScale=d;return *this;}
     594  ///Turns on/off the automatic edge width scaling.
     595
     596  ///Turns on/off the automatic edge width scaling.
     597  ///
     598  ///\sa edgeWidthScale()
     599  ///
     600  GraphToEps<T> &autoEdgeWidthScale(bool b=true) {
     601    _autoEdgeWidthScale=b;return *this;
     602  }
    562603  ///Sets a global scale factor for the whole picture
    563604
    564605  ///Sets a global scale factor for the whole picture
    565606  ///
     607
    566608  GraphToEps<T> &scale(double d) {_scale=d;return *this;}
    567609  ///Sets the width of the border around the picture
     
    715757      os << "%%CreationDate: " << cbuf;
    716758    }
     759
     760    if (_autoEdgeWidthScale) {
     761      double max_w=0;
     762      for(EdgeIt e(g);e!=INVALID;++e)
     763        max_w=std::max(double(_edgeWidths[e]),max_w);
     764      ///\todo better 'epsilon' would be nice here.
     765      if(max_w>1e-9) {
     766        _edgeWidthScale/=max_w;
     767      }
     768    }
     769
     770    if (_autoNodeScale) {
     771      double max_s=0;
     772      for(NodeIt n(g);n!=INVALID;++n)
     773        max_s=std::max(double(_nodeSizes[n]),max_s);
     774      ///\todo better 'epsilon' would be nice here.
     775      if(max_s>1e-9) {
     776        _nodeScale/=max_s;
     777      }
     778    }
     779
     780
    717781    BoundingBox<double> bb;
    718782    ///\bug: Chech whether the graph is empty.
     
    726790      bb = BoundingBox<double>(xy<double>(0,0));
    727791    }
     792   
    728793    if(_scaleToA4)
    729794      os <<"%%BoundingBox: 0 0 596 842\n%%DocumentPaperSizes: a4\n";
Note: See TracChangeset for help on using the changeset viewer.