File demoprograms.dox thrown away: demos module used instead.
2 * demo/graph_to_eps.cc - Part of LEMON, a generic C++ optimization library
4 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5 * (Egervary Research Group on Combinatorial Optimization, EGRES).
7 * Permission to use, modify and distribute this software is granted
8 * provided that this copyright notice appears in all copies. For
9 * precise terms see the accompanying LICENSE file.
11 * This software is provided "AS IS" with no warranty of any kind,
12 * express or implied, and with no claim as to its suitability for any
19 /// \brief Demo of the graph grawing function \ref graphToEps()
21 /// This demo program shows examples how to use the function \ref
22 /// graphToEps(). It takes no input but simply creates six
23 /// <tt>.eps</tt> files demonstrating how to draw directed/undirected
24 /// graphs, how to handle parallel egdes, how to change the properties
25 /// (like color, shape, size, title etc.) of nodes and edges
26 /// individually using appropriate \ref maps-page "graphmaps".
30 #include<lemon/graph_to_eps.h>
31 #include<lemon/list_graph.h>
34 using namespace lemon;
41 typedef ListGraph::Node Node;
42 typedef ListGraph::NodeIt NodeIt;
43 typedef ListGraph::Edge Edge;
52 ListGraph::NodeMap<Xy> coords(g);
53 ListGraph::NodeMap<double> sizes(g);
54 ListGraph::NodeMap<int> colors(g);
55 ListGraph::NodeMap<int> shapes(g);
56 ListGraph::EdgeMap<int> ecolors(g);
57 ListGraph::EdgeMap<int> widths(g);
59 coords[n1]=Xy(50,50); sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
60 coords[n2]=Xy(50,70); sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
61 coords[n3]=Xy(70,70); sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
62 coords[n4]=Xy(70,50); sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
63 coords[n5]=Xy(85,60); sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
67 e=g.addEdge(n1,n2); ecolors[e]=0; widths[e]=1;
68 e=g.addEdge(n2,n3); ecolors[e]=0; widths[e]=1;
69 e=g.addEdge(n3,n5); ecolors[e]=0; widths[e]=3;
70 e=g.addEdge(n5,n4); ecolors[e]=0; widths[e]=1;
71 e=g.addEdge(n4,n1); ecolors[e]=0; widths[e]=1;
72 e=g.addEdge(n2,n4); ecolors[e]=1; widths[e]=2;
73 e=g.addEdge(n3,n4); ecolors[e]=2; widths[e]=1;
75 IdMap<ListGraph,Node> id(g);
77 cout << "Create 'graph_to_eps_demo_out.eps'" << endl;
78 graphToEps(g,"graph_to_eps_demo_out.eps").scale(10).coords(coords).
79 title("Sample .eps figure").
80 copyright("(C) 2005 LEMON Project").
81 nodeScale(2).nodeSizes(sizes).
83 nodeColors(composeMap(colorSet,colors)).
84 edgeColors(composeMap(colorSet,ecolors)).
85 edgeWidthScale(.4).edgeWidths(widths).
86 nodeTexts(id).nodeTextSize(3).
90 cout << "Create 'graph_to_eps_demo_out_arr.eps'" << endl;
91 graphToEps(g,"graph_to_eps_demo_out_arr.eps").scale(10).
92 title("Sample .eps figure (with arrowheads)").
93 copyright("(C) 2005 LEMON Project").
94 nodeColors(composeMap(colorSet,colors)).
96 nodeScale(2).nodeSizes(sizes).
98 edgeColors(composeMap(colorSet,ecolors)).
99 edgeWidthScale(.4).edgeWidths(widths).
100 nodeTexts(id).nodeTextSize(3).
101 drawArrows().arrowWidth(1).arrowLength(1).
104 e=g.addEdge(n1,n4); ecolors[e]=2; widths[e]=1;
105 e=g.addEdge(n4,n1); ecolors[e]=1; widths[e]=2;
107 e=g.addEdge(n1,n2); ecolors[e]=1; widths[e]=1;
108 e=g.addEdge(n1,n2); ecolors[e]=2; widths[e]=1;
109 e=g.addEdge(n1,n2); ecolors[e]=3; widths[e]=1;
110 e=g.addEdge(n1,n2); ecolors[e]=4; widths[e]=1;
111 e=g.addEdge(n1,n2); ecolors[e]=5; widths[e]=1;
112 e=g.addEdge(n1,n2); ecolors[e]=6; widths[e]=1;
113 e=g.addEdge(n1,n2); ecolors[e]=7; widths[e]=1;
115 cout << "Create 'graph_to_eps_demo_out_par.eps'" << endl;
116 graphToEps(g,"graph_to_eps_demo_out_par.eps").scale(10).
117 title("Sample .eps figure (parallel edges)").
118 copyright("(C) 2005 LEMON Project").
121 nodeScale(2).nodeSizes(sizes).
122 nodeColors(composeMap(colorSet,colors)).
123 edgeColors(composeMap(colorSet,ecolors)).
124 edgeWidthScale(.4).edgeWidths(widths).
125 nodeTexts(id).nodeTextSize(3).
126 enableParallel().parEdgeDist(1.5).
129 cout << "Create 'graph_to_eps_demo_out_par_arr.eps'" << endl;
130 graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").scale(10).
131 title("Sample .eps figure (parallel edges and arrowheads)").
132 copyright("(C) 2005 LEMON Project").
133 nodeScale(2).nodeSizes(sizes).
136 nodeColors(composeMap(colorSet,colors)).
137 edgeColors(composeMap(colorSet,ecolors)).
138 edgeWidthScale(.3).edgeWidths(widths).
139 nodeTexts(id).nodeTextSize(3).
140 enableParallel().parEdgeDist(1).
141 drawArrows().arrowWidth(1).arrowLength(1).
144 cout << "Create 'graph_to_eps_demo_out_a4.eps'" << endl;
145 graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
146 title("Sample .eps figure (fits to A4)").
147 copyright("(C) 2005 LEMON Project").
148 nodeScale(2).nodeSizes(sizes).
151 nodeColors(composeMap(colorSet,colors)).
152 edgeColors(composeMap(colorSet,ecolors)).
153 edgeWidthScale(.3).edgeWidths(widths).
154 nodeTexts(id).nodeTextSize(3).
155 enableParallel().parEdgeDist(1).
156 drawArrows().arrowWidth(1).arrowLength(1).
160 ListGraph::NodeMap<int> hcolors(h);
161 ListGraph::NodeMap<Xy> hcoords(h);
163 int cols=int(sqrt(double(colorSet.size())));
164 for(int i=0;i<int(colorSet.size());i++) {
166 hcoords[n]=Xy(i%cols,i/cols);
170 cout << "Create 'graph_to_eps_demo_out_colors.eps'" << endl;
171 graphToEps(h,"graph_to_eps_demo_out_colors.eps").scale(60).
172 title("Sample .eps figure (ColorSet demo)").
173 copyright("(C) 2005 LEMON Project").
176 distantColorNodeTexts().
177 // distantBWNodeTexts().
178 nodeTexts(hcolors).nodeTextSize(.6).
179 nodeColors(composeMap(colorSet,hcolors)).