# HG changeset patch # User alpar # Date 1125602495 0 # Node ID 8919ca9e70f3cbccfe7108fb0387128988e59a6a # Parent 85e30ec7c9574921c59e784650868671cc61a864 negateY() option added. diff -r 85e30ec7c957 -r 8919ca9e70f3 lemon/graph_to_eps.h --- a/lemon/graph_to_eps.h Thu Sep 01 12:14:14 2005 +0000 +++ b/lemon/graph_to_eps.h Thu Sep 01 19:21:35 2005 +0000 @@ -169,6 +169,17 @@ return Color(v,v,v); } +template +class _NegY { +public: + typedef typename MT::Key Key; + typedef typename MT::Value Value; + const MT ↦ + int yscale; + _NegY(const MT &m,bool b) : map(m), yscale(1-b*2) {} + Value operator[](Key n) { return Value(map[n].x,map[n].y*yscale);} +}; + ///Default traits class of \ref GraphToEps ///Default traits class of \ref GraphToEps @@ -190,7 +201,8 @@ std::ostream& os; - ConstMap > _coords; + typedef ConstMap > CoordsMapType; + CoordsMapType _coords; ConstMap _nodeSizes; ConstMap _nodeShapes; @@ -237,6 +249,7 @@ bool _autoNodeScale; bool _autoEdgeWidthScale; + bool _negY; ///Constructor ///Constructor @@ -263,7 +276,8 @@ _pleaseRemoveOsStream(_pros), _scaleToA4(false), _nodeTextColorType(SAME_COL), _nodeTextColors(Color(0,0,0)), _autoNodeScale(false), - _autoEdgeWidthScale(false) + _autoEdgeWidthScale(false), + _negY(false) {} }; @@ -413,6 +427,7 @@ GraphToEps(const T &t) : T(t), dontPrint(false) {}; template struct CoordsTraits : public T { + typedef X CoordsMapType; const X &_coords; CoordsTraits(const T &t,const X &x) : T(t), _coords(x) {} }; @@ -579,6 +594,17 @@ GraphToEps &autoNodeScale(bool b=true) { _autoNodeScale=b;return *this; } + + ///Negates the Y coordinates. + + ///Negates the Y coordinates. + /// + ///\todo More docs. + /// + GraphToEps &negateY(bool b=true) { + _negY=b;return *this; + } + ///Sets a global scale factor for edge widths /// Sets a global scale factor for edge widths. @@ -743,6 +769,8 @@ void run() { if(dontPrint) return; + _NegY mycoords(_coords,_negY); + os << "%!PS-Adobe-2.0 EPSF-2.0\n"; if(_title.size()>0) os << "%%Title: " << _title << '\n'; if(_copyright.size()>0) os << "%%Copyright: " << _copyright << '\n'; @@ -783,8 +811,8 @@ for(NodeIt n(g);n!=INVALID;++n) { double ns=_nodeSizes[n]*_nodeScale; xy p(ns,ns); - bb.add(p+_coords[n]); - bb.add(-p+_coords[n]); + bb.add(p+mycoords[n]); + bb.add(-p+mycoords[n]); } if (bb.empty()) { bb = BoundingBox(xy(0,0)); @@ -888,18 +916,18 @@ sw+=_edgeWidths[*e]*_edgeWidthScale+_parEdgeDist; sw-=_parEdgeDist; sw/=-2.0; - xy dvec(_coords[g.target(*i)]-_coords[g.source(*i)]); + 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 m; -// m=xy(_coords[g.target(*i)]+_coords[g.source(*i)])/2.0; +// m=xy(mycoords[g.target(*i)]+mycoords[g.source(*i)])/2.0; -// m=xy(_coords[g.source(*i)])+ +// m=xy(mycoords[g.source(*i)])+ // dvec*(double(_nodeSizes[g.source(*i)])/ // (_nodeSizes[g.source(*i)]+_nodeSizes[g.target(*i)])); - m=xy(_coords[g.source(*i)])+ + m=xy(mycoords[g.source(*i)])+ d*(l+_nodeSizes[g.source(*i)]-_nodeSizes[g.target(*i)])/2.0; for(typename std::vector::iterator e=i;e!=j;++e) { @@ -907,8 +935,8 @@ xy mm=m+rot90(d)*sw/.75; if(_drawArrows) { int node_shape; - xy s=_coords[g.source(*e)]; - xy t=_coords[g.target(*e)]; + xy s=mycoords[g.source(*e)]; + xy t=mycoords[g.target(*e)]; double rn=_nodeSizes[g.target(*e)]*_nodeScale; node_shape=_nodeShapes[g.target(*e)]; Bezier3 bez(s,mm,mm,t); @@ -948,11 +976,11 @@ << psOut(linend-dd) << " lineto closepath fill\n"; } else { - os << _coords[g.source(*e)].x << ' ' - << _coords[g.source(*e)].y << ' ' + os << mycoords[g.source(*e)].x << ' ' + << mycoords[g.source(*e)].y << ' ' << mm.x << ' ' << mm.y << ' ' - << _coords[g.target(*e)].x << ' ' - << _coords[g.target(*e)].y << ' ' + << mycoords[g.target(*e)].x << ' ' + << mycoords[g.target(*e)].y << ' ' << _edgeColors[*e].red() << ' ' << _edgeColors[*e].green() << ' ' << _edgeColors[*e].blue() << ' ' @@ -965,7 +993,7 @@ else for(EdgeIt e(g);e!=INVALID;++e) if((!_undir||g.source(e)0) if(_drawArrows) { - xy d(_coords[g.target(e)]-_coords[g.source(e)]); + xy d(mycoords[g.target(e)]-mycoords[g.source(e)]); double rn=_nodeSizes[g.target(e)]*_nodeScale; int node_shape=_nodeShapes[g.target(e)]; double t1=0,t2=1; @@ -978,16 +1006,16 @@ os << l*(1-(t1+t2)/2) << ' ' << _edgeWidths[e]*_edgeWidthScale << ' ' << d.x << ' ' << d.y << ' ' - << _coords[g.source(e)].x << ' ' - << _coords[g.source(e)].y << ' ' + << mycoords[g.source(e)].x << ' ' + << mycoords[g.source(e)].y << ' ' << _edgeColors[e].red() << ' ' << _edgeColors[e].green() << ' ' << _edgeColors[e].blue() << " arr\n"; } - else os << _coords[g.source(e)].x << ' ' - << _coords[g.source(e)].y << ' ' - << _coords[g.target(e)].x << ' ' - << _coords[g.target(e)].y << ' ' + else os << mycoords[g.source(e)].x << ' ' + << mycoords[g.source(e)].y << ' ' + << mycoords[g.target(e)].x << ' ' + << mycoords[g.target(e)].y << ' ' << _edgeColors[e].red() << ' ' << _edgeColors[e].green() << ' ' << _edgeColors[e].blue() << ' ' @@ -997,7 +1025,7 @@ if(_showNodes) { os << "%Nodes:\ngsave\n"; for(NodeIt n(g);n!=INVALID;++n) { - os << _coords[n].x << ' ' << _coords[n].y << ' ' + os << mycoords[n].x << ' ' << mycoords[n].y << ' ' << _nodeSizes[n]*_nodeScale << ' ' << _nodeColors[n].red() << ' ' << _nodeColors[n].green() << ' ' @@ -1032,7 +1060,7 @@ default: os << "0 0 0 setrgbcolor\n"; } - os << _coords[n].x << ' ' << _coords[n].y + os << mycoords[n].x << ' ' << mycoords[n].y << " (" << _nodeTexts[n] << ") cshow\n"; } os << "grestore\n"; @@ -1040,7 +1068,7 @@ if(_showNodePsText) { os << "%Node PS blocks:\ngsave\n"; for(NodeIt n(g);n!=INVALID;++n) - os << _coords[n].x << ' ' << _coords[n].y + os << mycoords[n].x << ' ' << mycoords[n].y << " moveto\n" << _nodePsTexts[n] << "\n"; os << "grestore\n"; }