added example for red-black tree presented as Lua table (from lua-rbtree.git)
[luagraph.git] / examples / render.lua
blob16d76fcadb3d5a8127e9d617787d87fcb123eb5d
1 local gr = require "graph"
3 if #arg < 2 then
4 print("usage: lua render.lua FILE FORMAT")
5 print(" FORMAT: dot, neato, twopi, fdp, circo")
6 os.exit(-1)
7 end
9 local fmt = arg[2] or "dot"
11 -- For simple formatted printing
13 local function printf(fmt, ...)
14 print(string.format(fmt, ...))
15 end
17 local function gshow(g)
18 local fn = os.tmpname() .. ".dot"
19 g:write(fn)
20 os.execute("dotty "..fn)
21 os.remove(fn)
22 end
24 -- Provide simple reference for frequently used functions (optional)
25 node, edge, subgraph, cluster, digraph, strictdigraph, ugraph =
26 gr.node, gr.edge, gr.subgraph, gr.cluster, gr.digraph, gr.strictdigraph, gr.graph
28 local f, err = assert(loadfile(arg[1]))
29 local g = f(fmt)
31 printf("Generated '%s' format:", fmt)
32 g:write()
33 g:show()
34 g:render("pdf", "out.pdf", fmt)
35 g:close()