Modulo:Grafico XY: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
mNessun oggetto della modifica
Nessun oggetto della modifica
Riga 130:
-- legge valori
local numero = 1
local dx, dy, dt, cc
while (args['x'..numero]) do numero = numero+1 end
local err = '-'
dt = {}
 
while (args['x'..numero]) do
dx = leggi(args, "x"..numero)
dy = leggi(args, "y"..numero)
if (dx and dy) then
if (#dx == #dy) then
dt[numero] = unisci(dx, dy, fattoreX, fattoreY)
else
err = 'Errore nel numero di elementi per serie '..numero
break
end
else
err = 'Errore nella serie '..numero
break
end
numero = numero+1
end
numero = numero-1
if err == '-' then
local dx, dy, cc
for i = 1,numero do
cc = i%10
if cc == 0 then cc = 10 end
graph['data'][i] = {
name = "tab"..i,
transform = { { type = "sort", by = "nx" } },
}
graph['data'][i]['values'] = dt[i]
dx = leggi(args, "x"..i)
graph['marks'][i] = {
dy = leggi(args, "y"..i)
type = "line",
graph['data'][i]['values'] = unisci(dx, dy, fattoreX, fattoreY)
from = {data = "tab"..i },
 
graph['marks'][i] properties = {
type enter = "line",{
from interpolate = {datavalue = "tablinear"..i },
x = {scale = "x",field = "nx"},
properties = {
enter y = {scale = "y",field = "ny"},
interpolate stroke = {value = "linear"clr[cc] },
x strokeWidth = {scalevalue = "x",field = "nx"4},
y opacity = {scalevalue = "y",field = "ny"0.5},
}
stroke = {value = clr[cc] },
strokeWidth = {value = 4},
opacity = {value = 0.5}
}
}
graph['marks'][i+numero] = {
}
type = "symbol",
graph['marks'][i+numero] = {
type from = {data = "symboltab"..i },
properties = {
from = {data = "tab"..i },
properties enter = {
enter x = {scale = "x",field = "nx"},
x y = {scale = "xy",field = "nxny"},
y stroke = {scalevalue = "y",fieldclr[cc] = "ny"},
stroke fill = {value = clr[cc] "#fff"},
fill size = {value = "#fff"30},
size = {value = 30}
}
}
graph['marks'][i+2*numero] = {
}
type = "text",
graph['marks'][i+2*numero] = {
type from = { data = "texttab"..i },
properties = {
from = { data = "tab"..i },
properties enter = {
enter x = {scale = "x",field = "nx"},
x y = {scale = "xy",field = "nxny", offset = -8},
y align = {scalevalue = "ycenter",field = "ny", offset = -8},
align fill = {value = "center#000"},
fill text = {valuefield = "#000ny" },
text = {field = "ny" }
}
}
graph['scales'][1]['___domain']['fields'][i] = {data = "tab"..i,field = "nx"}
}
graph['scales'][12]['___domain']['fields'][i] = {data = "tab"..i,field = "nxny"}
graph['scales'][23]['___domain']['fieldsrange'][i] = {data = "tab"..i,field = "ny"}clr[cc]
-- colori
graph['scales'][3]['range'][i] = clr[cc]
if args['colore'..i] then
-- colori
if graph['marks'][i]['properties']['enter']['stroke']['value'] = args['colore'..i] then
graph['marks'][i+numero]['properties']['enter']['stroke']['value'] = args['colore'..i]
graph['marksscales'][i+numero3]['propertiesrange']['enter']['stroke']['value'i] = args['colore'..i]
graph['scales'][3]['range'][i] = args['colore'..i]
end
-- opzioni etichette
if args['etichette'..i] then
if args['etichette'..i] == 'dispari' then
graph['marks'][i+2*numero]['from']['transform'] = {{ type = "filter", test = "datum.num % 2 == 1"}}
elseif args['etichette'..i] == 'pari' then
graph['marks'][i+2*numero]['from']['transform'] = {{ type = "filter", test = "datum.num % 2 == 0"}}
elseif args['etichette'..i] == 'no' then
graph['marks'][i+2*numero]['from']['transform'] = {{ type = "filter", test = "datum.num < 1"}}
end
-- opzioni etichette
end
if args['etichette'..i] then
-- mostra dati
if args['mostraetichette'..i] == 'dispari' then
graph['marks'][i+2*numero]['from']['transform'] = {{ type = "filter", test = "datum.num % 2 == 1"}}
if args['mostra'..i] == '1' then
elseif args['etichette'..i] == 'pari' then
graph['marks'][numero+i]['from']['transform'] = {{ type = "filter", test = "datum.num < 1"}}
graph['marks'][i+2*numero]['from']['transform'] = {{ type = "filter", test = "datum.num % 2 == 0"}}
elseif args['mostra'..i] == '2' then
elseif args['etichette'..i] == 'no' then
graph['marks'][i+2*numero]['from']['transform'] = {{ type = "filter", test = "datum.num < 1"}}
end
end
-- mostra dati
if args['mostra'..i] then
if args['mostra'..i] == '1' then
graph['marks'][numero+i]['from']['transform'] = {{ type = "filter", test = "datum.num < 1"}}
elseif args['mostra'..i] == '2' then
graph['marks'][i]['from']['transform'] = {{ type = "filter", test = "datum.num < 1"}}
end
end
end
-- legenda
end
graph['data'][numero+1] = {
-- legenda
name = "nomi",
graph['data'][numero+1] = {
name values = "nomi",{ }
values = { }
local lg = 1
}
while (args['nome'..lg]) do
local lg = 1
while graph['data'][numero+1]['values'][lg] = { testo = (args['nome'..lg]) do}
lg = lg +1
graph['data'][numero+1]['values'][lg] = { testo = args['nome'..lg] }
end
lg = lg +1
if args.legenda then graph['legends'][1]['orient'] = args.legenda end
end
if args.legenda then graph['legends'][1]['orient'] = args.legenda end
 
local ris = {}
local allinea = args['allinea'] or ''
if (flex[allinea]) then table.insert(ris,flex[allinea][1]) end
table.insert(ris,mw.getCurrentFrame():extensionTag('graph', mw.text.jsonEncode(graph)))
if (args.didascalia) then
table.insert(ris,'<p>'..args.didascalia..'</p>')
end
if (flex[allinea]) then table.insert(ris,flex[allinea][2]) end
if args['debug'] then
return mw.text.jsonEncode(graph)
else
return table.concat(ris)
end
else
return '<span style="color:red"><b>Template GraficoXY:</b> '..err..'</span>'
return table.concat(ris)
end
end