added example for red-black tree presented as Lua table (from lua-rbtree.git)
[luagraph.git] / examples / famtree.lua
blob92b0f5be3711c495a9f6940b6fd0869186e21a1d
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, graph =
14 gr.node, gr.edge, gr.subgraph, gr.cluster, gr.digraph, gr.strictdigraph, gr.graph
17 -- The definition of a graph
19 local g = graph{"G",
20 compound = "1",
21 -- rankdir = "BT",
22 size="6.5,6.5",
23 comment = "LuaGraph: exam2.lua",
24 cluster{
25 "mueller",
26 edge{
27 node{"peter"},
28 node{"maria"},
29 label = "in love"
31 node{"toni"},
32 node{"jupp"},
33 edge{"toni", "jupp", label="brothers"},
34 edge{"peter", "toni", label="father"},
35 edge{"peter", "jupp", label="father"},
36 edge{"maria", "toni", label="mother"},
37 edge{"maria", "jupp", label="mother"}
39 cluster{
40 "meier",
41 edge{
42 node{"johann"},
43 node{"eva"},
44 label = "in love"
47 node{"berlin", fillcolor="blue"},
48 edge{
49 "peter", "berlin",
50 ltail = "cluster_mueller",
51 label = "lives in"
53 edge{
54 "berlin", "johann",
55 lhead = "cluster_meier",
56 label = "lives in"
58 edge{
59 "peter", "eva", label="daughter"
61 edge{
62 "maria", "eva", label="daughter"
67 -- Show the graph
69 if true then
70 g:show()
71 end
74 -- Render the graph into postscript format
76 print("Render ...")
77 g:layout("dot")
78 g:render("ps", "out.ps")
79 g:render("gif", "out.gif")
80 g:render("svg", "out.svg")
81 g:render("png", "out.png")
82 g:freelayout()
84 -- Close the graph
86 print("Close ...")
87 g:close()