2 * src/lemon/demo/graph_to_eps.cc -
3 * Part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
6 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 * Permission to use, modify and distribute this software is granted
9 * provided that this copyright notice appears in all copies. For
10 * precise terms see the accompanying LICENSE file.
12 * This software is provided "AS IS" with no warranty of any kind,
13 * express or implied, and with no claim as to its suitability for any
18 #include<lemon/graph_to_eps.h>
19 #include<lemon/maps.h>
20 #include<lemon/list_graph.h>
21 #include<lemon/graph_utils.h>
27 using namespace lemon;
34 typedef ListGraph::Node Node;
35 typedef ListGraph::NodeIt NodeIt;
36 typedef ListGraph::Edge Edge;
45 ListGraph::NodeMap<Xy> coords(g);
46 ListGraph::NodeMap<double> sizes(g);
47 ListGraph::NodeMap<int> colors(g);
48 ListGraph::NodeMap<int> shapes(g);
49 ListGraph::EdgeMap<int> ecolors(g);
50 ListGraph::EdgeMap<int> widths(g);
52 coords[n1]=Xy(50,50); sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
53 coords[n2]=Xy(50,70); sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
54 coords[n3]=Xy(70,70); sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
55 coords[n4]=Xy(70,50); sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
56 coords[n5]=Xy(85,60); sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
60 e=g.addEdge(n1,n2); ecolors[e]=0; widths[e]=1;
61 e=g.addEdge(n2,n3); ecolors[e]=0; widths[e]=1;
62 e=g.addEdge(n3,n5); ecolors[e]=0; widths[e]=3;
63 e=g.addEdge(n5,n4); ecolors[e]=0; widths[e]=1;
64 e=g.addEdge(n4,n1); ecolors[e]=0; widths[e]=1;
65 e=g.addEdge(n2,n4); ecolors[e]=1; widths[e]=2;
66 e=g.addEdge(n3,n4); ecolors[e]=2; widths[e]=1;
68 IdMap<ListGraph,Node> id(g);
70 graphToEps(g,"graph_to_eps_demo_out.eps").scale(10).coords(coords).
71 title("Sample .eps figure").
72 copyright("(C) 2005 LEMON Project").
73 nodeScale(2).nodeSizes(sizes).
75 nodeColors(composeMap(colorSet,colors)).
76 edgeColors(composeMap(colorSet,ecolors)).
77 edgeWidthScale(.4).edgeWidths(widths).
78 nodeTexts(id).nodeTextSize(3).
81 graphToEps(g,"graph_to_eps_demo_out_arr.eps").scale(10).
82 title("Sample .eps figure (with arrowheads)").
83 copyright("(C) 2005 LEMON Project").
84 nodeColors(composeMap(colorSet,colors)).
86 nodeScale(2).nodeSizes(sizes).
88 edgeColors(composeMap(colorSet,ecolors)).
89 edgeWidthScale(.4).edgeWidths(widths).
90 nodeTexts(id).nodeTextSize(3).
91 drawArrows().arrowWidth(1).arrowLength(1).
94 e=g.addEdge(n1,n4); ecolors[e]=2; widths[e]=1;
95 e=g.addEdge(n4,n1); ecolors[e]=1; widths[e]=2;
97 e=g.addEdge(n1,n2); ecolors[e]=1; widths[e]=1;
98 e=g.addEdge(n1,n2); ecolors[e]=2; widths[e]=1;
99 e=g.addEdge(n1,n2); ecolors[e]=3; widths[e]=1;
100 e=g.addEdge(n1,n2); ecolors[e]=4; widths[e]=1;
101 e=g.addEdge(n1,n2); ecolors[e]=5; widths[e]=1;
102 e=g.addEdge(n1,n2); ecolors[e]=6; widths[e]=1;
103 e=g.addEdge(n1,n2); ecolors[e]=7; widths[e]=1;
105 graphToEps(g,"graph_to_eps_demo_out_par.eps").scale(10).
106 title("Sample .eps figure (parallel edges)").
107 copyright("(C) 2005 LEMON Project").
110 nodeScale(2).nodeSizes(sizes).
111 nodeColors(composeMap(colorSet,colors)).
112 edgeColors(composeMap(colorSet,ecolors)).
113 edgeWidthScale(.4).edgeWidths(widths).
114 nodeTexts(id).nodeTextSize(3).
115 enableParallel().parEdgeDist(1.5).
118 graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").scale(10).
119 title("Sample .eps figure (parallel edges and arrowheads)").
120 copyright("(C) 2005 LEMON Project").
121 nodeScale(2).nodeSizes(sizes).
124 nodeColors(composeMap(colorSet,colors)).
125 edgeColors(composeMap(colorSet,ecolors)).
126 edgeWidthScale(.3).edgeWidths(widths).
127 nodeTexts(id).nodeTextSize(3).
128 enableParallel().parEdgeDist(1).
129 drawArrows().arrowWidth(1).arrowLength(1).
132 graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
133 title("Sample .eps figure (fits to A4)").
134 copyright("(C) 2005 LEMON Project").
135 nodeScale(2).nodeSizes(sizes).
138 nodeColors(composeMap(colorSet,colors)).
139 edgeColors(composeMap(colorSet,ecolors)).
140 edgeWidthScale(.3).edgeWidths(widths).
141 nodeTexts(id).nodeTextSize(3).
142 enableParallel().parEdgeDist(1).
143 drawArrows().arrowWidth(1).arrowLength(1).
147 ListGraph::NodeMap<int> hcolors(h);
148 ListGraph::NodeMap<Xy> hcoords(h);
150 int cols=int(sqrt(double(colorSet.size())));
151 for(int i=0;i<int(colorSet.size());i++) {
153 hcoords[n]=Xy(i%cols,i/cols);
157 graphToEps(h,"graph_to_eps_demo_out_colors.eps").scale(60).
158 title("Sample .eps figure (parallel edges and arrowheads)").
159 copyright("(C) 2005 LEMON Project").
162 distantColorNodeTexts().
163 // distantBWNodeTexts().
164 nodeTexts(hcolors).nodeTextSize(.6).
165 nodeColors(composeMap(colorSet,hcolors)).