Module:Chart: Difference between revisions

Content deleted Content added
No edit summary
teach barchart to do tooltip value accumulation
Line 15:
xlegend = 'x legends',
tooltip = 'tooltip',
accumulateTooltip = 'tooltip value accumulation',
links = 'links',
defcolor = 'default color',
Line 189 ⟶ 190:
local groupNames, unitsSuffix, unitsPrefix, links = {}, {}, {}, {}
local width, height, stack, delimiter = 500, 350, false, ':'
local chartWidth, chartHeight, defcolor, scalePerGroup, accumulateTooltip
 
 
Line 258 ⟶ 259:
elseif k == keywords.scalePerGroup then scalePerGroup = true
elseif k == keywords.defcolor then defcolor = v
elseif k == keywords.accumulateTooltip then accumulateTooltip = true
else
for keyword, tab in pairs( {
Line 336 ⟶ 338:
end
 
function drawbar( gi, i, val, ttval )
local color, tooltip, custom = colors[gi] or defcolor or 'blue', tooltip( gi, i, ttval or val )
local left, barWidth = calcx( gi, i )
local barHeight, top = calcHeights( gi, i, val )
Line 403 ⟶ 405:
 
table.insert( res, mw.text.tag( 'div', { style = string.format("float:right;position:relative;min-height:%spx;min-width:%spx;max-width:%spx;border-left:1px black solid;border-bottom:1px black solid;", chartHeight, chartWidth, chartWidth ) } ) )
local acum = stack and accumulateTooltip and {}
for gi, group in pairs( values ) do
for i, val in ipairs( group ) do
drawbar(if gi,acum then acum[i,] val= ( acum[i] or 0 ) + val end
drawbar( gi, i, val, acum and acum[i] )
end
end