Module:Chart: Difference between revisions

Content deleted Content added
Bugfix for extremely lopsided charts
Copyedit. Add number got to error message.
 
(6 intermediate revisions by 3 users not shown)
Line 48:
table.insert( tab,
mw.text.tag( 'ul',
{style="width:100%;list-style:none;column-width:12em;"},
table.concat( list, '\n' )
)
Line 112:
 
local function createImageMap()
addRes( '{{#tag:imagemap|', 'ImageFile:Circle frame.svg{{!}}' .. ( radius * 2 ) .. 'px' )
addRes( unpack( imslices ) )
addRes( 'desc none', '}}' )
Line 232:
if #values[gi] ~= numValues then error( keywords.group .. " " .. gi .. " does not have same number of values as " .. keywords.group .. " 1" ) end
end
if #xlegends ~= numValues then error( 'Illegal number of ' .. keywords.xlegend .. '. Should be exactly ' .. numValues .. ' not ' .. #xlegends) end
end
 
Line 314:
 
local function calcHeights( gi, i, val )
local barHeight = math.max( 2, math.floor( val / yscales[gi] * chartHeight + 0.5 ) ) -- add half to make it "round" instead of "trunc", min height to 2 to avoid negative bar sizes
local top, base = chartHeight - barHeight, 0
if stack then
localfor rawbasej = 01, gi - 1 do
if tonumber(values[j][i]) > 0 then
for j = 1, gi - 1 do rawbase = rawbase + values[j][i] end -- sum the "i" value of all the groups below our group, gi.
base = base + math.floormax( chartHeight2, *math.floor( rawbasevalues[j][i] / yscales[gi] * chartHeight + 0.5 ) ) -- normally,sum andthe especially"i" ifvalue it'sof "stack"all the groups below our group, allgi, and keep the yscalessame mustcalculation befor equal.each bar
end
end
end
if barHeight < 2 then
barHeight = 2 -- Otherwise the template would try to create a bar with a negative height
end
return barHeight, top - base
end
Line 406 ⟶ 405:
setOffset, setWidth = groupBounds( i )
-- setWidth = 0.85 * setWidth
table.insert( res, mw.text.tag( 'div', { style = string.format( legendDivStyleFormat, setOffset + 51, setWidth - 102, setWidth - 102 ) }, xlegends[i] or '' ) )
table.insert( res, mw.text.tag( 'div', { style = string.format( tickDivstyleFormat, setOffset + setWidth / 2 ) }, '' ) )
end
Line 413 ⟶ 412:
 
local function drawChart()
table.insert( res, mw.text.tag( 'div', { class = 'chart noresize', style = string.format( 'padding-top:10px;margin-top:1em;max-width:%spx;', width ) } ) )
table.insert( res, mw.text.tag( 'div', { style = string.format("position:relative;min-height:%spx;min-width:%spx;max-width:%spx;", height, width, width ) } ) )