Module:CDP Tasks
From atwg
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' ..
'|?Start Year' )
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 )
if table.concat( v.printouts['Start Year'] ) == '0' then
s = s .. ', color=darkgreen, fontcolor=darkgreen'
end
s = s .. '];\n'
end
for k1,v1 in pairs( tasks.results ) do
local target_task_name = string.gsub( v1.fulltext, ':', '' )
for k2,v2 in pairs( v1.printouts['Depends On Task'] ) do
local source_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