Modulo:Diagramma parlamentare: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
mNessun oggetto della modifica |
legenda: uso codice generato da t:Box colorato e t:, |
||
| (17 versioni intermedie di 4 utenti non mostrate) | |||
Riga 1:
require('
local p = {}
local getArgs = require('Module:Arguments').getArgs
local errorCategory = '[[Categoria:Errori di compilazione del template Diagramma parlamentare]]'
local colore = require('Module:Partiti').colore
local dimx = 175
Riga 7 ⟶ 9:
local dimc = 40
local limite = 2000
-- Error handler per xpcall, formatta l'errore.
local function errhandler(msg)
local cat = mw.title.getCurrentTitle().namespace == 0 and errorCategory or ''
return string.format('<span class="error">%s</span>%s', msg, cat)
end
-- crea unico array per stringa
Riga 20 ⟶ 28:
local function colora(a,b)
local c = '#CCC'
if (
c =
else
c =
end
if string.sub(c,1,5) == '#' then c = "#" .. string.sub(c, 6, 11) end
Riga 78 ⟶ 86:
-- crea arco parlamentare
function p.
local ss = {}
local ss2 = {}
Riga 95 ⟶ 92:
local num = 1
local totalepunti = 0
local dida = args
local mostra =
while (args['n'..num]) do
if (tonumber(args['n'..num])) then
dati[num] = {
n = args['n'..num] and tonumber(args['n'..num]), c = colora(args['p'..num] or '', args['c'..num]), b = args['b'..num] or '-' p = args['p'..num] or 'Serie '..num
}
totalepunti = totalepunti + dati[num].n
num = num+1
else
end
end
num = num - 1
if (totalepunti>limite) then
elseif (totalepunti<1) then
end
local punti = valori(totalepunti)
if (args['larghezza'] and tonumber(args['larghezza'])) then
scala = larghezza/(2*dimx)
elseif (args['altezza'] and tonumber(args['altezza'])) then
scala = altezza/(dimx+dimc)
elseif (totalepunti<29) then
larghezza = 200
scala = larghezza/(2*dimx)
altezza = (dimx+dimc)*scala
elseif (totalepunti<101) then
larghezza = 250
scala = larghezza/(2*dimx)
altezza = (dimx+dimc)*scala
elseif (totalepunti<281) then
larghezza = 300
scala = larghezza/(2*dimx)
altezza = (dimx+dimc)*scala
end
-- crea HTML
agg(ss,mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = 'Template:Diagramma parlamentare/styles.css' } })
agg(ss, string.format('<div class="diaPar" style="width: %dpx; height: %dpx">', larghezza, altezza))
local ee = 0
local valori
for i=1,num do
for j=1,dati[i].n do
ee = ee + 1
local size = 2 * dimc * scala
local px = (dimx-punti[ee][2]*math.cos(math.pi*punti[ee][1])) * scala - size/2
local py = altezza - (dimc+punti[ee][2]*math.sin(math.pi*punti[ee][1])) * scala - size/2
local color = dati[i].c
-- punti come elementi div
agg(ss, string.format(
'<div style="left: %.2fpx; top: %.2fpx; width: %.2fpx; height: %.2fpx; background-color: %s"></div>',
px, py, size, size, color
))
end
end
agg(ss, '</div>')
-- Aggiungiamo la didascalia, se presente
if (dida ~= '') then
agg(ss,string.format('<p style="font-size:90%%; margin-left:10px">%s</p>',dida))
end
if mostra == 1 then
for i=1,num do
agg(ss2,string.format('<span style="border:1px solid grey; background-color:%s; color:black; width:1em; height:1em"> </span> %s', dati[i].c, dati[i].n))
end
agg(ss,'<p style="font-size:90%; margin-left:10px">')
agg(ss,table.concat(ss2,"<b> · </b>"))
agg(ss,'</p>')
elseif mostra ==2 then
for i=1,num do
agg(ss2,string.format('<span style="border:1px solid grey; background-color:%s; color:black; width:1em; height:1em"> </span> %s %s', dati[i].c, dati[i].p, dati[i].n))
end
agg(ss,'<p style="font-size:90%; margin-left:10px">')
agg(ss,table.concat(ss2,"<br/>"))
agg(ss,'</p>')
end
if args['debug'] then
return table.concat(ss)
else
return table.concat(ss)
end
end
function p.parlamento(frame)
return select(2, xpcall(function()
return p._parlamento(getArgs(frame, { parentOnly = true }))
end, errhandler))
end
| |||