From: Daniel Kolesa Date: Wed, 27 Apr 2016 14:49:13 +0000 (+0100) Subject: docgen: add support for inheritance graphs via graphviz X-Git-Tag: upstream/1.20.0~6364^2~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c85e79b32f76c742bd7af407d9dfdcdb89d94548;p=platform%2Fupstream%2Fefl.git docgen: add support for inheritance graphs via graphviz --- diff --git a/gendoc.lua b/gendoc.lua index c59b50d..43dc3da 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 = { "\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" + + 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())