Modulo:Demografia/sandbox: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
mNessun oggetto della modifica
use require("strict") instead of require("Module:No globals")
 
(10 versioni intermedie di un altro utente non mostrate)
Riga 1:
require("Module:No globalsstrict")
local getArgs = require('Module:Arguments').getArgs
local p = {}
 
local minimo, massimo
 
-- =====================================================================
Riga 39 ⟶ 41:
local function merge_years_population(years, populations)
local values = { }
local t
for i =1,#populations do
values[i]if (minimo == {nil year =or years[i], population< =minimo) populations[i],then numminimo = years[i] }end
if (massimo == nil or years[i] > massimo) then massimo = years[i] end
t = string.format("%g",math.floor(populations[i]+0.5))
t = t:gsub('%.',',')
values[i] = { year = years[i], population = populations[i], num = i, txt = t }
end
return values
Riga 48 ⟶ 55:
-- Crea tabella laterale
-- =====================================================================
local function mostraTabellaformato(a,b)
local k
local s = ''..a
while true do
s, k = s:gsub("^(-?%d+)(%d%d%d)", '%1&nbsp;%2')
if (k==0) then break end
end
return s
end
 
local function mostraTabella(a,b,f)
local ss = {}
table.insert(ss,'</td><td style="vertical-align:top"><table class="wikitable" style="font-size:smaller;text-align:right"><tr><th>Anno</th><th>Abitanti</th></tr>')
forif i =1,#b do> 12 then
table.insert(ss,string.format('<tr><th>%sAnno</th><tdth>%sAbitanti</tdth></tr>',a[i],math.floor(b[i]+0.5)))
local c = math.floor(0.5+#b/2)
for i =1,c do
table.insert(ss,string.format('<tr><th>%s</th><td>%s</td>',a[i],formato(math.floor(b[i]*f+0.5))))
if b[i+c] then table.insert(ss,string.format('<th>%s</th><td>%s</td>',a[i+c],formato(math.floor(b[i+c]*f+0.5)))) end
table.insert(ss,'</tr>')
end
else
table.insert(ss,'</tr>')
for i =1,#b do
table.insert(ss,string.format('<tr><th>%s</th><td>%s</td></tr>',a[i],formato(math.floor(b[i]*f+0.5))))
end
end
table.insert(ss,'</table></td></tr></table>')
Riga 109 ⟶ 137:
title = "Anno",
grid = true,
properties = {
labels = { font = { value = "Helvetica" } },
title = { font = { value = "Helvetica" } }
}
},
{
Riga 115 ⟶ 147:
title = "Abitanti",
grid = true,
layer = "back",
properties = {
labels = { font = { value = "Helvetica" } },
title = { font = { value = "Helvetica" } }
}
}
},
Riga 168 ⟶ 204:
align = {value = "center"},
fill = {value = "#000"},
text = {field = "populationtxt" },
font = {value = "Helvetica"},
}
}
Riga 192 ⟶ 229:
fill = {value = "black"},
fontSize = {value = 14},
font = {value = "Helvetica"},
align = {value = "center"},
fontWeight = {value = "bold"}
Riga 214 ⟶ 252:
local tabella1 = ''
local tabella2 = ''
local fattore = args.fattore and tonumber(args.fattore) and tonumber(args.fattore) or 1
if fattore == 1000 then
graph['axes'][2]['title'] = 'Abitanti (migliaia)'
elseif fattore == 1000000 then
graph['axes'][2]['title'] = 'Abitanti (milioni)'
end
if args.etichette then
if args.etichette == "dispari" then
-- mostra solo etichette dispari
graph['marks'][4]['from']['transform'] = {{ type = "filter", test = "(datum.num > 1) && (datum.num % 2 == 1)"}}
elseif args.etichette == "pari" then
graph['marks'][4]['from']['transform'] = {{ type = "filter", test = "(datum.num > 1) && (datum.num % 2 == 0)"}}
-- mostra solo etichette pari
elseif args.etichette == "tabella" then
graph['marks'][4]['from']['transform'] = {{ type = "filter", test = "(datum.num > 1) && (datum.num % 2 == 0)"}}
elseif args.etichette == "tabella" then
-- nasconde etichette e crea tabella a fianco
graph['marks'][4]['from']['transform'] = {{ type = "filter", test = "datum.num < 1"}}
tabella1 = '<table><tr><td style="vertical-align:top">'
tabella2 = mostraTabella(years, populations, fattore)
end
else
graph['marks'][4]['from']['transform'] = {{ type = "filter", test = "datum.num > 1"}}
end
--if true then return mw.text.jsonEncode(graph) end
Riga 234 ⟶ 279:
graph['marks'][5]['properties']['enter']['text']['template'] = template_text
end
if (massimo - minimo > 1) then
graph['scales'][1]['domainMin'] = minimo - (massimo-minimo)*0.04
graph['scales'][1]['domainMax'] = massimo + (massimo-minimo)*0.04
end
local ris = {}
table.insert(ris,titolo)