Module:CDP Tasks Mermaid: Difference between revisions
From atwg
No edit summary |
No edit summary |
||
(6 intermediate revisions by the same user not shown) | |||
Line 39: | Line 39: | ||
end | end | ||
local s = 'graph LR\n' | local s = 'graph LR\n' | ||
s = s .. 'classDef mermaid-task fill: | s = s .. 'classDef mermaid-task fill:#888888,stroke:black;\n' | ||
s = s .. 'classDef mermaid-task-year1 fill: | s = s .. 'classDef mermaid-task-year1 fill:green,stroke:green;\n' | ||
for k,v in pairs( tasks.results ) do | for k,v in pairs( tasks.results ) do | ||
local task_name = string.gsub( v.fulltext, ':', '' ) | local task_name = string.gsub( v.fulltext, ':', '' ) | ||
Line 61: | Line 61: | ||
for k2,v2 in pairs( v1.printouts['Depends On Task'] ) do | for k2,v2 in pairs( v1.printouts['Depends On Task'] ) do | ||
local source_task_name = string.gsub( v2.fulltext, ':', '' ) | local source_task_name = string.gsub( v2.fulltext, ':', '' ) | ||
s = s .. source_task_name .. '->' .. target_task_name .. '\n' | s = s .. source_task_name .. ' -->' .. target_task_name .. '\n' | ||
end | end | ||
end | end | ||
Line 69: | Line 69: | ||
function p.showDependencyGraph(frame) | function p.showDependencyGraph(frame) | ||
local s = p.buildDependencyGraph() | local s = p.buildDependencyGraph() | ||
return frame:callParserFunction{ name = '# | return '<div style="font-size:16px;font-weight:normal;">' .. frame:callParserFunction{ name = '#mermaid', args = { s } } .. '</div>' | ||
end | end | ||
return p | return p |
Latest revision as of 14:55, 21 February 2018
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 '<div style="font-size:16px;font-weight:normal;">' .. frame:callParserFunction{ name = '#mermaid', args = { s } } .. '</div>'
end
return p