Modulo:Discendenza: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
mNessun oggetto della modifica |
ottimizzazione |
||
Riga 1:
require('Module:No globals')
local getArgs = require('Module:Arguments').getArgs
local errorCategory = '[[Categoria:Errori di compilazione del template Discendenza]]'
local p = {}
Line 6 ⟶ 7:
local tabella = {}
local txt = {}
local function errhandler(msg)
local cat = mw.title.getCurrentTitle().namespace == 0 and errorCategory or ''
return string.format('<span class="error">%s</span>%s', msg, cat)
end
local function agg(t)
Line 15 ⟶ 21:
local resto = 0
local nx,px
-- conta elementi
while (dati[n]) do n = n+1 end
n = n-1
-- crea pers dai dati
for m=4,n,4 do
nx = tonumber(dati[m-3])
Line 26 ⟶ 31:
if (px) then
if (pers[nx]) then
else
pers[nx] = { padre = px, testo = dati[m-1], nota = dati[m], id = -1, x = -1, y = -1, sp = 0, figli = {} }
end
else
end
else
end
resto = n-m
end
if (
end
end
Line 133 ⟶ 137:
local tt = #pers[pid].figli
if (tt == 0) then
if (pers[pid].padre == -1 or pers[pid].id == 1) then
pers[pid].x = 0
else
Line 141 ⟶ 143:
end
elseif (tt == 1) then
if (pers[pid].padre == -1 or pers[pid].id == 1) then
pers[pid].x = pers[pers[pid].figli[1]].x
else
Riga 152:
else
local media = math.floor((pers[pers[pid].figli[1]].x + pers[pers[pid].figli[tt]].x)/2)
if (pers[pid].padre == -1 or pers[pid].id == 1) then
pers[pid].x = media
else
Line 196 ⟶ 194:
local function mostraX(pid,allinea,largo,dida)
local xy = massimoXY(pid, {0, 0})
local
local n1
local
local riga = {}
local xx, xp
if (allinea == 'destra') then
agg(string.format('<div class="floatright" style="width:
agg('<table cellpadding="1" cellspacing="0" border=0 style="border-collapse:separate;text-align:center;font-size:95%;line-height: else
agg('<table cellpadding="1" cellspacing="0" border=0 style="border-collapse:separate;text-align:center;font-size:95%;line-height:
end
local lg = math.floor(100/(xy[1]+2))
if (lg == 0) then lg = 1 end
for n=1,xy[2] do
posx[1] = 0; posx[2] = 0; posx[3] = 0
n1 = 0
for _, v in pairs(tabella[n]) do
xx = pers[v].x
xp = pers[v].padre
if (n==1) then
for m=1,(xy[1]+2) do table.insert(riga[1],string.format('<td width=%d%%></td>',lg)) end
else
n1==xp and ';border-top:1px solid #000' or '',
xx-posx[1]>0 and '" colspan="'..(xx+1-posx[1]) or ''
)
n1 = xp
posx[1] = xx + 1
table.insert(riga[1],stx)
end
if (xx-
table.insert(riga[2],string.format('<td%s> </td>',
end
table.insert(riga[2],'<td colspan=2>'..pers[v].testo)
if (pers[v].nota == '-') then else table.insert(riga[2],
string.format('<br/><span style="font-size:90%%"><i>%s</i></span>',pers[v].nota))
end
table.insert(riga[2],'</td>')
posx[2] = xx + 2
if (n<xy[2]) then
if (#pers[v].figli > 0) then
end
end
end
if (n<xy[2]) then
agg(
agg(table.concat(riga[2]))
agg(table.concat(riga[3]))
end
Line 312 ⟶ 316:
end
function p.
local capo = -1
local n1, n2
local
local larg = args['larghezza'] or '300'
local tipo = args['tipo'] or 'o'
local dida = args['didascalia'] or ''
dividi(args)
n1 = 0
for i, v in pairs(pers) do
n1 = n1+1
if (v.padre == -1) then
if (capo == -1) then
capo = i
else
error(string.format('Inseriti più elementi come capostipite (id = %d, %d)',capo,i))
end
else
if (v.padre == i) then
error(string.format('Inserito elemento come figlio di se stesso (id = %d)', i))
elseif (pers[v.padre]) then
table.insert(pers[v.padre].figli,i)
else
error(string.format('Inserito id genitore = %d non valido (id = %d)',v.padre,i))
end
end
end
if (capo == -1) then
error('Capostipite non definito')
else
n2 = organizza(capo, 1)
if (n1 == n2) then
if (tipo == 'v') then
return mostraY(capo)
elseif (tipo == 'o') then
calcolaX1(capo)
calcolaX2(capo)
calcolaX3(capo, 0)
return mostraX(capo, lato, larg, dida)
end
else
error('Inseriti elementi non collegati al capostipite')
end
end
end
function p.main(frame)
local args = getArgs(frame, {
valueFunc = function (key, value)
Line 330 ⟶ 378:
end
})
return p._discendenza(args)
end
|