Modulo:Grafico epidemia/sandbox: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
m rip
alleggerito
Riga 409:
return table.concat(output)
end
 
function p._chart(args)
local navbar = require('Modulo:Navbox')._navbox
local barargs = {}
local barwidth = 280
if args.barwidth == 'thin' then
barwidth = 120
elseif args.barwidth == 'medium' then
barwidth = 280
elseif args.barwidth == 'wide' then
barwidth = 400
end
local function _numwidth(p)
local n = mw.ustring.sub((args.numwidth or ''),p,p)
if n == 'n' then
return 0
elseif n == 't' then
return 40
elseif n == 'm' then
return 55
elseif n == 'w' then
return 70
elseif n == 'd' then
return 55
end
return 0
end
local numwidth = 120
local right1 = numwidth - 8 -- -8 because of padding
if args.numwidth then
numwidth = _numwidth(1) + 10 + _numwidth(2)
if mw.ustring.len(args.numwidth) == 4 then
numwidth = numwidth + _numwidth(3) + _numwidth(4)
if mw.ustring.sub(args.numwidth,3,3) == 'n' then
numwidth = numwidth + 6
else
numwidth = numwidth + 10
end
end
right1 = _numwidth(1) + 2 + _numwidth(2)
if (not args.destra2) and mw.ustring.len(args.numwidth) == 4 then
right1 = right1 + _numwidth(3) + _numwidth(4)
if mw.ustring.sub(args.numwidth,3,3) == 'n' then
numwidth = numwidth + 6
else
numwidth = numwidth + 10
end
end
end
barargs.width = (85 + barwidth + numwidth) .. 'px'
barargs.barwidth = barwidth .. 'px'
barargs.float = args.float and args.float or 'right'
local ___location = mw.ustring.gsub(args.localita, 'I ', '')
___location = mw.ustring.upper(mw.ustring.sub(___location,1,1)) .. mw.ustring.sub(___location,2)
local navbartitle = args.epidemia .. '/' ..
'grafico dei casi in' .. ((args.localita3) and (args.posttitolo and '/') or '') ..
((args.localita2) and (args.localita2 and '/') or '') ..
___location
local title = {}
title[1] = ((args.pretitolo) and (args.pretitolo .. ' ') or ('')) ..
' casi di ' .. args.malattia .. args.preposizione ..
((args.localita) or '') ..
((args.localita2) and (', ' .. args.localita2) or '') ..
((args.localita3) and (', ' .. args.localita3) or '') ..
((args.posttitolo) and (' ' .. args.posttitolo) or '') .. '<span class="nowrap">&nbsp;&nbsp;</span>(' ..
navbar({[1] = navbartitle, titleArg = (':' .. mw.getCurrentFrame():getParent():getTitle()), mini = 1, nodiv = 1}) ..
')<br />'
title[2] = p._legend0({[1] = p._barColors(1),[2] = 'Morti'})
if yesno(args.guarigioni) == false then
title[3] = ''
else
title[3] = '<span class="nowrap">&nbsp;&nbsp;&nbsp;</span>' .. p._legend0({[1] = p._barColors(2),[2] = (args.reclbl or 'Guarigioni')})
end
title[4] = '<span class="nowrap">&nbsp;&nbsp;&nbsp;</span>' .. p._legend0({[1] = p._barColors(3),[2] = (args.altlbl1 or 'Ammalati')})
if args.altlbl2 then
title[5] = '<span class="nowrap">&nbsp;&nbsp;&nbsp;</span>' .. p._legend0({[1] = p._barColors(4),[2] = args.altlbl2})
else
title[5] = ''
end
if args.altlbl3 then
title[6] = '<span class="nowrap">&nbsp;&nbsp;&nbsp;</span>' .. p._legend0({[1] = p._barColors(5),[2] = args.altlbl3}) ..'\n'
else
title[6] = '\n'
end
title[7] = (args.togglesbar or '') -- this feature is WIP
barargs.title = table.concat(title)
barargs.left1 =
'<div class="center" style="margin-left:auto; margin-right:auto;width:77px;">' .. -- 85-8 because of padding
"'''Data'''" ..
'</div>'
barargs.right1 =
'<div class="center" style="margin-left:auto; margin-right:auto;width:' .. right1 .. 'px;">' ..
(args.destra1 or "'''&#35; di casi'''") ..
'</div>'
if args.destra2 then
local right2 = _numwidth(3) + _numwidth(4)
if mw.ustring.sub(args.numwidth,3,3) == 'n' then
right2 = right2 - 2
else
right2 = right2 + 2
end
barargs.right2 =
'<div class="center" style="margin-left:auto; margin-right:auto;width:' ..right2 ..'px;">' ..
"'''" .. args.destra2 .. "'''" ..
'</div>'
end
 
