Module:CDP Tasks Mermaid
From atwg
Documentation for this module may be created at Module:CDP Tasks Mermaid/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.wrapArray( a, length )
s = ''
for k,v in pairs( a ) do
if #s > 0 then
s = s .. '<BR/>'
end
s = s .. p.wrap( v, length )
end
return s
end
function p.label( a )
return '"' .. p.wrapArray( a, 50 ) .. '"'
end
function p.buildDependencyGraph()
local tasks = mw.smw.getQueryResult( '[[Category:Tasks]][[Archived::!true]]|?Primary Team' ..
'|?Depends On Task' ..
'|?End Year' )
if tasks == nil then
return ''
end
local s = 'graph LR\n'
s = s .. 'classDef mermaid-task fill:#888888,stroke:black;\n'
s = s .. 'classDef mermaid-task-year1 fill:green,stroke:green;\n'
for k,v in pairs( tasks.results ) do
local task_name = string.gsub( v.fulltext, ':', '' )
local team = table.concat( v.printouts['Primary Team'], ', ' )
if ( #team > 0 ) then
team = '<BR/>(' .. team .. ')'
else
team = ''
end
s = s .. task_name .. '[' .. p.label( { v.displaytitle, team } ) .. ']\n'
if table.concat( v.printouts['End Year'] ) == '0' then
s = s .. 'class ' .. task_name .. ' mermaid-task-year1\n'
else
s = s .. 'class ' .. task_name .. ' mermaid-task\n'
end
s = s .. 'click ' .. task_name .. ' "' .. v.fullurl .. '"\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
return s
end
function p.showDependencyGraph(frame)
local s = p.buildDependencyGraph()
return frame:callParserFunction{ name = '#mermaid', args = { s } }
end
return p