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:,
 
(13 versioni intermedie di 4 utenti non mostrate)
Riga 1:
require('Module:No globalsstrict')
 
local p = {}
local getArgs = require('Module:Arguments').getArgs
local errorCategory = '[[Categoria:VociErrori condi erroricompilazione del modulotemplate Diagramma parlamentare]]'
local colore = require('Module:Partiti').colore
local dimx = 175
Riga 27 ⟶ 28:
local function colora(a,b)
local c = '#CCC'
if (ab) then
c = colore({a,(b or c)})
else
c = b or colore({a,(c)})
end
if string.sub(c,1,5) == '#' then c = "#" .. string.sub(c, 6, 11) end
Riga 126 ⟶ 127:
scala = altezza/(dimx+dimc)
larghezza = 2*dimx*scala
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
 
local graph = {
-- crea HTML
version = 2, width = larghezza, height = altezza, padding = "no",
agg(ss,mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = 'Template:Diagramma parlamentare/styles.css' } })
data = { },
agg(ss, string.format('<div class="diaPar" style="width: %dpx; height: %dpx">', larghezza, altezza))
scales = {
 
{ name = "x", type = "linear", range = "width", zero = true, domainMin = 0, domainMax = 2*dimx },
{ name = "y", type = "linear", range = "height", zero = true, domainMin = 0, domainMax = dimx + dimc }
},
marks = { }
}
local ee = 0
local valori
for i=1,num do
valori = {}
for j=1,dati[i].n do
ee = ee + 1
local size = {value = (2 * dimc * scala)^2}
valori[j] = {
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
filllocal = {valuecolor = dati[i].c},
}
 
end
-- punti come elementi div
graph['data'][i] = { name = "tab"..i, values = valori }
agg(ss, string.format(
graph['marks'][i] = { type = "symbol", from = {data = "tab"..i },
'<div style="left: %.2fpx; top: %.2fpx; width: %.2fpx; height: %.2fpx; background-color: %s"></div>',
properties = {
px, py, size, size, color
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
end
 
graph['marks'][num+1] = {
agg(ss, '</div>')
type = "text",
 
properties = {
-- Aggiungiamo la didascalia, se presente
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))
Riga 188 ⟶ 171:
if mostra == 1 then
for i=1,num do
agg(ss2,string.format('<span style="display:inline-block;border:1px solid grey 1px; background-color:%s; color:black; width:1em; height:1em">&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;%s', dati[i].c, dati[i].n))
end
agg(ss,'<p style="font-size:90%; margin-left:10px">')
agg(ss,table.concat(ss2," <b>&nbsp;· &nbsp;</b>"))
agg(ss,'</p>')
elseif mostra ==2 then
for i=1,num do
agg(ss2,string.format('<span style="display:inline-block;border:1px solid grey 1px; 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))
end
agg(ss,'<p style="font-size:90%; margin-left:10px">')
Riga 201 ⟶ 184:
agg(ss,'</p>')
end
 
if args['debug'] then
return mwtable.text.jsonEncodeconcat(graphss)
else
return table.concat(ss)