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.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 95 ⟶ 91:
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+dimc)*scala
end
larghezza = 2*dimx*scala
local graph = {
end
version = 2, width = larghezza, height = altezza, padding = "no",
local graph = {
data = { },
version = 2, width = larghezza, height = altezza, padding = "no",
datascales = { },
{ name = "x", type = "linear", range = "width", zero = true, domainMin = 0, domainMax = 2*dimx },
scales = {
{ name = "xy", type = "linear", range = "widthheight", zero = true, domainMin = 0, domainMax = 2*dimx + dimc },
},
{ name = "y", type = "linear", range = "height", zero = true, domainMin = 0, domainMax = dimx + dimc }
marks = { },
}
marks = { }
local ee = 0
}
local ee = 0valori
for i=1,num do
local valori
forvalori i=1,num do{}
for j=1,dati[i].n do
valori = {}
foree j=1,dati[i].n doee + 1
eevalori[j] = ee + 1{
px = dimx-punti[ee][2]*math.cos(math.pi*punti[ee][1]),
valori[j] = {
pxpy = dimx-dimc+punti[ee][2]*math.cossin(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
graph['marksdata'][num+1i] = { name = "tab"..i, values = valori }
graph['marks'][i] = { type = "symbol", from = {data = "tab"..i },
type = "text",
properties = {
enter = {
x = {scale = "x",valuefield =dimx "px"},
y = {scale = "y",valuefield =dimc+8 "py"},
alignfill = {value = "center"dati[i].c},
fillsize = {value = "#000"(2*dimc*scala)^2},
font = {value = "Helvetica"},
fontSize = { value = 36*scala },
fontWeight = { value = "bold" },
text = {value = totalepunti }
}
}
}
if (dati[i].b ~= "-") then
agg(ss, mw.getCurrentFrame():extensionTag('graph', mw.text.jsonEncode(graph)))
graph['marks'][i]['properties']['enter']['stroke'] = {value = dati[i].b}
if (dida ~= '') then
graph['marks'][i]['properties']['enter']['strokeWidth'] = {value = 1}
agg(ss,string.format('<p style="font-size:90%%; margin-left:10px">%s</p>',dida))
end
end
if (mostra == 's') then
graph['marks'][num+1] = {
agg(ss,'<p style="font-size:90%; margin-left:10px">')
type = "text",
agg(ss,table.concat(ss2," · "))
properties = {
agg(ss,'</p>')
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">&nbsp;</span>&nbsp;%s', dati[i].c, dati[i].n))
end
agg(ss,'<p style="font-size:90%; margin-left:10px">')
if args['debug'] then
agg(ss,table.concat(ss2," · "))
return mw.text.jsonEncode(graph)
agg(ss,'</p>')
else
elseif mostra ==2 then
return table.concat(ss)
for i=1,num do
agg(ss2,string.format('<span style="display:inline-block;border:solid grey 1px;background:%s;width:1em;height:1em">&nbsp;</span>&nbsp;%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)
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