fixed graph._SYSTEM for Linux
[luagraph.git] / examples / exam2.lua
blobc2b371e80f072984844239ff16be41602a9fff7c
1 gr = require "graph"
3 --
4 -- Formatted printing
5 --
6 local function printf(fmt, ...)
7 print(string.format(fmt, ...))
8 end
11 -- Convenience
13 local node, edge, subgraph, cluster, digraph, strictdigraph =
14 gr.node, gr.edge, gr.subgraph, gr.cluster, gr.digraph, gr.strictdigraph
17 -- The definition of a graph
19 local g = strictdigraph{"G",
20 compound = "1",
21 rankdir = "LR",
22 size="6.5,6.5",
23 comment = "LuaGraph: exam2.lua",
24 cluster{"c1",
25 edge{
26 node{"n1", comment="123"},
27 node{"n2"},
28 label = "n1-n2"
31 cluster{"c2",
32 edge{
33 node{"m1"},
34 node{"m2"},
35 node{"m3"},
36 label = "m1-m2-m3"
38 edge{"m3", "m1"},
40 node{"o1"},
41 edge{"n1", "m2", ltail="cluster_c1", lhead="cluster_c2", label="comp"},
42 edge{"n1","o1", "m1", label="nom"}
47 -- Render the graph into postscript format
49 print("Render ...")
50 g:layout("dot")
51 g:render("ps", "out.ps")
52 g:render("gif", "out.gif")
53 g:render("svg", "out.svg")
54 g:render("png", "out.png")
55 g:freelayout()
57 -- Show the graph
60 g:show()
62 -- Close the graph
64 print("Close ...")
65 g:close()