Modulo:Diagramma parlamentare: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
m estensione limite a 2000
legenda: uso codice generato da t:Box colorato e t:,
 
(19 versioni intermedie di 4 utenti non mostrate)
Riga 1:
require('Module:No globalsstrict')
 
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 19 ⟶ 27:
-- a = partito; b = colore opzionale
local function colora(a,b)
local c = colore({a,(b or '#CCC')})
if (b) then
c = b
else
c = colore({a,(c)})
end
if string.sub(c,1,5) == '&#35;' then c = "#" .. string.sub(c, 6, 11) end
return c
Riga 73 ⟶ 86:
 
-- crea arco parlamentare
function p.parlamento_parlamento(frameargs)
local args = getArgs(frame, { valueFunc =
function (key, value)
if type(key) == "number" then
if value == nil then return nil else value = mw.text.trim(value) end
else
if value == '' then return nil end
end
return value
end })
local err = {}
agg(err, '<p style="color:#800"><b>Errore nel template:</b>')
local ss = {}
local ss2 = {}
Riga 90 ⟶ 92:
local num = 1
local totalepunti = 0
local dida = args['.didascalia'] or ''
local mostra = 'n'tonumber(args.mostra) or 0
if (args['mostra'] and args['mostra']=='s') then mostra = 's' end
 
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
aggerror(string.format(err,' Valore per n'..num..'%d non valido.', num),2)
end
end
num = num - 1
if (totalepunti>limite) then
aggerror(err,' Numero di punti superiore al limite.')
elseif (totalepunti<1) then
aggerror(err,' Non sono stati indicati punti.')
end
local punti = valori(totalepunti)
if (#err == 1) then
local puntilarghezza = valori(totalepunti)2*dimx
local larghezzaaltezza = 2*dimx+dimc
local altezzascala = dimx+dimc1.0
if (args['larghezza'] and tonumber(args['larghezza'])) then
local scala = 1.0
if (args['larghezza'] and= tonumber(args['larghezza'])) then
scala = larghezza/(2*dimx)
larghezza = tonumber(args['larghezza'])
scalaaltezza = larghezza/(2*dimx+dimc)*scala
elseif (args['altezza'] and tonumber(args['altezza'])) then
altezza = (dimx+dimc)*scala
elseif (args['altezza'] and= tonumber(args['altezza'])) then
scala = altezza/(dimx+dimc)
altezza = tonumber(args['altezza'])
scalalarghezza = altezza/(2*dimx+c)*scala
elseif (totalepunti<29) then
larghezza = 2*dimx*scala
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
local graph = {
 
version = 2, width = larghezza, height = altezza, padding = "no",
agg(ss, '</div>')
data = { },
 
scales = {
-- Aggiungiamo la didascalia, se presente
{ name = "x", type = "linear", range = "width", zero = true, domainMin = 0, domainMax = 2*dimx },
if (dida ~= '') then
{ name = "y", type = "linear", range = "height", zero = true, domainMin = 0, domainMax = dimx + dimc }
agg(ss,string.format('<p style="font-size:90%%; margin-left:10px">%s</p>',dida))
},
end
marks = { }
if mostra == 1 then
}
local ee = 0
local valori
for i=1,num do
agg(ss2,string.format('<span style="border:1px solid grey; background-color:%s; color:black; width:1em; height:1em">&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;%s', dati[i].c, dati[i].n))
valori = {}
for j=1,dati[i].n do
ee = ee + 1
valori[j] = {
px = dimx-punti[ee][2]*math.cos(math.pi*punti[ee][1]),
py = dimc+punti[ee][2]*math.sin(math.pi*punti[ee][1]),
}
end
graph['data'][i] = { name = "tab"..i, values = valori }
graph['marks'][i] = { type = "symbol", from = {data = "tab"..i },
properties = {
enter = {
x = {scale = "x",field = "px"},
y = {scale = "y",field = "py"},
fill = {value = dati[i].c},
size = {value = (2*dimc*scala)^2}
}
}
}
if (dati[i].b ~= "-") then
graph['marks'][i]['properties']['enter']['stroke'] = {value = dati[i].b}
graph['marks'][i]['properties']['enter']['strokeWidth'] = {value = 1}
end
agg(ss2,string.format('<span style="display:inline-block;border:solid grey 1px;background:%s;width:1em;height:1em">&nbsp;</span>&nbsp;%s', dati[i].c, dati[i].n))
end
agg(ss,'<p style="font-size:90%; margin-left:10px">')
graph['marks'][num+1] = {
agg(ss,table.concat(ss2,"<b>&nbsp;·&nbsp;</b>"))
type = "text",
agg(ss,'</p>')
properties = {
elseif mostra ==2 then
enter = {
for i=1,num do
x = {scale = "x",value=dimx},
agg(ss2,string.format('<span style="border:1px solid grey; background-color:%s; color:black; width:1em; height:1em">&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;%s %s', dati[i].c, dati[i].p, dati[i].n))
y = {scale = "y",value=dimc+8},
align = {value = "center"},
fill = {value = "#000"},
font = {value = "Helvetica"},
fontSize = { value = 36*scala },
fontWeight = { value = "bold" },
text = {value = totalepunti }
}
}
}
agg(ss, mw.getCurrentFrame():extensionTag('graph', mw.text.jsonEncode(graph)))
if (dida ~= '') then
agg(ss,string.format('<p style="font-size:90%%; margin-left:10px">%s</p>',dida))
end
if (mostra == 's') then
agg(ss,'<p style="font-size:90%; margin-left:10px">')
agg(ss,table.concat(ss2," · "))
agg(ss,'</p>')
end
if args['debug'] then
return mw.text.jsonEncode(graph)
else
return table.concat(ss)
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)
agg(err,'</p>')
return table.concat(err)
end
end
 
function p.parlamento(frame)
return select(2, xpcall(function()
return p._parlamento(getArgs(frame, { parentOnly = true }))
end, errhandler))
end