if args.rows then
barargs.bars = args.rows
elseif args.data then
barargs.bars = p._buildBars({
barwidth = barwidth,
data = args.data,
divisor = args.divisor,
numwidth = args.numwidth,
collapsible = args.collapsible
})
end
barargs.caption = args.caption
return p._barBox(barargs)
end
 
function p._barBox(args)
local width = args.width or 'auto'
local class = 'barbox'
if args.float == 'left' or args.float == 'right' or args.float == 'none' then
class = 'barbox t' .. args.float
elseif args.float == 'center' then
class = 'barbox tnone'
end
local output = {}
if (args.float == 'left') or (args.float == 'right') then
output[1] = ''
output[11] = ''
else
output[1] = '<table style="margin:' .. ( (args.float == 'center') and '0 auto' or 'auto' ) .. '; border:none;"><tr><td style="border:none; padding:0;">'
output[11] = '</td></tr></table>[[Category:Pages using bar box without float left or float right|' .. ( (width == 'auto') and 'Ω' or '' ) .. mw.title.getCurrentTitle().text .. ']]'
end
output[2] =
'<div class="' .. class .. '" style="overflow-x: auto;' .. (args.style or '') .. '">\n' ..
'<div style="border:' .. (args.border_width or '1') .. 'px solid silver; font-size:88%; padding:0.4em; width:' .. width .. '; background: ' .. (args['background-color'] or 'white') .. ';">\n' ..
'<table style="text-align:left; border-collapse:collapse; width:100%;">\n'
 
if args.title then
output[3] =
'<tr style="background:' .. (args.titlebar or 'none') .. '">' ..
'<th style="text-align:center;" colspan="5">' .. args.title .. '</th>' ..
'</tr>\n'
else
output[3] = ''
end
output[4] =
'<tr style="font-size:88%; height:4px;">\n' ..
'<td ' .. (args.left2 and '' or 'colspan="2"') .. ' style="padding:0 4px; text-align:left;">' ..
(args.left1 or '') ..
'</td>\n'
if args.left2 then
output[5] = '<td style="padding:0 4px; text-align:right;">' .. args.left2 .. '</td>\n'
else
output[5] = ''
end
output[6] = '<td style="width:' .. (args.barwidth or '100px') .. '; text-align:left;"></td>\n' ..
'<td ' .. (args.destra2 and '' or 'colspan="2"') .. ' style="padding:0 4px; width:1em; text-align:right;">' ..
(args.destra1 or '') ..
'</td>\n'
if args.destra2 then
output[7] = '<td style="padding:0 4px; text-align:right;">' .. args.destra2 .. '</td>\n'
else
output[7] = ''
end
output[8] = '</tr>\n' .. (args.bars or '')
if args.caption then
output[9] = '<tr><td colspan="5" style="padding:5px; text-align:left;">' .. args.caption .. '</td></tr>\n'
else
output[9] = ''
end
output[10] = '</table>\n</div>\n</div>\n'
-- output[11] defined above
return table.concat(output)
end
 
function p.barBox(frame)
local args = getArgs(frame, {
valueFunc = function (key, value)
if value then
value = mw.text.trim(value)
if (key == 'width') or (key == 'float') then
value = mw.ustring.lower(value)
end
if value ~= '' then
return value
end
end
return nil
end
})
return p._barBox(args)
end
 
function p.chart(frame)
local args = getArgs(frame, {
valueFunc = function (key, value)
if value then
value = mw.text.trim(value)
if (key == 'numwidth') or (key == 'barwidth') or (key == 'guarigioni') then
value = mw.ustring.lower(value)
end
if value ~= '' then
return value
end
end
return nil
end
})
return p._chart(args)
end