6 local function printf(fmt
, ...)
7 print(string.format(fmt
, ...))
13 local node
, edge
, subgraph
, cluster
, digraph
=
14 gr
.node
, gr
.edge
, gr
.subgraph
, gr
.cluster
, gr
.digraph
20 xn
= node
{"xn", color
="red"}
25 local g
= digraph
{"G",
27 node
= {shape
= "box", color
= "blue", style
= "filled", fillcolor
= "lightgrey"},
28 edge
= {color
= "red"},
29 graph
= {style
= "filled", label
= ""},
31 -- General graph properties
38 node
{"SomeNode", fillcolor
= "cyan"},
40 node
{"sn1", style
= "filled", fillcolor
= "green"},
43 label
= "hello world",
49 node
{"SomeOtherNode"},
52 node
{"n1", shape
= "box", color
= "black"},
53 node
{"n2", shape
= "circle"},
54 node
{"n3", shape
= "ellipse"},
59 edge
{"sn2", "n1", label
="sn1=>n1"},
60 edge
{"SomeNode", "SomeOtherNode", label
="this=>other", color
="magenta"},
61 edge
{"SomeNode", "SomeNode", label
="this=>this", color
="grey"},
62 edge
{"SomeOtherNode", "sn1", ltail
="cluster_SG2", lhead
="cluster_SG1", label
="compound"},
65 printf("GRAPH: %q", g
.name
)
67 -- Print subgraphs/clusters, nodes and edges
69 printf(" SUBGRAPH: %q", sg
.name
)
70 for n
in sg
:walknodes() do
71 printf(" NODE: %q, shape=%q, color=%q",
72 s(n
.name
), s(n
.shape
), s(n
.color
))
73 for e
in n
:walkedges() do
74 printf(" EDGE: %q, color=%q", s(e
.label
), s(e
.color
))
79 printf("NUMBER OF NODES: %d nodes", g
.nnodes
)
80 printf("NUMBER OF EDGES: %d edges", g
.nedges
)