Edge width and node size autoscaling added.
authoralpar
Thu, 28 Jul 2005 19:05:45 +0000
changeset 16044d037c2b66aa
parent 1603 5ad84fbadf2b
child 1605 4fa618f7aa69
Edge width and node size autoscaling added.
lemon/graph_to_eps.h
     1.1 --- a/lemon/graph_to_eps.h	Thu Jul 28 19:04:43 2005 +0000
     1.2 +++ b/lemon/graph_to_eps.h	Thu Jul 28 19:05:45 2005 +0000
     1.3 @@ -234,6 +234,9 @@
     1.4      { DIST_COL=0, DIST_BW=1, CUST_COL=2, SAME_COL=3 } _nodeTextColorType;
     1.5    ConstMap<typename Graph::Node,Color > _nodeTextColors;
     1.6  
     1.7 +  bool _autoNodeScale;
     1.8 +  bool _autoEdgeWidthScale;
     1.9 +
    1.10    ///Constructor
    1.11  
    1.12    ///Constructor
    1.13 @@ -258,7 +261,9 @@
    1.14      _showNodePsText(false), _nodePsTexts(false), _nodePsTextsPreamble(0),
    1.15      _undir(false),
    1.16      _pleaseRemoveOsStream(_pros), _scaleToA4(false),
    1.17 -    _nodeTextColorType(SAME_COL), _nodeTextColors(Color(0,0,0))
    1.18 +    _nodeTextColorType(SAME_COL), _nodeTextColors(Color(0,0,0)),
    1.19 +    _autoNodeScale(false),
    1.20 +    _autoEdgeWidthScale(false)
    1.21    {}
    1.22  };
    1.23  
    1.24 @@ -324,6 +329,10 @@
    1.25    using T::DIST_BW;
    1.26    using T::_nodeTextColorType;
    1.27    using T::_nodeTextColors;
    1.28 +
    1.29 +  using T::_autoNodeScale;
    1.30 +  using T::_autoEdgeWidthScale;
    1.31 +
    1.32    // dradnats ++C eht yb deriuqer si ti eveileb t'naC
    1.33  
    1.34    typedef typename T::Graph Graph;
    1.35 @@ -551,18 +560,51 @@
    1.36    }
    1.37    ///Sets a global scale factor for node sizes
    1.38  
    1.39 -  ///Sets a global scale factor for node sizes
    1.40 +  ///Sets a global scale factor for node sizes.
    1.41 +  /// 
    1.42 +  /// If nodeSizes() is not given, this function simply sets the node
    1.43 +  /// sizes to \c d.  If nodeSizes() is given, but
    1.44 +  /// autoNodeScale() is not, then the node size given by
    1.45 +  /// nodeSizes() will be multiplied by the value \c d.
    1.46 +  /// If both nodeSizes() and autoNodeScale() are used, then the
    1.47 +  /// node sizes will be scaled in such a way that the greatest size will be
    1.48 +  /// equal to \c d.
    1.49 +  GraphToEps<T> &nodeScale(double d) {_nodeScale=d;return *this;}
    1.50 +  ///Turns on/off the automatic node width scaling.
    1.51 +
    1.52 +  ///Turns on/off the automatic node width scaling.
    1.53    ///
    1.54 -  GraphToEps<T> &nodeScale(double d) {_nodeScale=d;return *this;}
    1.55 +  ///\sa nodeScale()
    1.56 +  ///
    1.57 +  GraphToEps<T> &autoNodeScale(bool b=true) {
    1.58 +    _autoNodeScale=b;return *this;
    1.59 +  }
    1.60    ///Sets a global scale factor for edge widths
    1.61  
    1.62 -  ///Sets a global scale factor for edge widths
    1.63 +  /// Sets a global scale factor for edge widths.
    1.64    ///
    1.65 +  /// If edgeWidths() is not given, this function simply sets the edge
    1.66 +  /// widths to \c d.  If edgeWidths() is given, but
    1.67 +  /// autoEdgeWidthScale() is not, then the edge withs given by
    1.68 +  /// edgeWidths() will be multiplied by the value \c d.
    1.69 +  /// If both edgeWidths() and autoEdgeWidthScale() are used, then the
    1.70 +  /// edge withs will be scaled in such a way that the greatest width will be
    1.71 +  /// equal to \c d.
    1.72    GraphToEps<T> &edgeWidthScale(double d) {_edgeWidthScale=d;return *this;}
    1.73 +  ///Turns on/off the automatic edge width scaling.
    1.74 +
    1.75 +  ///Turns on/off the automatic edge width scaling.
    1.76 +  ///
    1.77 +  ///\sa edgeWidthScale()
    1.78 +  ///
    1.79 +  GraphToEps<T> &autoEdgeWidthScale(bool b=true) {
    1.80 +    _autoEdgeWidthScale=b;return *this;
    1.81 +  }
    1.82    ///Sets a global scale factor for the whole picture
    1.83  
    1.84    ///Sets a global scale factor for the whole picture
    1.85    ///
    1.86 +
    1.87    GraphToEps<T> &scale(double d) {_scale=d;return *this;}
    1.88    ///Sets the width of the border around the picture
    1.89  
    1.90 @@ -714,6 +756,28 @@
    1.91        ctime_r(&tv.tv_sec,cbuf);
    1.92        os << "%%CreationDate: " << cbuf;
    1.93      }
    1.94 +
    1.95 +    if (_autoEdgeWidthScale) {
    1.96 +      double max_w=0;
    1.97 +      for(EdgeIt e(g);e!=INVALID;++e)
    1.98 +	max_w=std::max(double(_edgeWidths[e]),max_w);
    1.99 +      ///\todo better 'epsilon' would be nice here.
   1.100 +      if(max_w>1e-9) {
   1.101 +	_edgeWidthScale/=max_w;
   1.102 +      }
   1.103 +    }
   1.104 +
   1.105 +    if (_autoNodeScale) {
   1.106 +      double max_s=0;
   1.107 +      for(NodeIt n(g);n!=INVALID;++n)
   1.108 +	max_s=std::max(double(_nodeSizes[n]),max_s);
   1.109 +      ///\todo better 'epsilon' would be nice here.
   1.110 +      if(max_s>1e-9) {
   1.111 +	_nodeScale/=max_s;
   1.112 +      }
   1.113 +    }
   1.114 +
   1.115 +
   1.116      BoundingBox<double> bb;
   1.117      ///\bug: Chech whether the graph is empty.
   1.118      for(NodeIt n(g);n!=INVALID;++n) {
   1.119 @@ -725,6 +789,7 @@
   1.120      if (bb.empty()) {
   1.121        bb = BoundingBox<double>(xy<double>(0,0));
   1.122      }
   1.123 +    
   1.124      if(_scaleToA4)
   1.125        os <<"%%BoundingBox: 0 0 596 842\n%%DocumentPaperSizes: a4\n";
   1.126      else os << "%%BoundingBox: "