adopted to graphviz version 10.0.1 and MACOS Sonoma
[luagraph.git] / examples / clust1.lua
blobab89d5dab2a3c1190f0e615378788521496d9700
1 gr = require "graph"
3 --
4 -- For simple formatted printing
5 --
6 local function printf(fmt, ...)
7 print(string.format(fmt, ...))
8 end
11 -- Get a local reference for frequently used functions (optional)
13 local node, edge, subgraph, cluster, digraph, strictdigraph =
14 gr.node, gr.edge, gr.subgraph, gr.cluster, gr.digraph, gr.strictdigraph
17 -- Example graph
19 local g = digraph{"G",
20 cluster{"c0",
21 edge{"a0", "a1", "a2", "a3"}
23 cluster{"c1",
24 edge{"b0", "b1", "b2", "b3"}
26 edge{"x", "a0"},
27 edge{"x", "b0"},
28 edge{"a1", "a3"},
29 edge{"a3", "a0"}
33 -- Same graph in dot notation
35 local dotsource = [[
36 digraph G {
37 subgraph cluster_c0 {a0 -> a1 -> a2 -> a3;}
38 subgraph cluster_c1 {b0 -> b1 -> b2 -> b3;}
39 x -> a0;
40 x -> b0;
41 a1 -> a3;
42 a3 -> a0;
46 -- Print graph as dotfile
47 printf("1. Generated 'dot' format:")
48 g:write()
49 printf("2. Source in 'dot' format:\n %s\n", dotsource)
51 -- Show the graph
52 g:show()
54 -- Close the graph
55 g:close()