-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrender_dep_graph
executable file
·84 lines (72 loc) · 1.54 KB
/
render_dep_graph
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/luajit
local deps = require("sphere.deps")
local graph = {}
for n, list in pairs(deps) do
for _, m in ipairs(list) do
table.insert(graph, {n, m})
end
end
table.sort(graph, function(a, b)
if a[1] == b[1] then
return a[2] < b[2]
end
return a[1] < b[1]
end)
local function delete_node(n)
local i = 1
while i <= #graph do
local g = graph[i]
if g[1] == n or g[2] == n then
table.remove(graph, i)
else
i = i + 1
end
end
end
delete_node("game")
delete_node("configModel")
local function get_rels()
local rels = {}
for _, g in ipairs(graph) do
local n, m = g[1], g[2]
rels[n] = rels[n] or {}
rels[m] = rels[m] or {}
rels[n]._out = true
rels[m]._in = true
end
return rels
end
for i = 1, 0 do
-- for i = 1, 10 do
local rels = get_rels()
for n, d in pairs(rels) do
if d._in and not d._out then
delete_node(n)
end
end
end
local rels = get_rels()
local function get_color(name)
local t = rels[name] or {}
if t._in and t._out then
return "#eeeeee"
elseif t._in then
return "#ffffb4"
elseif t._out then
return "#b3b3ff"
end
return "#ffffff"
end
local buf = {}
table.insert(buf, "digraph {")
table.insert(buf, "overlap=prism")
for _, g in ipairs(graph) do
local n, m = g[1], g[2]
table.insert(buf, ("%s -> %s"):format(n, m))
table.insert(buf, ("%s [style=filled, fillcolor=%q]"):format(n, get_color(n)))
table.insert(buf, ("%s [style=filled, fillcolor=%q]"):format(m, get_color(m)))
end
table.insert(buf, "}")
local p = assert(io.popen("sfdp -Tpng -o graph.png", "w"))
p:write(table.concat(buf, "\n"))
p:close()