1gv(3python) gv(3python)
2
3
4
6 gv_python - graph manipulation in python
7
8
10 #!/usr/bin/python
11 import sys
12 import gv
13
14
17 gv_python is a dynamically loaded extension for python that provides
18 access to the graph facilities of graphviz.
19
20
22 New graphs
23
24 New empty graph
25 graph_handle gv.graph (name);
26 graph_handle gv.digraph (name);
27 graph_handle gv.strictgraph (name);
28 graph_handle gv.strictdigraph (name);
29
30 New graph from a dot-syntax string or file
31 graph_handle gv.readstring (string);
32 graph_handle gv.read (string filename);
33 graph_handle gv.read (channel);
34
35 Add new subgraph to existing graph
36 graph_handle gv.graph (graph_handle, name);
37
38 New nodes
39
40 Add new node to existing graph
41 node_handle gv.node (graph_handle, name);
42
43 New edges
44
45 Add new edge between existing nodes
46 edge_handle gv.edge (tail_node_handle, head_node_handle);
47
48 Add a new edge between an existing tail node, and a named head node
49 which will be induced in the graph if it doesn't already exist
50 edge_handle gv.edge (tail_node_handle, head_name);
51
52 Add a new edge between an existing head node, and a named tail node
53 which will be induced in the graph if it doesn't already exist
54 edge_handle gv.edge (tail_name, head_node_handle);
55
56 Add a new edge between named tail and head nodes which will be induced
57 in the graph if they don't already exist
58 edge_handle gv.edge (graph_handle, tail_name, head_name);
59
60 Setting attribute values
61
62 Set value of named attribute of graph/node/edge - creating attribute if
63 necessary
64 string gv.setv (graph_handle, attr_name, attr_value);
65 string gv.setv (node_handle, attr_name, attr_value);
66 string gv.setv (edge_handle, attr_name, attr_value);
67
68 Set value of existing attribute of graph/node/edge (using attribute
69 handle)
70 string gv.setv (graph_handle, attr_handle, attr_value);
71 string gv.setv (node_handle, attr_handle, attr_value);
72 string gv.setv (edge_handle, attr_handle, attr_value);
73
74 Getting attribute values
75
76 Get value of named attribute of graph/node/edge
77 string gv.getv (graph_handle, attr_name);
78 string gv.getv (node_handle, attr_name);
79 string gv.getv (edge_handle, attr_name);
80
81 Get value of attribute of graph/node/edge (using attribute handle)
82 string gv.getv (graph_handle, attr_handle);
83 string gv.getv (node_handle, attr_handle);
84 string gv.getv (edge_handle, attr_handle);
85
86 Obtain names from handles
87 string gv.nameof (graph_handle);
88 string gv.nameof (node_handle);
89 string gv.nameof (attr_handle);
90
91 Find handles from names
92 graph_handle gv.findsubg (graph_handle, name);
93 node_handle gv.findnode (graph_handle, name);
94 edge_handle gv.findedge (tail_node_handle, head_node_handle);
95 attribute_handle gv.findattr (graph_handle, name);
96 attribute_handle gv.findattr (node_handle, name);
97 attribute_handle gv.findattr (edge_handle, name);
98
99 Misc graph navigators returning handles
100 node_handle gv.headof (edge_handle);
101 node_handle gv.tailof (edge_handle);
102 graph_handle gv.graphof (graph_handle);
103 graph_handle gv.graphof (edge_handle);
104 graph_handle gv.graphof (node_handle);
105 graph_handle gv.rootof (graph_handle);
106
107 Obtain handles of proto node/edge for setting default attribute values
108 node_handle gv.protonode (graph_handle);
109 edge_handle gv.protoedge (graph_handle);
110
111 Iterators
112
113 Iteration termination tests
114 bool gv.ok (graph_handle);
115 bool gv.ok (node_handle);
116 bool gv.ok (edge_handle);
117 bool gv.ok (attr_handle);
118
119 Iterate over subgraphs of a graph
120 graph_handle gv.firstsubg (graph_handle);
121 graph_handle gv.nextsubg (graph_handle, subgraph_handle);
122
123 Iterate over supergraphs of a graph (obscure and rarely useful)
124 graph_handle gv.firstsupg (graph_handle);
125 graph_handle gv.nextsupg (graph_handle, subgraph_handle);
126
127 Iterate over edges of a graph
128 edge_handle gv.firstedge (graph_handle);
129 edge_handle gv.nextedge (graph_handle, edge_handle);
130
131 Iterate over outedges of a graph
132 edge_handle gv.firstout (graph_handle);
133 edge_handle gv.nextout (graph_handle, edge_handle);
134
135 Iterate over edges of a node
136 edge_handle gv.firstedge (node_handle);
137 edge_handle gv.nextedge (node_handle, edge_handle);
138
139 Iterate over out-edges of a node
140 edge_handle gv.firstout (node_handle);
141 edge_handle gv.nextout (node_handle, edge_handle);
142
143 Iterate over head nodes reachable from out-edges of a node
144 node_handle gv.firsthead (node_handle);
145 node_handle gv.nexthead (node_handle, head_node_handle);
146
147 Iterate over in-edges of a graph
148 edge_handle gv.firstin (graph_handle);
149 edge_handle gv.nextin (node_handle, edge_handle);
150
151 Iterate over in-edges of a node
152 edge_handle gv.firstin (node_handle);
153 edge_handle gv.nextin (graph_handle, edge_handle);
154
155 Iterate over tail nodes reachable from in-edges of a node
156 node_handle gv.firsttail (node_handle);
157 node_handle gv.nexttail (node_handle, tail_node_handle);
158
159 Iterate over nodes of a graph
160 node_handle gv.firstnode (graph_handle);
161 node_handle gv.nextnode (graph_handle, node_handle);
162
163 Iterate over nodes of an edge
164 node_handle gv.firstnode (edge_handle);
165 node_handle gv.nextnode (edge_handle, node_handle);
166
167 Iterate over attributes of a graph
168 attribute_handle gv.firstattr (graph_handle);
169 attribute_handle gv.nextattr (graph_handle, attr_handle);
170
171 Iterate over attributes of an edge
172 attribute_handle gv.firstattr (edge_handle);
173 attribute_handle gv.nextattr (edge_handle, attr_handle);
174
175 Iterate over attributes of a node
176 attribute_handle gv.firstattr (node_handle);
177 attribute_handle gv.nextattr (node_handle, attr_handle);
178
179 Remove graph objects
180 bool gv.rm (graph_handle);
181 bool gv.rm (node_handle);
182 bool gv.rm (edge_handle);
183
184 Layout
185
186 Annotate a graph with layout attributes and values using a specific
187 layout engine
188 bool gv.layout (graph_handle, string engine);
189
190 Render
191
192 Render a layout into attributes of the graph
193 bool gv.render (graph_handle);
194
195 Render a layout to stdout
196 bool gv.render (graph_handle, string format);
197
198 Render to an open file
199 bool gv.render (graph_handle, string format, channel fout);
200
201 Render a layout to an unopened file by name
202 bool gv.render (graph_handle, string format, string filename);
203
204 Render to an open channel
205 bool gv.renderchannel (graph_handle, string format, string chan‐
206 nelname);
207
208 Render to a string result
209 gv.renderresult (graph_handle, string format, string outdata);
210
211 Render a layout to a malloc'ed string, to be free'd by the caller
212
213 (deprecated - too easy to leak memory)
214
215 (still needed for "eval [gv::renderdata $G tk]" )
216 string gv.renderdata (graph_handle, string format);
217
218 Writing graph back to file
219 bool gv.write (graph_handle, string filename);
220 bool gv.write (graph_handle, channel);
221
222
224 graph, dot, neato, fdp, circo, twopi, python.
225
226
227
228
229 14 February 2013 gv(3python)