diff -r 416a7030b7e3 -r 0d7c0f96a5ee lemon/graph_to_eps.h --- a/lemon/graph_to_eps.h Fri Aug 11 14:55:33 2006 +0000 +++ b/lemon/graph_to_eps.h Mon Aug 14 15:15:57 2006 +0000 @@ -38,7 +38,7 @@ #include #include #include -#include +#include ///\ingroup eps_io @@ -130,6 +130,9 @@ bool _autoNodeScale; bool _autoEdgeWidthScale; + bool _absoluteNodeSizes; + bool _absoluteEdgeWidths; + bool _negY; ///Constructor @@ -143,9 +146,9 @@ DefaultGraphToEpsTraits(const G &_g,std::ostream& _os=std::cout, bool _pros=false) : g(_g), os(_os), - _coords(xy(1,1)), _nodeSizes(1.0), _nodeShapes(0), + _coords(xy(1,1)), _nodeSizes(.01), _nodeShapes(0), _nodeColors(WHITE), _edgeColors(BLACK), - _edgeWidths(1), _edgeWidthScale(0.3), + _edgeWidths(1.0), _edgeWidthScale(0.003), _nodeScale(1.0), _xBorder(10), _yBorder(10), _scale(1.0), _nodeBorderQuotient(.1), _drawArrows(false), _arrowLength(1), _arrowWidth(0.3), @@ -158,6 +161,8 @@ _nodeTextColorType(SAME_COL), _nodeTextColors(BLACK), _autoNodeScale(false), _autoEdgeWidthScale(false), + _absoluteNodeSizes(false), + _absoluteEdgeWidths(false), _negY(false) {} }; @@ -229,6 +234,10 @@ using T::_autoNodeScale; using T::_autoEdgeWidthScale; + using T::_absoluteNodeSizes; + using T::_absoluteEdgeWidths; + + using T::_negY; // dradnats ++C eht yb deriuqer si ti eveileb t'naC @@ -478,6 +487,8 @@ /// 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. + /// \sa nodeSizes() + /// \sa autoNodeScale() GraphToEps &nodeScale(double d) {_nodeScale=d;return *this;} ///Turns on/off the automatic node width scaling. @@ -489,6 +500,16 @@ _autoNodeScale=b;return *this; } + ///Turns on/off the absolutematic node width scaling. + + ///Turns on/off the absolutematic node width scaling. + /// + ///\sa nodeScale() + /// + GraphToEps &absoluteNodeSizes(bool b=true) { + _absoluteNodeSizes=b;return *this; + } + ///Negates the Y coordinates. ///Negates the Y coordinates. @@ -520,6 +541,15 @@ GraphToEps &autoEdgeWidthScale(bool b=true) { _autoEdgeWidthScale=b;return *this; } + ///Turns on/off the absolutematic edge width scaling. + + ///Turns on/off the absolutematic edge width scaling. + /// + ///\sa edgeWidthScale() + /// + GraphToEps &absoluteEdgeWidths(bool b=true) { + _absoluteEdgeWidths=b;return *this; + } ///Sets a global scale factor for the whole picture ///Sets a global scale factor for the whole picture @@ -664,6 +694,8 @@ ///this function calles the algorithm itself, i.e. in this case ///it draws the graph. void run() { + ///\todo better 'epsilon' would be nice here. + const double EPSILON=1e-9; if(dontPrint) return; _NegY mycoords(_coords,_negY); @@ -687,7 +719,7 @@ 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) { + if(max_w>EPSILON) { _edgeWidthScale/=max_w; } } @@ -697,14 +729,25 @@ 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) { + if(max_s>EPSILON) { _nodeScale/=max_s; } } - + double diag_len = 1; + if(!(_absoluteNodeSizes&&_absoluteEdgeWidths)) { + BoundingBox bb; + for(NodeIt n(g);n!=INVALID;++n) bb.add(mycoords[n]); + if (bb.empty()) { + bb = BoundingBox(xy(0,0)); + } + diag_len = std::sqrt((bb.bottomLeft()-bb.topRight()).normSquare()); + if(diag_len bb; - ///\bug: Chech whether the graph is empty. for(NodeIt n(g);n!=INVALID;++n) { double ns=_nodeSizes[n]*_nodeScale; xy p(ns,ns); @@ -864,7 +907,7 @@ xy dvec(mycoords[g.target(*i)]-mycoords[g.source(*i)]); double l=std::sqrt(dvec.normSquare()); ///\todo better 'epsilon' would be nice here. - xy d(dvec/std::max(l,1e-9)); + xy d(dvec/std::max(l,EPSILON)); xy m; // m=xy(mycoords[g.target(*i)]+mycoords[g.source(*i)])/2.0;