update index.html documentation
[luagraph.git] / examples / renderall.lua
blob794b9e402404dc2eb14ca31c7bb20e99ddc72f8a
1 local gr = require "graph"
3 local doall = true
5 if #arg < 2 then
6 print("usage: lua renderall.lua FILE FORMAT")
7 print(" FORMAT: dot, neato, twopi, fdp, circo")
8 print(" FILE: Lua file defining and returning graph")
9 os.exit(-1)
10 end
12 local layoutfmt = arg[2] or "dot"
14 -- For simple formatted printing
16 local function printf(layoutfmt, ...)
17 print(string.format(layoutfmt, ...))
18 end
20 local function gshow(g)
21 local fn = os.tmpname() .. ".dot"
22 g:write(fn)
23 os.execute("dotty "..fn)
24 os.remove(fn)
25 end
27 -- Provide simple reference for frequently used functions (optional)
28 node, edge, subgraph, cluster, digraph, strictdigraph, ugraph =
29 gr.node, gr.edge, gr.subgraph, gr.cluster, gr.digraph, gr.strictdigraph, gr.graph
31 local f, err = assert(loadfile(arg[1]))
32 local g = f(layoutfmt)
34 printf("Generated '%s' format.", layoutfmt)
35 if string.find(layoutfmt, "nop") then
36 g:layout("neato")
37 end
38 g:write()
39 g:show()
40 os.execute("rm -rf outdir")
41 os.execute("mkdir -p outdir")
42 local notworking = {
43 Darwin = {
44 cairo = 1,lasi = 1, map = 1, quartz = 1
47 local sys = io.popen("uname"):read()
48 local fmtlist, err = gr.plugins("render")
49 print("available formats: ".. table.concat(fmtlist, " "))
50 print("system: "..sys)
51 for _, fmt in ipairs(fmtlist) do
52 local fname = "outdir/out."..fmt
53 if (not notworking[sys][fmt]) then
54 printf("Rendering on system %q with format %q into file %q", sys, fmt, fname)
55 local stat, rv, err = pcall(g.render, g, fmt, fname, "dot")
56 print(stat, rv, err)
57 if rv == nil then break end
58 end
59 end
60 g:close()