Modulo:Grafico XY: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
Nessun oggetto della modifica |
m modulo no globals obsoleto |
||
(28 versioni intermedie di un altro utente non mostrate) | |||
Riga 1:
require("
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 71 ⟶ 75:
name = "colori2",
type = "ordinal",
___domain = { data = "
range = { }
}
Riga 80 ⟶ 84:
scale = "x",
title = "",
format = args['formatoX'] or "d",
labelOverlap = "greedy",
grid = true,
properties = {▼
}▼
},
{
Riga 88 ⟶ 97:
title = "",
grid = true,
format = args['formatoY'] or "d",
labels = { font = { value = "Helvetica" } },
title = { font = { value = "Helvetica" } },
}▼
}
},
Riga 98 ⟶ 112:
orient = "top-left",
offset = 8,
properties = {
▲ shape = {value = "square"},
labels = { font = { value = "Helvetica" }, fontSize = { value = 12 } },
strokeWidth = 0▼
symbols = {
▲ strokeWidth = { value = 0 },
},
legend = { fill = { value = "#fff" } }
}
},
{
Riga 106 ⟶ 127:
orient = "top-left",
offset = 8,
properties = {
▲ shape = {value = "square"},
labels = { font = { value = "Helvetica" }, fontSize = { value = 12 } },
strokeWidth = 0▼
symbols = {
▲ strokeWidth = { value = 0 },
opacity = { value = 0.3 }
},
legend = { fill = { value = "#fff" } }
}
}
},
marks = {
{
type = "rect",
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 '
local fattoreX = args.fattoreX and tonumber(args.fattoreX) and tonumber(args.fattoreX) or 1
if fattoreX == 0 then
Riga 123 ⟶ 166:
end
graph['axes'][1]['title'] = titoloX
local titoloY = args.titoloY or '
local fattoreY = args.fattoreY and tonumber(args.fattoreY) and tonumber(args.fattoreY) or 1
if fattoreY == 0 then
Riga 175 ⟶ 218:
}
graph['data'][i]['values'] = dt[i]
graph['marks'][1+i] = {
type = "line",
from = {data = "tab"..i },
Riga 189 ⟶ 232:
}
}
graph['marks'][1+i+numero] = {
type = "symbol",
from = {data = "tab"..i },
Riga 202 ⟶ 245:
}
}
graph['marks'][1+i+2*numero] = {
type = "text",
from = { data = "tab"..i },
Riga 211 ⟶ 254:
align = {value = "center"},
fill = {value = "#000"},
fontSize = { value = 12 },
text = {field = "txt" }
}
}
Riga 220 ⟶ 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 227 ⟶ 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 237 ⟶ 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 264 ⟶ 310:
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
▲ type = "rect",
if (args.minimoX and tonumber(args.minimoX)) then
▲ from = { data = "area" },
graph['scales'][1]['domainMin'] = tonumber(args.minimoX)
▲ properties = {
end
▲ enter = {
if (args.massimoX and tonumber(args.massimoX)) then
▲ x = {scale = "x",field = "x1"},
graph['scales'][1]['domainMax'] = tonumber(args.massimoX)
▲ x2 = {scale = "x",field = "x2"},
end
▲ y = {value = 0},
▲ y2 = {signal = "height"},
if (args.minimoY and tonumber(args.minimoY)) then
▲ fill = {scale = "colori2", field = "testo" },
graph['scales'][2]['domainMin'] = tonumber(args.minimoY)
▲ opacity = {value =0.2 }
if (args.massimoY and tonumber(args.massimoY)) then
▲ }
graph['scales'][2]['domainMax'] = tonumber(args.massimoY)
▲ }
end
▲ if args.area_legenda then graph['legends'][1]['orient'] = args.area_legenda end
local ris = {}
Riga 287 ⟶ 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 301 ⟶ 349:
-- ======================================================================================================
-- Funzione di intefaccia con template:
-- ======================================================================================================
function p.grafico(frame)
|