Modulo:Grafico XY: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Nessun oggetto della modifica
m modulo no globals obsoleto
 
(30 versioni intermedie di un altro utente non mostrate)
Riga 1:
require("Module:No globalsstrict")
 
local getArgs = require('Module:Arguments').getArgs
local p = {}
Riga 29 ⟶ 30:
local function unisci(a,b,c,d)
local values = { }
local t
for i =1,#b do
t = string.format("%g",math.floor(10*b[i]/d+0.5)/10)
values[i] = { nx = a[i]/c, ny = b[i]/d, num = i }
t = t:gsub('%.',',')
values[i] = { nx = a[i]/c, ny = b[i]/d, num = i, txt = t }
end
return values
Riga 66 ⟶ 70:
type = "ordinal",
___domain = { data = "nomi", field = "testo"},
range = { }
},
{
name = "colori2",
type = "ordinal",
___domain = { data = "area", field = "testo"},
range = { }
}
Riga 73 ⟶ 83:
type = "x",
scale = "x",
title = "X",
format = args['formatoX'] or "d",
labelOverlap = "greedy",
grid = true,
properties = {
shape labels = { font = { value = "squareHelvetica" } },
title = { font = { value = "Helvetica" } },
}
},
{
type = "y",
scale = "y",
title = "Y",
grid = true,
format = args['formatoY'] or "d",
layerlabelOverlap = "backgreedy",
layer = "back",
properties = {
labels = { font = { value = "Helvetica" } },
title = { font = { value = "Helvetica" } },
}
}
},
Riga 92 ⟶ 112:
orient = "top-left",
offset = 8,
properties = {
shape = {value = "square"},
labels = { font = { value = "Helvetica" }, fontSize = { value = 12 } },
strokeWidth = 0
symbols = {
strokeWidth = { value = 0 },
shape = { value = "square" },
opacity = { value = 0.7 }
},
legend = { fill = { value = "#fff" } }
}
},
{
fill = "colori2",
title = "",
orient = "top-left",
offset = 8,
properties = {
labels = { font = { value = "Helvetica" }, fontSize = { value = 12 } },
symbols = {
strokeWidth = { value = 0 },
shape = { value = "square" },
opacity = { value = 0.3 }
},
legend = { fill = { value = "#fff" } }
}
}
},
marks = { }
{
type = "rect",
from = { data = "area" },
properties = {
enter = {
x = {scale = "x",field = "x1"},
x2 = {scale = "x",field = "x2"},
y = {value = 0},
y2 = {signal = "height"},
fill = {scale = "colori2", field = "testo" },
opacity = {value =0.2 }
}
}
}
}
}
-- titoli assi
local titoloX = args.titoloX or 'X'
local fattoreX = args.fattoreX and tonumber(args.fattoreX) and tonumber(args.fattoreX) or 1
if fattoreX == 0 then
Riga 109 ⟶ 166:
end
graph['axes'][1]['title'] = titoloX
local titoloY = args.titoloY or 'Y'
local fattoreY = args.fattoreY and tonumber(args.fattoreY) and tonumber(args.fattoreY) or 1
if fattoreY == 0 then
Riga 161 ⟶ 218:
}
graph['data'][i]['values'] = dt[i]
graph['marks'][1+i] = {
type = "line",
from = {data = "tab"..i },
Riga 175 ⟶ 232:
}
}
graph['marks'][1+i+numero] = {
type = "symbol",
from = {data = "tab"..i },
Riga 188 ⟶ 245:
}
}
graph['marks'][1+i+2*numero] = {
type = "text",
from = { data = "tab"..i },
Riga 197 ⟶ 254:
align = {value = "center"},
fill = {value = "#000"},
textfont = {fieldvalue = "nyHelvetica" },
fontSize = { value = 12 },
text = {field = "txt" }
}
}
Riga 206 ⟶ 265:
-- colori
if args['colore'..i] then
graph['marks'][1+i]['properties']['enter']['stroke']['value'] = args['colore'..i]
graph['marks'][1+i+numero]['properties']['enter']['stroke']['value'] = args['colore'..i]
graph['scales'][3]['range'][i] = args['colore'..i]
end
Riga 213 ⟶ 272:
if args['etichette'..i] then
if args['etichette'..i] == 'dispari' then
graph['marks'][1+i+2*numero]['from']['transform'] = {{ type = "filter", test = "datum.num % 2 == 1"}}
elseif args['etichette'..i] == 'pari' then
graph['marks'][1+i+2*numero]['from']['transform'] = {{ type = "filter", test = "datum.num % 2 == 0"}}
elseif args['etichette'..i] == 'no' then
graph['marks'][1+i+2*numero]['from']['transform'] = {{ type = "filter", test = "datum.num < 1"}}
end
end
Riga 223 ⟶ 282:
if args['mostra'..i] then
if args['mostra'..i] == '1' then
graph['marks'][1+numero+i]['from']['transform'] = {{ type = "filter", test = "datum.num < 1"}}
elseif args['mostra'..i] == '2' then
graph['marks'][1+i]['from']['transform'] = {{ type = "filter", test = "datum.num < 1"}}
end
end
end
 
-- legenda
graph['data'][numero+1] = {
Riga 240 ⟶ 300:
end
if args.legenda then graph['legends'][1]['orient'] = args.legenda end
 
-- annotazioni
graph['data'][numero+2] = {
name = "area",
values = { }
}
lg = 1
while (args['area'..lg]) do
graph['data'][numero+2]['values'][lg] = { testo = args['area'..lg], x1 = args['area'..lg..'_x1'], x2 = args['area'..lg..'_x2'] }
graph['scales'][4]['range'][lg] = args['area'..lg..'_colore'] or clr[lg]
graph['scales'][1]['___domain']['fields'][numero+2*lg-1] = {data = "area",field = "x1"}
graph['scales'][1]['___domain']['fields'][numero+2*lg] = {data = "area",field = "x2"}
lg = lg +1
end
if args.area_legenda then graph['legends'][2]['orient'] = args.area_legenda end
 
if (args.minimoX and tonumber(args.minimoX)) then
graph['scales'][1]['domainMin'] = tonumber(args.minimoX)
end
if (args.massimoX and tonumber(args.massimoX)) then
graph['scales'][1]['domainMax'] = tonumber(args.massimoX)
end
 
if (args.minimoY and tonumber(args.minimoY)) then
graph['scales'][2]['domainMin'] = tonumber(args.minimoY)
end
if (args.massimoY and tonumber(args.massimoY)) then
graph['scales'][2]['domainMax'] = tonumber(args.massimoY)
end
 
local ris = {}
Riga 246 ⟶ 335:
table.insert(ris,mw.getCurrentFrame():extensionTag('graph', mw.text.jsonEncode(graph)))
if (args.didascalia) then
table.insert(ris,'<p style="font-size:90%;margin-left:30px">'..args.didascalia..'</p>')
end
if (flex[allinea]) then table.insert(ris,flex[allinea][2]) end
Riga 260 ⟶ 349:
 
-- ======================================================================================================
-- Funzione di intefaccia con template:DemografiaGrafico XY
-- ======================================================================================================
function p.grafico(frame)