Module:Graph

From mcr
Revision as of 12:24, 24 December 2017 by Ccicalese (talk | contribs)

Documentation for this module may be created at Module:Graph/doc

--  Mollusca [URL="[[Phab:T107595|hello world]]"];
--  Mollusca->X1
local p = {}

function p.getNodes(category, property)
	local nodes = {};
	local result = mw.smw.getQueryResult( '[[Category:' .. category .. ']]|?' .. property )
    if result ~= nil then
		for k1,v1 in pairs( result.results ) do
			nodes[v1.fulltext] = {}
			nodes[v1.fulltext].displaytitle = v1.displaytitle
			nodes[v1.fulltext].dependencies = {} 
			for k2,v2 in pairs (v1.printouts[property]) do
				nodes[v1.fulltext].dependencies[v2.fulltext] = true
			end
		end
	end
   return nodes
end

function p.draw(frame)
	
	s = 'digraph dependency_graph {\n'
	s = s .. 'rankdir=LR;\n'
	s = s .. 'node [shape=plaintext,fontname="Arial"];\n'
	
	s = s .. 'A->B\n'
	s = s .. 'A->C\n'
	
	s = s .. '}\n'
	return frame:callParserFunction{ name = '#tag', args = { 'graphviz', format='png', s } }

end

return p