# HG changeset patch # User Peter Kovacs # Date 2008-07-13 17:34:27 # Node ID 4e22275a2b52ba05233b85c94e124cda790d2c93 # Parent 1e6af6f0843c373a0579fc699ac4a83bb4f5948a Improvements related to graphToEps() diff --git a/demo/graph_to_eps_demo.cc b/demo/graph_to_eps_demo.cc --- a/demo/graph_to_eps_demo.cc +++ b/demo/graph_to_eps_demo.cc @@ -18,23 +18,22 @@ /// \ingroup demos /// \file -/// \brief Demo of the graph grawing function \ref graphToEps() +/// \brief Demo of the graph drawing function \ref graphToEps() /// /// This demo program shows examples how to use the function \ref /// graphToEps(). It takes no input but simply creates six /// .eps files demonstrating the capability of \ref -/// graphToEps(), and showing how to draw directed/graphs, +/// graphToEps(), and showing how to draw directed graphs, /// how to handle parallel egdes, how to change the properties (like /// color, shape, size, title etc.) of nodes and arcs individually /// using appropriate \ref maps-page "graph maps". /// /// \include graph_to_eps_demo.cc -#include - -#include #include #include +#include +#include using namespace std; using namespace lemon; @@ -44,6 +43,7 @@ Palette palette; Palette paletteW(true); + // Create a small digraph ListDigraph g; typedef ListDigraph::Node Node; typedef ListDigraph::NodeIt NodeIt; @@ -60,7 +60,7 @@ ListDigraph::NodeMap sizes(g); ListDigraph::NodeMap colors(g); ListDigraph::NodeMap shapes(g); - ListDigraph::ArcMap ecolors(g); + ListDigraph::ArcMap acolors(g); ListDigraph::ArcMap widths(g); coords[n1]=Point(50,50); sizes[n1]=1; colors[n1]=1; shapes[n1]=0; @@ -69,118 +69,116 @@ coords[n4]=Point(70,50); sizes[n4]=2; colors[n4]=4; shapes[n4]=1; coords[n5]=Point(85,60); sizes[n5]=3; colors[n5]=5; shapes[n5]=2; - Arc e; + Arc a; - e=g.addArc(n1,n2); ecolors[e]=0; widths[e]=1; - e=g.addArc(n2,n3); ecolors[e]=0; widths[e]=1; - e=g.addArc(n3,n5); ecolors[e]=0; widths[e]=3; - e=g.addArc(n5,n4); ecolors[e]=0; widths[e]=1; - e=g.addArc(n4,n1); ecolors[e]=0; widths[e]=1; - e=g.addArc(n2,n4); ecolors[e]=1; widths[e]=2; - e=g.addArc(n3,n4); ecolors[e]=2; widths[e]=1; + a=g.addArc(n1,n2); acolors[a]=0; widths[a]=1; + a=g.addArc(n2,n3); acolors[a]=0; widths[a]=1; + a=g.addArc(n3,n5); acolors[a]=0; widths[a]=3; + a=g.addArc(n5,n4); acolors[a]=0; widths[a]=1; + a=g.addArc(n4,n1); acolors[a]=0; widths[a]=1; + a=g.addArc(n2,n4); acolors[a]=1; widths[a]=2; + a=g.addArc(n3,n4); acolors[a]=2; widths[a]=1; IdMap id(g); - cout << "Create 'graph_to_eps_demo_out_pure.eps'" << endl; - graphToEps(g,"graph_to_eps_demo_out_pure.eps"). - //scale(10). + // Create five .eps files showing the digraph with different options + cout << "Create 'graph_to_eps_demo_out_1_pure.eps'" << endl; + graphToEps(g,"graph_to_eps_demo_out_1_pure.eps"). coords(coords). title("Sample .eps figure"). - copyright("(C) 2003-2007 LEMON Project"). + copyright("(C) 2003-2008 LEMON Project"). run(); - cout << "Create 'graph_to_eps_demo_out.eps'" << endl; - graphToEps(g,"graph_to_eps_demo_out.eps"). - //scale(10). + cout << "Create 'graph_to_eps_demo_out_2.eps'" << endl; + graphToEps(g,"graph_to_eps_demo_out_2.eps"). coords(coords). title("Sample .eps figure"). - copyright("(C) 2003-2007 LEMON Project"). + copyright("(C) 2003-2008 LEMON Project"). absoluteNodeSizes().absoluteArcWidths(). nodeScale(2).nodeSizes(sizes). nodeShapes(shapes). nodeColors(composeMap(palette,colors)). - arcColors(composeMap(palette,ecolors)). + arcColors(composeMap(palette,acolors)). arcWidthScale(.4).arcWidths(widths). nodeTexts(id).nodeTextSize(3). run(); - - cout << "Create 'graph_to_eps_demo_out_arr.eps'" << endl; - graphToEps(g,"graph_to_eps_demo_out_arr.eps"). - //scale(10). + cout << "Create 'graph_to_eps_demo_out_3_arr.eps'" << endl; + graphToEps(g,"graph_to_eps_demo_out_3_arr.eps"). title("Sample .eps figure (with arrowheads)"). - copyright("(C) 2003-2007 LEMON Project"). + copyright("(C) 2003-2008 LEMON Project"). absoluteNodeSizes().absoluteArcWidths(). nodeColors(composeMap(palette,colors)). coords(coords). nodeScale(2).nodeSizes(sizes). nodeShapes(shapes). - arcColors(composeMap(palette,ecolors)). + arcColors(composeMap(palette,acolors)). arcWidthScale(.4).arcWidths(widths). nodeTexts(id).nodeTextSize(3). - drawArrows().arrowWidth(1).arrowLength(1). + drawArrows().arrowWidth(2).arrowLength(2). run(); - e=g.addArc(n1,n4); ecolors[e]=2; widths[e]=1; - e=g.addArc(n4,n1); ecolors[e]=1; widths[e]=2; + a=g.addArc(n1,n4); acolors[a]=2; widths[a]=1; + a=g.addArc(n4,n1); acolors[a]=1; widths[a]=2; - e=g.addArc(n1,n2); ecolors[e]=1; widths[e]=1; - e=g.addArc(n1,n2); ecolors[e]=2; widths[e]=1; - e=g.addArc(n1,n2); ecolors[e]=3; widths[e]=1; - e=g.addArc(n1,n2); ecolors[e]=4; widths[e]=1; - e=g.addArc(n1,n2); ecolors[e]=5; widths[e]=1; - e=g.addArc(n1,n2); ecolors[e]=6; widths[e]=1; - e=g.addArc(n1,n2); ecolors[e]=7; widths[e]=1; + a=g.addArc(n1,n2); acolors[a]=1; widths[a]=1; + a=g.addArc(n1,n2); acolors[a]=2; widths[a]=1; + a=g.addArc(n1,n2); acolors[a]=3; widths[a]=1; + a=g.addArc(n1,n2); acolors[a]=4; widths[a]=1; + a=g.addArc(n1,n2); acolors[a]=5; widths[a]=1; + a=g.addArc(n1,n2); acolors[a]=6; widths[a]=1; + a=g.addArc(n1,n2); acolors[a]=7; widths[a]=1; cout << "Create 'graph_to_eps_demo_out_par.eps'" << endl; graphToEps(g,"graph_to_eps_demo_out_par.eps"). //scale(10). title("Sample .eps figure (parallel arcs)"). - copyright("(C) 2003-2007 LEMON Project"). + copyright("(C) 2003-2008 LEMON Project"). absoluteNodeSizes().absoluteArcWidths(). nodeShapes(shapes). coords(coords). nodeScale(2).nodeSizes(sizes). nodeColors(composeMap(palette,colors)). - arcColors(composeMap(palette,ecolors)). + arcColors(composeMap(palette,acolors)). arcWidthScale(.4).arcWidths(widths). nodeTexts(id).nodeTextSize(3). enableParallel().parArcDist(1.5). run(); - - cout << "Create 'graph_to_eps_demo_out_par_arr.eps'" << endl; - graphToEps(g,"graph_to_eps_demo_out_par_arr.eps"). - //scale(10). + + cout << "Create 'graph_to_eps_demo_out_4_par_arr.eps'" << endl; + graphToEps(g,"graph_to_eps_demo_out_4_par_arr.eps"). title("Sample .eps figure (parallel arcs and arrowheads)"). - copyright("(C) 2003-2007 LEMON Project"). + copyright("(C) 2003-2008 LEMON Project"). absoluteNodeSizes().absoluteArcWidths(). nodeScale(2).nodeSizes(sizes). coords(coords). nodeShapes(shapes). nodeColors(composeMap(palette,colors)). - arcColors(composeMap(palette,ecolors)). + arcColors(composeMap(palette,acolors)). arcWidthScale(.3).arcWidths(widths). nodeTexts(id).nodeTextSize(3). enableParallel().parArcDist(1). drawArrows().arrowWidth(1).arrowLength(1). run(); - cout << "Create 'graph_to_eps_demo_out_a4.eps'" << endl; - graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4(). + cout << "Create 'graph_to_eps_demo_out_5_par_arr_a4.eps'" << endl; + graphToEps(g,"graph_to_eps_demo_out_5_par_arr_a4.eps"). title("Sample .eps figure (fits to A4)"). - copyright("(C) 2003-2007 LEMON Project"). + copyright("(C) 2003-2008 LEMON Project"). + scaleToA4(). absoluteNodeSizes().absoluteArcWidths(). nodeScale(2).nodeSizes(sizes). coords(coords). nodeShapes(shapes). nodeColors(composeMap(palette,colors)). - arcColors(composeMap(palette,ecolors)). + arcColors(composeMap(palette,acolors)). arcWidthScale(.3).arcWidths(widths). nodeTexts(id).nodeTextSize(3). enableParallel().parArcDist(1). drawArrows().arrowWidth(1).arrowLength(1). run(); + // Create an .eps file showing the colors of a default Palette ListDigraph h; ListDigraph::NodeMap hcolors(h); ListDigraph::NodeMap hcoords(h); @@ -188,21 +186,22 @@ int cols=int(sqrt(double(palette.size()))); for(int i=0;i=0) colors.resize(num); } ///\e @@ -171,13 +170,13 @@ { colors[i%colors.size()]=c; } - ///Add a new color to the end of the color list. + ///Adds a new color to the end of the color list. void add(const Color &c) { colors.push_back(c); } - ///Sets the number of the exiting colors. + ///Sets the number of the existing colors. void resize(int s) { colors.resize(s);} ///Returns the number of the existing colors. int size() const { return int(colors.size());} diff --git a/lemon/graph_to_eps.h b/lemon/graph_to_eps.h --- a/lemon/graph_to_eps.h +++ b/lemon/graph_to_eps.h @@ -63,7 +63,7 @@ ///Default traits class of \ref GraphToEps -///Default traits class of \ref GraphToEps +///Default traits class of \ref GraphToEps. /// ///\c G is the type of the underlying graph. template @@ -140,12 +140,11 @@ ///Constructor ///Constructor - ///\param _g is a reference to the graph to be printed - ///\param _os is a reference to the output stream. - ///\param _os is a reference to the output stream. + ///\param _g Reference to the graph to be printed. + ///\param _os Reference to the output stream. + ///\param _os Reference to the output stream. By default it is std::cout. ///\param _pros If it is \c true, then the \c ostream referenced by \c _os ///will be explicitly deallocated by the destructor. - ///By default it is std::cout DefaultGraphToEpsTraits(const G &_g,std::ostream& _os=std::cout, bool _pros=false) : g(_g), os(_os), @@ -173,7 +172,9 @@ ///Auxiliary class to implement the named parameters of \ref graphToEps() -///Auxiliary class to implement the named parameters of \ref graphToEps() +///Auxiliary class to implement the named parameters of \ref graphToEps(). +/// +///For detailed examples see the \ref graph_to_eps_demo.cc demo file. template class GraphToEps : public T { // Can't believe it is required by the C++ standard @@ -258,7 +259,7 @@ public: ///Node shapes - ///Node shapes + ///Node shapes. /// enum NodeShapes { /// = 0 @@ -335,7 +336,7 @@ ///Sets the map of the node coordinates ///Sets the map of the node coordinates. - ///\param x must be a node map with dim2::Point or + ///\param x must be a node map with \ref dim2::Point "dim2::Point" or ///\ref dim2::Point "dim2::Point" values. template GraphToEps > coords(const X &x) { dontPrint=true; @@ -347,7 +348,7 @@ }; ///Sets the map of the node sizes - ///Sets the map of the node sizes + ///Sets the map of the node sizes. ///\param x must be a node map with \c double (or convertible) values. template GraphToEps > nodeSizes(const X &x) { @@ -376,9 +377,9 @@ }; ///Sets the text printed on the nodes - ///Sets the text printed on the nodes + ///Sets the text printed on the nodes. ///\param x must be a node map with type that can be pushed to a standard - ///ostream. + ///\c ostream. template GraphToEps > nodeTexts(const X &x) { dontPrint=true; @@ -393,14 +394,14 @@ ///With this command it is possible to insert a verbatim PostScript ///block to the nodes. - ///The PS current point will be moved to the centre of the node before + ///The PS current point will be moved to the center of the node before ///the PostScript block inserted. /// ///Before and after the block a newline character is inserted so you ///don't have to bother with the separators. /// ///\param x must be a node map with type that can be pushed to a standard - ///ostream. + ///\c ostream. /// ///\sa nodePsTextsPreamble() template GraphToEps > nodePsTexts(const X &x) @@ -415,7 +416,7 @@ }; ///Sets the map of the arc widths - ///Sets the map of the arc widths + ///Sets the map of the arc widths. ///\param x must be an arc map with \c double (or convertible) values. template GraphToEps > arcWidths(const X &x) { @@ -429,7 +430,7 @@ }; ///Sets the map of the node colors - ///Sets the map of the node colors + ///Sets the map of the node colors. ///\param x must be a node map with \ref Color values. /// ///\sa Palette @@ -445,7 +446,7 @@ }; ///Sets the map of the node text colors - ///Sets the map of the node text colors + ///Sets the map of the node text colors. ///\param x must be a node map with \ref Color values. /// ///\sa Palette @@ -463,7 +464,7 @@ }; ///Sets the map of the arc colors - ///Sets the map of the arc colors + ///Sets the map of the arc colors. ///\param x must be an arc map with \ref Color values. /// ///\sa Palette @@ -487,9 +488,9 @@ /// \sa nodeSizes() /// \sa autoNodeScale() GraphToEps &nodeScale(double d=.01) {_nodeScale=d;return *this;} - ///Turns on/off the automatic node width scaling. + ///Turns on/off the automatic node size scaling. - ///Turns on/off the automatic node width scaling. + ///Turns on/off the automatic node size scaling. /// ///\sa nodeScale() /// @@ -497,9 +498,9 @@ _autoNodeScale=b;return *this; } - ///Turns on/off the absolutematic node width scaling. + ///Turns on/off the absolutematic node size scaling. - ///Turns on/off the absolutematic node width scaling. + ///Turns on/off the absolutematic node size scaling. /// ///\sa nodeScale() /// @@ -508,9 +509,6 @@ } ///Negates the Y coordinates. - - ///Negates the Y coordinates. - /// GraphToEps &negateY(bool b=true) { _negY=b;return *this; } @@ -557,86 +555,47 @@ _absoluteArcWidths=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 - - ///Sets the width of the border around the picture - /// GraphToEps &border(double b=10) {_xBorder=_yBorder=b;return *this;} ///Sets the width of the border around the picture - - ///Sets the width of the border around the picture - /// GraphToEps &border(double x, double y) { _xBorder=x;_yBorder=y;return *this; } ///Sets whether to draw arrows - - ///Sets whether to draw arrows - /// GraphToEps &drawArrows(bool b=true) {_drawArrows=b;return *this;} ///Sets the length of the arrowheads - - ///Sets the length of the arrowheads - /// GraphToEps &arrowLength(double d=1.0) {_arrowLength*=d;return *this;} ///Sets the width of the arrowheads - - ///Sets the width of the arrowheads - /// GraphToEps &arrowWidth(double d=.3) {_arrowWidth*=d;return *this;} ///Scales the drawing to fit to A4 page - - ///Scales the drawing to fit to A4 page - /// GraphToEps &scaleToA4() {_scaleToA4=true;return *this;} ///Enables parallel arcs - - ///Enables parallel arcs GraphToEps &enableParallel(bool b=true) {_enableParallel=b;return *this;} - ///Sets the distance - - ///Sets the distance - /// + ///Sets the distance between parallel arcs GraphToEps &parArcDist(double d) {_parArcDist*=d;return *this;} ///Hides the arcs - - ///Hides the arcs - /// GraphToEps &hideArcs(bool b=true) {_showArcs=!b;return *this;} ///Hides the nodes - - ///Hides the nodes - /// GraphToEps &hideNodes(bool b=true) {_showNodes=!b;return *this;} ///Sets the size of the node texts - - ///Sets the size of the node texts - /// GraphToEps &nodeTextSize(double d) {_nodeTextSize=d;return *this;} ///Sets the color of the node texts to be different from the node color ///Sets the color of the node texts to be as different from the node color - ///as it is possible - /// + ///as it is possible. GraphToEps &distantColorNodeTexts() {_nodeTextColorType=DIST_COL;return *this;} ///Sets the color of the node texts to be black or white and always visible. ///Sets the color of the node texts to be black or white according to - ///which is more - ///different from the node color - /// + ///which is more different from the node color. GraphToEps &distantBWNodeTexts() {_nodeTextColorType=DIST_BW;return *this;} @@ -648,18 +607,18 @@ GraphToEps & nodePsTextsPreamble(const char *str) { _nodePsTextsPreamble=str ;return *this; } - ///Sets whether the the graph is undirected + ///Sets whether the graph is undirected - ///Sets whether the the graph is undirected. + ///Sets whether the graph is undirected. /// ///This setting is the default for undirected graphs. /// ///\sa directed() GraphToEps &undirected(bool b=true) {_undirected=b;return *this;} - ///Sets whether the the graph is directed + ///Sets whether the graph is directed - ///Sets whether the the graph is directed. + ///Sets whether the graph is directed. ///Use it to show the edges as a pair of directed ones. /// ///This setting is the default for digraphs. @@ -716,7 +675,6 @@ 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'; -// << "%%Copyright: XXXX\n" os << "%%Creator: LEMON, graphToEps()\n"; { @@ -748,7 +706,7 @@ double max_w=0; for(ArcIt e(g);e!=INVALID;++e) max_w=std::max(double(_arcWidths[e]),max_w); - ///\todo better 'epsilon' would be nice here. + //\todo better 'epsilon' would be nice here. if(max_w>EPSILON) { _arcWidthScale/=max_w; } @@ -758,7 +716,7 @@ 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. + //\todo better 'epsilon' would be nice here. if(max_s>EPSILON) { _nodeScale/=max_s; } @@ -1114,18 +1072,12 @@ ///@{ ///An alias for arcWidths() - - ///An alias for arcWidths() - /// template GraphToEps > edgeWidths(const X &x) { return arcWidths(x); } ///An alias for arcColors() - - ///An alias for arcColors() - /// template GraphToEps > edgeColors(const X &x) { @@ -1133,39 +1085,24 @@ } ///An alias for arcWidthScale() - - ///An alias for arcWidthScale() - /// GraphToEps &edgeWidthScale(double d) {return arcWidthScale(d);} ///An alias for autoArcWidthScale() - - ///An alias for autoArcWidthScale() - /// GraphToEps &autoEdgeWidthScale(bool b=true) { return autoArcWidthScale(b); } ///An alias for absoluteArcWidths() - - ///An alias for absoluteArcWidths() - /// GraphToEps &absoluteEdgeWidths(bool b=true) { return absoluteArcWidths(b); } ///An alias for parArcDist() - - ///An alias for parArcDist() - /// GraphToEps &parEdgeDist(double d) {return parArcDist(d);} ///An alias for hideArcs() - - ///An alias for hideArcs() - /// GraphToEps &hideEdges(bool b=true) {return hideArcs(b);} ///@} @@ -1185,9 +1122,9 @@ ///\ingroup eps_io ///Generates an EPS file from a graph. -///\param g is a reference to the graph to be printed -///\param os is a reference to the output stream. -///By default it is std::cout +///\param g Reference to the graph to be printed. +///\param os Reference to the output stream. +///By default it is std::cout. /// ///This function also has a lot of ///\ref named-templ-func-param "named parameters", @@ -1198,6 +1135,9 @@ /// .nodeScale(2).nodeSizes(sizes) /// .arcWidthScale(.4).run(); ///\endcode +/// +///For more detailed examples see the \ref graph_to_eps_demo.cc demo file. +/// ///\warning Don't forget to put the \ref GraphToEps::run() "run()" ///to the end of the parameter list. ///\sa GraphToEps