Module:CDP Tasks: Difference between revisions
From atwg
(Created page with "local p = {} function p.wrap( s, length ) s = mw.text.trim( s ) local oldindex = 1 local index = string.find( s, ' ' ) while ( index ) do if ( index - oldindex >= lengt...") |
No edit summary |
||
Line 27: | Line 27: | ||
local s = 'digraph tasks' | local s = 'digraph tasks' | ||
s = s .. ' {\n' | s = s .. ' {\n' | ||
s = s .. 'rankdir=LR;\n' | |||
s = s .. 'node [shape=box, fontsize=10, fontname="Arial bold"];\n' | s = s .. 'node [shape=box, fontsize=10, fontname="Arial bold"];\n' | ||
s = s .. 'edge [color=gray75];\n' | s = s .. 'edge [color=gray75];\n' |
Revision as of 15:45, 11 February 2018
Documentation for this module may be created at Module:CDP Tasks/doc
local p = {}
function p.wrap( s, length )
s = mw.text.trim( s )
local oldindex = 1
local index = string.find( s, ' ' )
while ( index ) do
if ( index - oldindex >= length ) then
local temp = string.sub( s, 1, index - 1 ) .. '<BR/>' .. string.sub( s, index + 1 )
s = temp
oldindex = index + 4
end
index = string.find( s, ' ', index + 1)
end
return s
end
function p.label( s )
return '<<TABLE BORDER="0"><TR><TD>' .. p.wrap( s, 30 ) .. '</TD></TR></TABLE>>'
end
function p.buildDependencyGraph()
local tasks = mw.smw.getQueryResult( '[[Category:Tasks]]|?Depends On Task' )
if tasks == nil then
return ''
end
local s = 'digraph tasks'
s = s .. ' {\n'
s = s .. 'rankdir=LR;\n'
s = s .. 'node [shape=box, fontsize=10, fontname="Arial bold"];\n'
s = s .. 'edge [color=gray75];\n'
for k,v in pairs( tasks.results ) do
local task_name = string.gsub( v.fulltext, ':', '' )
s = s .. task_name .. ' [URL="[[' .. v.fulltext .. ']]", label='
s = s .. p.label( v.displaytitle )
s = s .. '];\n'
end
for k1,v1 in pairs( tasks.results ) do
local source_task_name = string.gsub( v1.fulltext, ':', '' )
for k2,v2 in pairs( v1.printouts['Depends On Task'] ) do
local target_task_name = string.gsub( v2.fulltext, ':', '' )
s = s .. source_task_name .. '->' .. target_task_name .. '\n'
end
end
s = s .. '}\n'
return s
end
function p.showDependencyGraph(frame)
local s = p.buildDependencyGraph()
return frame:callParserFunction{ name = '#tag', args = { 'graphviz', format='png', s } }
end
return p