summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2016-04-27 15:49:13 +0100
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2016-05-12 11:59:09 +0100
commitc85e79b32f76c742bd7af407d9dfdcdb89d94548 (patch)
tree162c5812de10391db810523e96ea2be3a0de0407
parentde66784dba4f13001c202033bd5149f544fc006a (diff)
downloadefl-c85e79b32f76c742bd7af407d9dfdcdb89d94548.tar.gz
docgen: add support for inheritance graphs via graphviz
-rw-r--r--gendoc.lua69
1 files changed, 69 insertions, 0 deletions
diff --git a/gendoc.lua b/gendoc.lua
index c59b50de0b..43dc3da799 100644
--- a/gendoc.lua
+++ b/gendoc.lua
@@ -1240,6 +1240,72 @@ build_inherits = function(cl, t, lvl)
return t
end
+
+local class_to_color = function(cl)
+ local classt_to_color = {
+ [eolian.class_type.REGULAR] = { "black", "gray" },
+ [eolian.class_type.ABSTRACT] = { "black", "gray" },
+ [eolian.class_type.MIXIN] = { "blue", "skyblue" },
+ [eolian.class_type.INTERFACE] = { "cornflowerblue", "azure" }
+ }
+ return classt_to_color[cl:type_get()]
+end
+
+local class_to_node = function(cl, main)
+ local cn = cl:full_name_get()
+ local sn = cn:lower():gsub("%.", "_")
+ local attrs = { "label = \"" .. cn .. "\"" }
+ local clr = class_to_color(cl)
+ if main then
+ attrs[#attrs + 1] = "style = filled"
+ attrs[#attrs + 1] = "fillcolor = " .. clr[2]
+ end
+ attrs[#attrs + 1] = "color = " .. clr[1]
+
+ -- FIXME: need a dokuwiki graphviz plugin with proper URL support
+ -- the existing one only supports raw URLs (no dokuwikí namespaces)
+ --local url = ":" .. global_opts.root_nspace .. ":"
+ -- .. table.concat(gen_nsp_class(cl), ":")
+ --attrs[#attrs + 1] = "URL=\"" .. url .. "\""
+
+ return sn .. " [" .. table.concat(attrs, ", ") .. "]"
+end
+
+local build_igraph_r
+build_igraph_r = function(cl, nbuf, ibuf)
+ local sn = cl:full_name_get():lower():gsub("%.", "_")
+ for cln in cl:inherits_get() do
+ local acl = eolian.class_get_by_name(cln)
+ if not acl then
+ error("error retrieving inherited class " .. cln)
+ end
+ nbuf[#nbuf + 1] = class_to_node(acl)
+ ibuf[#ibuf + 1] = sn .. " -> " .. cln:lower():gsub("%.", "_")
+ build_igraph_r(acl, nbuf, ibuf)
+ end
+end
+
+local build_igraph = function(cl)
+ local buf = { "<graphviz>\n" }
+ buf[#buf + 1] = "digraph hierarchy {\n"
+ buf[#buf + 1] = "rankdir = TB\n"
+ buf[#buf + 1] = "size = \"6\"\n"
+ buf[#buf + 1] = "node [shape = box]\n\n"
+
+ local nbuf = {}
+ local ibuf = {}
+ nbuf[#nbuf + 1] = class_to_node(cl, true)
+ build_igraph_r(cl, nbuf, ibuf)
+
+ buf[#buf + 1] = table.concat(nbuf, "\n")
+ buf[#buf + 1] = "\n\n"
+
+ buf[#buf + 1] = table.concat(ibuf, "\n")
+ buf[#buf + 1] = "\n}\n</graphviz>"
+
+ return table.concat(buf)
+end
+
local build_class = function(cl)
local f = Writer(gen_nsp_class(cl))
check_class(cl)
@@ -1248,6 +1314,9 @@ local build_class = function(cl)
f:write_h("Inheritance hierarchy", 3)
f:write_list(build_inherits(cl))
+ f:write_nl()
+ f:write_raw(build_igraph(cl))
+ f:write_nl(2)
f:write_h("Description", 3)
write_full_doc(f, cl:documentation_get())