« Module:Chart » : différence entre les versions

[version vérifiée][version vérifiée]
Contenu supprimé Contenu ajouté
Aucun résumé des modifications
Aucun résumé des modifications
 
Ligne 41 :
table.insert( tab, mw.text.tag( 'div' ) )
local list = {}
local spanStyle = "padding:0 1em;background-color:%s;box-shadowborder:2px -1px 4pxsolid 0 silver%s;margin-right:1em;-webkit-print-color-adjust:exact;"
for gi = 1, #legends do
local span = mw.text.tag( 'span', { style = string.format( spanStyle, cols[gi], cols[gi] ) }, ' ' ) .. ' '.. legends[gi]
table.insert( list, mw.text.tag( 'li', {}, span ) )
end
Ligne 142 :
end
 
local style = string.format( 'border:solid transparent;position:absolute;%s:%spx;%s:%spx;width:%spx;height:%spx', s1, radius, s2, radius, radius, radius )
if start <= ( q - 1 ) * 0.25 then
style = string.format( '%s;border:0;background-color:%s', style, color )
Ligne 148 :
style = string.format( '%s;border-width:%spx %spx %spx %spx;border-%s-color:%s', style, w1, w2, w3, w4, border, color )
end
addRes( mw.text.tag( 'div', { class = 'transborder', style = style }, '' ) )
end
 
Ligne 174 :
analyzeParams()
if #values == 0 then error( "no slices found - can't draw pie chart" ) end
addRes( mw.text.tag( 'div', { class = 'chart noresize', style = string.format( "'margin-top:0.5em;max-width:%spx";', radius * 2 ) } ) )
addRes( mw.text.tag( 'div', { style = string.format( 'position:relative;min-width:%spx;min-height:%spx;max-width:%spx;overflow:hidden;', radius * 2, radius * 2, radius * 2 ) } ) )
createSlices()
Ligne 192 :
local values, xlegends, colors, tooltips, yscales = {}, {}, {}, {} ,{}, {}, {}
local groupNames, unitsSuffix, unitsPrefix, links = {}, {}, {}, {}
local width, height, yticks, stack, delimiter = 500, 350, -1, false, args.delimiter or ':'
local chartWidth, chartHeight, defcolor, scalePerGroup, accumulateTooltip
 
Ligne 208 :
end
if #tab > 0 and #tab ~= numGroups then
error ( keywords[name] .. ' shouldmust contain the same number of items as the number of groups, but it contains ' .. #tab .. ' items and there are (' .. numGroups .. ') groups')
end
end
Ligne 233 :
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 exatlyexactly ' .. numValues ) end
end
 
Ligne 260 :
end
elseif k == keywords.stack then stack = true
elseif k == keywords.yticks then yticks = tonumber(v) or -1
elseif k == keywords.scalePerGroup then scalePerGroup = true
elseif k == keywords.defcolor then defcolor = v
Ligne 290 ⟶ 291 :
end
 
function calcHeightLimits() -- if limits were passed by user, use ithemthem, otherwise calculate. for "stack" there's only one limet.
if stack then
local sums = {}
Ligne 301 ⟶ 302 :
for i, group in ipairs( values ) do yscales[i] = math.max( unpack( group ) ) end
end
for i, scale in ipairs( yscales ) do yscales[i] = roundup( scale * 0.9999 ) end
if not scalePerGroup then for i = 1, #values do yscales[i] = math.max( unpack( yscales ) ) end end
end
Ligne 314 ⟶ 315 :
 
function calcHeights( gi, i, val )
local barHeight = math.floor( val / yscales[gi] * chartHeight + 0.5 ) -- add half to make it "round" inssteadinstead of "trunc"
local top, base = chartHeight - barHeight, 0
if stack then
Ligne 332 ⟶ 333 :
function calcx( gi, i )
local setOffset, setWidth = groupBounds( i )
if stack or numGroups == 1 then
local barWidth = math.min( 38, math.floor( 0.8 * setWidth ) )
return setOffset + (setWidth - barWidth) / 2, barWidth
Ligne 343 ⟶ 344 :
 
function drawbar( gi, i, val, ttval )
if val == '0' then return end -- do not show single line (borders....) if value is 0, or rather, '0'. see talkpage
 
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 )
local style = string.format("position:absolute;left:%spx;top:%spx;height:%spx;min-width:%spx;max-width:%spx;background-color:%s;box-shadow:2px -1px 4px 0 silver;overflow:hidden;",
-- borders so it shows up when printing
left, top, barHeight, barWidth, barWidth, color)
local style = string.format("position:absolute;left:%spx;top:%spx;height:%spx;min-width:%spx;max-width:%spx;background-color:%s;box-shadow:2px webkit-print-color-adjust:exact;border:1px 4pxsolid 0 silver%s;border-bottom:none;overflow:hidden;",
left, top, barHeight-1, barWidth-2, barWidth-2, color, color)
local link = links[gi] and links[gi][i] or ''
local img = not nulOrWhitespace( link ) and mw.ustring.format( '[[File:Transparent.png|1000px|link=%s|%s]]', link, custom and tooltip or '' ) or ''
localtable.insert( tag =res, mw.text.tag( 'div', { style = style, title = tooltip, }, img ):gsub( '&#nbsp;', '&nbsp;' ) -- gsub to correct mw.text.encode bug with unbreakable space
table.insert( res, tag )
end
 
 
function drawYScale()
function drawSingle( gi, color, width, yticks, single )
local yscale = yscales[gi]
local _, top, ordermag = roundup( yscale * 0.999 )
local numnotches = topyticks <>= 1.50 and topyticks * 4or
or (top <= 4 1.5 and top * 24
or top < 4 and top * or top2
or top)
local valStyleStr =
single and 'position:absolute;height=20px;text-align:right;vertical-align:middle;width:%spx;top:%spx;padding:0 2px'
Ligne 383 ⟶ 388 :
local color = colors[gi] or defcolor
table.insert( res, mw.text.tag( 'div', { style = string.format( colStyle, chartHeight, colWidth, left, color, color ) } ) )
drawSingle( gi, color, colWidth, yticks )
table.insert( res, '</div>' )
end
else
drawSingle( 1, 'black', scaleWidth, yticks, true )
end
end
Ligne 393 ⟶ 398 :
function drawXlegends()
local setOffset, setWidth
local legendDivStyleFormat = "position:absolute;left:%spx;top:10px;min-width:%spx;max-width:%spx;text-align:center;veriticalvertical-align:top;"
local tickDivstyleFormat = "position:absolute;left:%spx;height:10px;width:1px;border-left:1px solid black;"
for i = 1, numValues do
Ligne 399 ⟶ 404 :
setOffset, setWidth = groupBounds( i )
-- setWidth = 0.85 * setWidth
table.insert( res, mw.text.tag( 'div', { style = string.format( legendDivStyleFormat, setOffset -+ 5, setWidth - 10, setWidth - 10 ) }, xlegends[i] or '' ) )
table.insert( res, mw.text.tag( 'div', { style = string.format( tickDivstyleFormat, setOffset + setWidth / 2 ) }, '' ) )
end
Ligne 406 ⟶ 411 :
 
function drawChart()
table.insert( res, mw.text.tag( 'div', { class = 'chart noresize', style = string.format( '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 ) } ) )