Difference between revisions of "Module:Graph"
From cpt
No edit summary |
No edit summary |
||
(24 intermediate revisions by the same user not shown) | |||
Line 21: | Line 21: | ||
s = string.gsub( s, '%[', '' ) | s = string.gsub( s, '%[', '' ) | ||
s = string.gsub( s, '%]', '' ) | s = string.gsub( s, '%]', '' ) | ||
s = | s = mw.text.decode( s, true ) | ||
s = p.wrap ( s, | s = p.wrap ( s, 30 ) | ||
return s .. extra | return s .. extra | ||
end | end | ||
Line 29: | Line 29: | ||
local nodes = {} | local nodes = {} | ||
local result1 = mw.smw.getQueryResult( '[[Category:Phabricator Tasks]]' .. | local result1 = mw.smw.getQueryResult( '[[Category:Phabricator Tasks]]' .. | ||
filter .. '|?Subtask|?Status|? | filter .. '|?Subtask|?Status|?Assignee|?CPT Column' .. | ||
'|limit=500' ) | '|limit=500' ) | ||
if result1 ~= nil then | if result1 ~= nil then | ||
Line 42: | Line 42: | ||
nodes[v1.fulltext].story = false | nodes[v1.fulltext].story = false | ||
local extra = '' | local extra = '' | ||
local | local assignee = table.concat( v1.printouts['Assignee'], ', ' ) | ||
if ( # | if ( #assignee > 0 ) then | ||
extra = '<BR/>' .. | extra = '<BR/>' .. assignee | ||
end | end | ||
nodes[v1.fulltext].projects = {} | nodes[v1.fulltext].projects = {} | ||
local result2 = mw.smw.getQueryResult( | local result2 = mw.smw.getQueryResult( | ||
'[[-Has subobject::' .. v1.fulltext .. ']]' .. | '[[-Has subobject::' .. v1.fulltext .. ']]' .. | ||
'[[Project::+]]' .. | |||
'|?Project|?Column' .. '|limit=500' ) | '|?Project|?Column' .. '|limit=500' ) | ||
for k2,v2 in pairs ( result2.results ) do | for k2,v2 in pairs ( result2.results ) do | ||
if string.match( v2.printouts['Project'][1], '^ | if string.match( v2.printouts['Project'][1], '^Platform Engineering$' ) and | ||
string.match( v2.printouts['Column'][1], '^Initiatives$' ) then | |||
nodes[v1.fulltext].initiative = true | nodes[v1.fulltext].initiative = true | ||
elseif string.match( v2.printouts['Project'][1], '^Epic$' ) then | elseif string.match( v2.printouts['Project'][1], '^Epic$' ) then | ||
Line 58: | Line 60: | ||
nodes[v1.fulltext].story = true | nodes[v1.fulltext].story = true | ||
end | end | ||
if string.match( v2.printouts['Project'][1], '^ | if string.match( v2.printouts['Project'][1], '^Platform Team Workboards' ) then | ||
extra = extra .. '<BR/>' .. v2.printouts['Project'][1] .. ' (' .. | extra = extra .. '<BR/>' .. v2.printouts['Project'][1] .. ' (' .. | ||
v2.printouts['Column'][1] .. ')' | v2.printouts['Column'][1] .. ')' | ||
Line 120: | Line 122: | ||
elseif v1.story then | elseif v1.story then | ||
s = s .. 'class ' .. name .. ' mermaid-story\n' | s = s .. 'class ' .. name .. ' mermaid-story\n' | ||
elseif v1.column == 'Doing' or v1.column == 'Contractor - Doing' then | elseif v1.column == 'Doing' or v1.column == 'Contractor - Doing' or | ||
v1.column == 'Discussing' then | |||
s = s .. 'class ' .. name .. ' mermaid-in-progress\n' | s = s .. 'class ' .. name .. ' mermaid-in-progress\n' | ||
elseif v1.column == 'Ready' or v1.column == 'Contractor - Ready' then | elseif v1.column == 'Ready' or v1.column == 'Contractor - Ready' then | ||
Line 126: | Line 129: | ||
elseif v1.column == 'Watching / External' then | elseif v1.column == 'Watching / External' then | ||
s = s .. 'class ' .. name .. ' mermaid-watching\n' | s = s .. 'class ' .. name .. ' mermaid-watching\n' | ||
elseif v1.column == 'Blocked Externally' then | elseif v1.column == 'Blocked' or v1.column == 'Blocked Externally' then | ||
s = s .. 'class ' .. name .. ' mermaid-blocked\n' | s = s .. 'class ' .. name .. ' mermaid-blocked\n' | ||
elseif v1.column == 'Waiting for Review' then | elseif v1.column == 'Waiting for Review' then | ||
Line 149: | Line 152: | ||
local filter = frame.args[1] or '' | local filter = frame.args[1] or '' | ||
local s = p.drawGraph( filter, true ) | local s = p.drawGraph( filter, true ) | ||
return '<div style="width:100%;text-align:center;font-size:20pt;font-weight:bold;">' .. | return '<div class="mermaid-graph" style="width:100%;text-align:center;font-size:20pt;font-weight:bold;">' .. | ||
frame:callParserFunction{ name = '#mermaid', args = { s } } .. '</div>' | frame:callParserFunction{ name = '#mermaid', args = { s, 'config.flowchart.curve=basis', 'config.flowchart.useMaxWidth = false' } } .. '</div>' | ||
end | end | ||
Line 156: | Line 159: | ||
local filter = frame.args[1] or '' | local filter = frame.args[1] or '' | ||
local s = p.drawGraph( filter, false ) | local s = p.drawGraph( filter, false ) | ||
return '<div style="width:100%;text-align:center;font-size:20pt;font-weight:bold;">' .. | return '<div class="mermaid-graph" style="width:100%;text-align:center;font-size:20pt;font-weight:bold;">' .. | ||
frame:callParserFunction{ name = '#mermaid', args = { s } } .. '</div>' | frame:callParserFunction{ name = '#mermaid', args = { s, 'config.flowchart.curve=basis', 'config.flowchart.useMaxWidth=false' } } .. '</div>' | ||
end | end | ||
return p | return p |
Latest revision as of 21:39, 29 July 2020
Documentation for this module may be created at Module:Graph/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.cleanseDisplayTitle( displaytitle, extra )
local s = displaytitle
s = string.gsub( s, '"', '' )
s = string.gsub( s, '%[', '' )
s = string.gsub( s, '%]', '' )
s = mw.text.decode( s, true )
s = p.wrap ( s, 30 )
return s .. extra
end
function p.getNodes( filter, unlimited )
local nodes = {}
local result1 = mw.smw.getQueryResult( '[[Category:Phabricator Tasks]]' ..
filter .. '|?Subtask|?Status|?Assignee|?CPT Column' ..
'|limit=500' )
if result1 ~= nil then
for k1,v1 in pairs( result1.results ) do
local status = v1.printouts['Status'][1]
if ( ( unlimited or
( ( status == 'open' or status == 'stalled' ) ) ) and
( not ( status == 'declined' or status == 'invalid' ) ) ) then
nodes[v1.fulltext] = {}
nodes[v1.fulltext].initiative = false
nodes[v1.fulltext].epic = false
nodes[v1.fulltext].story = false
local extra = ''
local assignee = table.concat( v1.printouts['Assignee'], ', ' )
if ( #assignee > 0 ) then
extra = '<BR/>' .. assignee
end
nodes[v1.fulltext].projects = {}
local result2 = mw.smw.getQueryResult(
'[[-Has subobject::' .. v1.fulltext .. ']]' ..
'[[Project::+]]' ..
'|?Project|?Column' .. '|limit=500' )
for k2,v2 in pairs ( result2.results ) do
if string.match( v2.printouts['Project'][1], '^Platform Engineering$' ) and
string.match( v2.printouts['Column'][1], '^Initiatives$' ) then
nodes[v1.fulltext].initiative = true
elseif string.match( v2.printouts['Project'][1], '^Epic$' ) then
nodes[v1.fulltext].epic = true
elseif string.match( v2.printouts['Project'][1], '^Story$' ) then
nodes[v1.fulltext].story = true
end
if string.match( v2.printouts['Project'][1], '^Platform Team Workboards' ) then
extra = extra .. '<BR/>' .. v2.printouts['Project'][1] .. ' (' ..
v2.printouts['Column'][1] .. ')'
nodes[v1.fulltext].column = v2.printouts['Column'][1]
end
nodes[v1.fulltext].projects[v2.printouts['Project'][1]] = true
end
nodes[v1.fulltext].fullurl = v1.fullurl
nodes[v1.fulltext].displaytitle =
p.cleanseDisplayTitle( v1.displaytitle, extra )
nodes[v1.fulltext].status = status
nodes[v1.fulltext].dependencies = {}
for k2,v2 in pairs ( v1.printouts['Subtask'] ) do
nodes[v1.fulltext].dependencies[v2.fulltext] = true
end
end
end
end
return nodes
end
function p.getPageName( title )
local location = string.find( title, ':' )
if location then
return string.sub( title, string.find( title, ':' ) + 1 )
else
return title
end
end
function p.contains( t, value )
for k,v in pairs ( t ) do
if v == value then
return true
end
end
return false
end
function p.drawGraph( filter, unlimited )
local nodes = p.getNodes( filter, unlimited )
local s = 'graph LR\n'
for k1,v1 in pairs( nodes ) do
local name = p.getPageName( k1 )
if v1.initiative or v1.epic or v1.story then
s = s .. name .. '("' .. v1.displaytitle .. '")\n';
else
s = s .. name .. '["' .. v1.displaytitle .. '"]\n';
end
s = s .. 'click ' .. name .. ' "' .. v1.fullurl .. '"\n'
if v1.projects['Deployment'] then
s = s .. 'class ' .. name .. ' mermaid-deployment\n'
end
if v1.status ~= 'open' and v1.status ~= 'stalled' then
s = s .. 'class ' .. name .. ' mermaid-done\n'
elseif v1.initiative then
s = s .. 'class ' .. name .. ' mermaid-initiative\n'
elseif v1.epic then
s = s .. 'class ' .. name .. ' mermaid-epic\n'
elseif v1.story then
s = s .. 'class ' .. name .. ' mermaid-story\n'
elseif v1.column == 'Doing' or v1.column == 'Contractor - Doing' or
v1.column == 'Discussing' then
s = s .. 'class ' .. name .. ' mermaid-in-progress\n'
elseif v1.column == 'Ready' or v1.column == 'Contractor - Ready' then
s = s .. 'class ' .. name .. ' mermaid-ready\n'
elseif v1.column == 'Watching / External' then
s = s .. 'class ' .. name .. ' mermaid-watching\n'
elseif v1.column == 'Blocked' or v1.column == 'Blocked Externally' then
s = s .. 'class ' .. name .. ' mermaid-blocked\n'
elseif v1.column == 'Waiting for Review' then
s = s .. 'class ' .. name .. ' mermaid-needs-review\n'
elseif v1.column == 'Needs Testing' then
s = s .. 'class ' .. name .. ' mermaid-needs-testing\n'
else
s = s .. 'class ' .. name .. ' mermaid-other\n'
end
end
for k1,v1 in pairs( nodes ) do
for k2, v2 in pairs ( v1.dependencies ) do
if ( nodes[k2] ) then
s = s .. p.getPageName( k2 ) .. '==>' .. p.getPageName( k1 ) .. '\n'
end
end
end
return s
end
function p.pert_chart(frame)
local filter = frame.args[1] or ''
local s = p.drawGraph( filter, true )
return '<div class="mermaid-graph" style="width:100%;text-align:center;font-size:20pt;font-weight:bold;">' ..
frame:callParserFunction{ name = '#mermaid', args = { s, 'config.flowchart.curve=basis', 'config.flowchart.useMaxWidth = false' } } .. '</div>'
end
function p.pert_chart_limited(frame)
local filter = frame.args[1] or ''
local s = p.drawGraph( filter, false )
return '<div class="mermaid-graph" style="width:100%;text-align:center;font-size:20pt;font-weight:bold;">' ..
frame:callParserFunction{ name = '#mermaid', args = { s, 'config.flowchart.curve=basis', 'config.flowchart.useMaxWidth=false' } } .. '</div>'
end
return p