# HG changeset patch # User alpar # Date 1122577545 0 # Node ID 4d037c2b66aa56af8205ad50a682d22299699e9c # Parent 5ad84fbadf2bbab4c4191f33ce68c1db543308e4 Edge width and node size autoscaling added. diff -r 5ad84fbadf2b -r 4d037c2b66aa lemon/graph_to_eps.h --- a/lemon/graph_to_eps.h Thu Jul 28 19:04:43 2005 +0000 +++ b/lemon/graph_to_eps.h Thu Jul 28 19:05:45 2005 +0000 @@ -234,6 +234,9 @@ { DIST_COL=0, DIST_BW=1, CUST_COL=2, SAME_COL=3 } _nodeTextColorType; ConstMap _nodeTextColors; + bool _autoNodeScale; + bool _autoEdgeWidthScale; + ///Constructor ///Constructor @@ -258,7 +261,9 @@ _showNodePsText(false), _nodePsTexts(false), _nodePsTextsPreamble(0), _undir(false), _pleaseRemoveOsStream(_pros), _scaleToA4(false), - _nodeTextColorType(SAME_COL), _nodeTextColors(Color(0,0,0)) + _nodeTextColorType(SAME_COL), _nodeTextColors(Color(0,0,0)), + _autoNodeScale(false), + _autoEdgeWidthScale(false) {} }; @@ -324,6 +329,10 @@ using T::DIST_BW; using T::_nodeTextColorType; using T::_nodeTextColors; + + using T::_autoNodeScale; + using T::_autoEdgeWidthScale; + // dradnats ++C eht yb deriuqer si ti eveileb t'naC typedef typename T::Graph Graph; @@ -551,18 +560,51 @@ } ///Sets a global scale factor for node sizes - ///Sets a global scale factor for node sizes + ///Sets a global scale factor for node sizes. + /// + /// If nodeSizes() is not given, this function simply sets the node + /// sizes to \c d. If nodeSizes() is given, but + /// autoNodeScale() is not, then the node size given by + /// nodeSizes() will be multiplied by the value \c d. + /// If both nodeSizes() and autoNodeScale() are used, then the + /// node sizes will be scaled in such a way that the greatest size will be + /// equal to \c d. + GraphToEps &nodeScale(double d) {_nodeScale=d;return *this;} + ///Turns on/off the automatic node width scaling. + + ///Turns on/off the automatic node width scaling. /// - GraphToEps &nodeScale(double d) {_nodeScale=d;return *this;} + ///\sa nodeScale() + /// + GraphToEps &autoNodeScale(bool b=true) { + _autoNodeScale=b;return *this; + } ///Sets a global scale factor for edge widths - ///Sets a global scale factor for edge widths + /// Sets a global scale factor for edge widths. /// + /// If edgeWidths() is not given, this function simply sets the edge + /// widths to \c d. If edgeWidths() is given, but + /// autoEdgeWidthScale() is not, then the edge withs given by + /// edgeWidths() will be multiplied by the value \c d. + /// If both edgeWidths() and autoEdgeWidthScale() are used, then the + /// edge withs will be scaled in such a way that the greatest width will be + /// equal to \c d. GraphToEps &edgeWidthScale(double d) {_edgeWidthScale=d;return *this;} + ///Turns on/off the automatic edge width scaling. + + ///Turns on/off the automatic edge width scaling. + /// + ///\sa edgeWidthScale() + /// + GraphToEps &autoEdgeWidthScale(bool b=true) { + _autoEdgeWidthScale=b;return *this; + } ///Sets a global scale factor for the whole picture ///Sets a global scale factor for the whole picture /// + GraphToEps &scale(double d) {_scale=d;return *this;} ///Sets the width of the border around the picture @@ -714,6 +756,28 @@ ctime_r(&tv.tv_sec,cbuf); os << "%%CreationDate: " << cbuf; } + + if (_autoEdgeWidthScale) { + double max_w=0; + for(EdgeIt e(g);e!=INVALID;++e) + max_w=std::max(double(_edgeWidths[e]),max_w); + ///\todo better 'epsilon' would be nice here. + if(max_w>1e-9) { + _edgeWidthScale/=max_w; + } + } + + if (_autoNodeScale) { + double max_s=0; + for(NodeIt n(g);n!=INVALID;++n) + max_s=std::max(double(_nodeSizes[n]),max_s); + ///\todo better 'epsilon' would be nice here. + if(max_s>1e-9) { + _nodeScale/=max_s; + } + } + + BoundingBox bb; ///\bug: Chech whether the graph is empty. for(NodeIt n(g);n!=INVALID;++n) { @@ -725,6 +789,7 @@ if (bb.empty()) { bb = BoundingBox(xy(0,0)); } + if(_scaleToA4) os <<"%%BoundingBox: 0 0 596 842\n%%DocumentPaperSizes: a4\n"; else os << "%%BoundingBox: "