Modulo:Diagramma parlamentare: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
mNessun oggetto della modifica |
sistemazione legenda |
||
Riga 2:
local p = {}
local getArgs = require('Module:Arguments').getArgs
local errorCategory = '[[Categoria:Voci con errori del modulo Diagramma parlamentare]]'
local colore = require('Module:Partiti').colore
local dimx = 175
Riga 7 ⟶ 8:
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 78 ⟶ 85:
-- crea arco parlamentare
function p.
local ss = {}
local ss2 = {}
Riga 95 ⟶ 91:
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)
end
local graph = {
version = 2, width = larghezza, height = altezza, padding = "no",
data = { },
{ name = "x", type = "linear", range = "width", zero = true, domainMin = 0, domainMax = 2*dimx },
},
}
local ee = 0
for i=1,num do
for j=1,dati[i].n do
px = dimx-punti[ee][2]*math.cos(math.pi*punti[ee][1]),
}
end
graph['
graph['marks'][i] = { type = "symbol", from = {data = "tab"..i },
properties = {
enter = {
x = {scale = "x",
y = {scale = "y",
}
}
}
if (dati[i].b ~= "-") then
graph['marks'][i]['properties']['enter']['stroke'] = {value = dati[i].b}
graph['marks'][i]['properties']['enter']['strokeWidth'] = {value = 1}
end
end
graph['marks'][num+1] = {
type = "text",
properties = {
enter = {
x = {scale = "x",value=dimx},
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 == 1 then
for i=1,num do
agg(ss2,string.format('<span style="display:inline-block;border:solid grey 1px;background:%s;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," · "))
agg(ss,'</p>')
elseif mostra ==2 then
for i=1,num do
agg(ss2,string.format('<span style="display:inline-block;border:solid grey 1px;background:%s;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 mw.text.jsonEncode(graph)
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
| |||