Modulo:TeamBracket: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Moroboshi (discussione | contributi)
fix uso getWidth
m meglio inherit di color base
 
(38 versioni intermedie di 6 utenti non mostrate)
Riga 1:
--
-- This module will implement {{TeamBracket}}
--
require('Module:No globals')
local getArgs = require('Module:Arguments').getArgs
 
local p = {}
local yes_repliesargs = { 'yes', 'y', 's', 'si', 'sì'}
local no_repliesrows = { 'n', 'no'}
local debugmask = false{}
local rounds
local maxround
local legs = {}
local compact
local byes
local hideSeeds
local showSeeds
local hideHeadings
local showThird
local offsetThird
local compactFinal
local sepwidth
local aggsep
local aggregate
local boldwinner
local hideomittedscores
local RD1seedmap = {}
local tcats = ''
 
local stylefunction = {isnotblank(s)
return s and s ~= ''
table = "border-style:none;font-size:90%;margin:1em 2em 1em 1em;border-collapse:separate;border-spacing:0",
end
seed_cell = "background-color:#f2f2f2;border:1px solid #aaa;text-align:center;",
team_cell = "background-color:#f2f2f2;border:1px solid #aaa;text-align:left;", --padding:0 2px
score_cell ="background-color:#f9f9f9;border:1px solid #aaa;text-align:center;",
header_third_place = "text-align:center;border:1px solid #aaa;background-color:#f2f2f2",
header_cell = "text-align:center;border:1px solid #aaa;background-color:#f2f2f2",
path_bottom = "border:0 solid black;border-bottom-width:1px;",
path_rigth_top = "border:0 solid black;border-top-width:1px;border-right-width:2px;",
path_right_bottom = "border:0 solid black;border-bottom-width:1px;border-right-width:2px;",
path_top = "border:0 solid black;border-top-width:2px;",
group = "text-align:center",
winner = 'font-weight:bold',
first_place = 'background-color:gold',
second_place = 'background-color:silver',
third_place = 'background-color:#C96',
row_height = "3px",
buffer_sx_width = "5px",
seed_width = "25px",
team_width = "150px",
score_width = "25px",
row_width = "10px"
}
 
local function isblank(s)
if debug then
return (not s) or (s == '')
style.group = style.group .. ";background-color:green"
style.path_bottom = style.path_bottom .. ";background-color:#F08080"
style.path_top= style.path_top .. ";background-color:#F08080"
style.path_rigth_top= style.path_rigth_top .. ";background-color:#F08080"
style.path_right_bottom= style.path_right_bottom .. ";background-color:#F08080"
end
 
local function sumScores(s1, s2)
--[[ ===============================================================================
s1 = mw.ustring.gsub(s1 or '', '^[\'%s]*([%d%.]*).-$', '%1')
Ritorna true se needle è lista haystack, altrimenti ritorna false
s2 = mw.ustring.gsub(s2 or '', '^[\'%s]*([%d%.]*).-$', '%1')
===============================================================================]]
if s1 ~= '' and s2 ~= '' then
local function in_array( needle, haystack )
return tonumber(s1) + tonumber(s2)
if needle == nil then return false; end
for n,v in ipairs( haystack ) do
if v == needle then return true; end
end
return false;s1
end
 
local function scoreCompare(s1,s2,highwin)
--[[ ===============================================================================
local ps1 = mw.ustring.gsub(s1 or '', '^[\'%s]*([%d%.]*)[\'%s]*%([\'%s]*([%d%.]*)[\'%s]*%).-$', '%2')
Oggetto per generare un TeamBracket
local ps2 = mw.ustring.gsub(s2 or '', '^[\'%s]*([%d%.]*)[\'%s]*%([\'%s]*([%d%.]*)[\'%s]*%).-$', '%2')
- args: array dei parametri passati al modulo
s1 = mw.ustring.gsub(s1 or '', '^[\'%s]*([%d%.]*).-$', '%1')
===============================================================================]]
s2 = mw.ustring.gsub(s2 or '', '^[\'%s]*([%d%.]*).-$', '%1')
local TeamBracket = {}
 
if s1 ~= '' and s2 ~= '' then
function TeamBracket:new(args)
s1 = tonumber(s1)
s2 = tonumber(s2)
if s1 and s2 then
if (s1 == s2) then
ps1 = tonumber(ps1)
ps2 = tonumber(ps2)
if ps1 and ps2 then
s1 = ps1
s2 = ps2
end
end
if highwin then
return ((s1 > s2) and 1) or ((s1 < s2) and 2) or 0
else
return ((s2 > s1) and 1) or ((s2 < s1) and 2) or 0
end
end
end
return 0
end
 
local function unboldParenthetical(s)
local self = {}
if s then
setmetatable(self, { __index = TeamBracket,
s = mw.ustring.gsub(s, '(%(%[%[[^%[%]]*%]%]%))', '<span style="font-weight:normal">%1</span>')
__tostring = function(t) return self:__tostring() end })
end
return s
end
 
local function parseArgs(frame)
self.args = args
local fargs = frame.args
self.rounds = tonumber(self.args['rounds']) or 2
local pargs = frame:getParent().args;
self.teams = math.pow(2, self.rounds)
 
self.compact = in_array(self.args['compact'], yes_replies)
local r = tonumber(fargs.rounds or '') or tonumber(pargs.rounds or '') or 2
self.hideSeeds = in_array(self.args['seeds'], no_replies)
local teams = math.pow(2, r)
self.showSeeds = in_array(self.args['seeds'], yes_replies)
local paddingrdstr = '%0RD' .. tostring((self.teams < 10r) and 1 or 2) .. 'd'
self.argname_patternlocal rdbstr = 'RD%d-%s' .. paddingtostring(r) .. 'b'
self.scorename_patternlocal rdp1str = 'RD%d-score' .. paddingtostring(r+1)
 
local autobold_par = self.args['bold_winner'] or ''
for i=1,2 do
self.bold_winner = not in_array(autobold_par, no_replies)
local targs = (i == 1) and pargs or fargs
self.low_winner = self.bold_winner and (autobold_par == 'low')
for k,v in pairs(targs) do
self.medals = self.bold_winner and not in_array(self.args['medals'], no_replies)
if type(k) == 'string' then
-- load number of scores for each round
if k:find('^[R3][Dr][d1-9]b?%-[a-z][a-z]*00*') then
self.scores = {}
k = mw.ustring.gsub(k, '^([R3][Dr][d1-9]b?%-[a-z][a-z]*)00*', '%1')
local scores_raw = self.args.scores or '1'
if (teams < 10) then
local max_scores = 1
tcats = tcats .. '[[Categoria:Errori nella compilazione di TeamBracket|P]]'
for i,score_value in ipairs(mw.text.split(scores_raw, ',')) do
end
self.scores[i] = tonumber(score_value) or 1
end
if self.scores[i] > max_scores then max_scores = self.scores[i] end
if k:find('^' .. rdp1str) then
k = mw.ustring.gsub(k, '^' .. rdp1str, '3rd')
tcats = tcats .. '[[Categoria:Errori nella compilazione di TeamBracket|3]]'
elseif k:find('^' .. rdbstr) then
k = mw.ustring.gsub(k, '^' .. rdbstr, '3rd')
elseif k:find('^' .. rdstr .. '%-[a-z][a-z]*3') then
k = mw.ustring.gsub(k, '^' .. rdstr .. '(%-[a-z][a-z]*)3', '3rd%11')
elseif k:find('^' .. rdstr .. '%-[a-z][a-z]*4') then
k = mw.ustring.gsub(k, '^' .. rdstr .. '(%-[a-z][a-z]*)4', '3rd%12')
elseif k:find('^Consol') then
k = mw.ustring.gsub(k, '^Consol', 'RD-finalina')
tcats = tcats .. '[[Categoria:Errori nella compilazione di TeamBracket|3]]'
elseif k:find('^group[0-9]') then
tcats = tcats .. '[[Categoria:Errori nella compilazione di TeamBracket|G]]'
end
end
args[k] = v
end
end
 
local last_scores = self.scores[#self.scores]
if (args['byes'] and (args['byes'] == 'yes' or args['byes'] == 'y')) then
for i =#self.scores+1, self.rounds do
tcats = tcats .. '[[Categoria:Errori nella compilazione di TeamBracket|B]]'
self.scores[i] = last_scores
end
end
if max_scores > 1 then
 
self.scorename_pattern = self.scorename_pattern .. "-%d"
local function parseSeedmap(s)
s = mw.text.split((s or '0') .. '/', '[%s]*/[%s]*')
local teams = math.pow(2, rounds)
for r=1,teams do
RD1seedmap[r] = 1
end
for r=1,#s do
-- custom style
if tonumber(s[r] or 'x') then
style.winner = self.args.style_medal or style.winner
RD1seedmap[tonumber(s[r])] = 0
style.first_place = self.args.style_first_place or style.first_place
style.second_place = self.args.style_second_place or style.second_place
style.third_place = self.args.style_third_place or style.third_place
style.header_cell = self.args.style_header or style.header_cell
style.header_third_place = self.args.style_header_third_place or style.header_third_place
style.seed_width = self:getWidth('seed', style.seed_width)
style.team_width = self:getWidth('team', style.team_width)
style.score_width = self:getWidth('score', style.score_width)
-- set default seeds for round 1
if not(self.hideSeeds) then
local seeds = self:getSeeds()
local argname
for i = 1, table.getn(seeds) do
argname = self:getTeamArgName(1, 'seed', i)
if not args[argname] then
args[argname] = seeds[i]
end
end
end
local c = 1
self.tbl = mw.html.create('table'):cssText(style.table)
for r=1,teams do
if in_array(args['nowrap'], yes_replies) then
if RD1seedmap[r] > 0 then
self.tbl:css('white-space', 'nowrap')
RD1seedmap[r] = c
c = c + 1
end
end
self.rows = { }
if self.compact then self.tbl:attr('cellpadding', '0') end
self.last_element = {}
self.rows = {}
self.current_col = 0
self.dump = {}
self.not_draw_top = false
self:renderHeading()
self:renderTree()
return self
end
 
local function parseLegs(s)
--[[ ===============================================================================
s = mw.text.split((s or '1') .. '/', '[%s]*/[%s]*')
-- collassa l'oggetto in una stringa contenente il wikicodice per generare l'albero
if aggregate == 'n' or aggregate == 'no' or aggregate == '0' then
===============================================================================]]
aggregate = ''
function TeamBracket:__tostring()
end
return tostring(self.tbl)
local n = showThird and (rounds + 1) or (rounds)
local lastlegs = nil
for r=1,n do
if s[r] ~= nil and s[r] ~= '' and tonumber(s[r]) then
legs[r] = tonumber(s[r])
elseif lastlegs then
legs[r] = lastlegs
else
legs[r] = 1
end
lastlegs = legs[r]
if legs[r] > 1 and aggregate ~= '' then
legs[r] = legs[r] + 1
end
end
end
 
local function getSeeds()
--[[ ===============================================================================
Genera i valori di default dei seeds
===============================================================================]]
function TeamBracket:getSeeds()
local seeds = {1, 2}
local count = 2
local before = false
for r = 2, self.rounds do
local max = math.pow(2, r)
for i = 1, count do
Line 157 ⟶ 178:
end
 
local function addTableRow(tbl)
--[[ ===============================================================================
return tbl:tag('tr')
Se fino alla riga row, colonna col-1 non sono ancora stati aggiunti elementi aggiunte
end
una cella vuota dall'ultima colonna usta dalla riga.
 
Aggiorna quindi il conteggio delle colonne usate alla posizione colonna +width
local function addBlank(i, css, rowspan, colspan)
Il valore di default di width è 0
local row = rows[i]
=============================================================================== --]]
rowspan = rowspan or 1
function TeamBracket:addGap(row, col, width, debug_info)
widthlocal jmax = widthi + rowspan or- 1
for j = i, jmax do
if self.last_element[row] + 1 < col then
if rows[j] == nil then
local gap = tostring(col - self.last_element[row] - 1)
rowspan = rowspan - 1
local cell=self.rows[row]:tag('td'):css('background-color', (debug and '#F5F5DC') or ''):attr('colspan', gap)
ifelseif debugrow == nil then
row = rows[j]
cell:wikitext(string.format('<div style="text-align:center;" title="row=%d, colonna:%d, last_col=%d, width:%d, gap:%s, last_col_set:%d, round:%d, deb:%s">info</div>',
row, col, self.last_element[row], width, gap, col+width, self.current_round, debug_info or ''))
end
end
local cell = row and row:tag('td') or mw.html.create('td')
self.last_element[row] = col + width - 1
if rowspan and rowspan > 1 then
cell:attr('rowspan', rowspan)
end
if colspan and colspan > 1 then
cell:attr('colspan', colspan)
end
if css then
cell:css(css)
end
return cell
end
 
local function addBorders(cell, topcell, seedorteam, extrasep)
function TeamBracket:getWidth(param, default)
if sepwidth > 1 then topcell = true end
local arg = self.args[param .. '-width']
if not argseedorteam then return default end
cell:css('border', '1px solid var(--border-color-base, #aaa)')
arg = arg .. ((tonumber(arg) and 'px') or '')
:css('border-top-width', topcell and '1px' or '0')
else
cell:css('border-color', 'var(--border-color-base, #aaa)')
:css('border-style', 'solid')
:css('border-top-width', topcell and '1px' or '0')
:css('border-left-width', (extrasep and '1px') or ((sepwidth > 1) and '1px') or '0')
:css('border-right-width', '1px')
:css('border-bottom-width', '1px')
end
end
 
local function addHeading(row, r, text, pad)
pad = (pad == nil or pad < 0) and 0 or pad
row:tag('td')
:attr('colspan', tonumber(hideSeeds and '1' or '2') + legs[r] + pad)
:css('text-align', 'center')
:css('border', '1px solid var(--border-color-base, #aaa)')
:css('background-color', args['RD-shade'] or 'var(--background-color-neutral, #f2f2f2)')
:css('color', 'inherit')
:wikitext(text)
:newline()
end
 
local function getWidth(param, default)
local arg = args[param .. '-width']
if isblank(arg) then
arg = default
end
if tonumber(arg) ~= nil then
arg = arg .. 'px'
end
return arg
end
 
local function TeamBracket:getTeamArgName(round, argnametype, team)
if round > rounds then
return string.format(self.argname_pattern, round, argname, team)
return string.format('3rd-%s%d', type, team)
else
if (round == 1) then
team = RD1seedmap[team]
if team == 0 then
return 'NIL'
end
end
return string.format('RD%d-%s%d', round, type, team)
end
end
 
local function TeamBracket:getTeamArggetShadeArg(round, argnameteam, teams)
returnlocal argname = self.args[self:getTeamArgName(round, argname'shade', team)] .. (s and ('-' .. s) or '')
local value = args[argname]
if isblank(value) then
return 'var(--background-color-neutral-subtle, #f9f9f9)'
end
return value
end
 
local function TeamBracket:getScoreArg(round, team, scores)
local argname = getTeamArgName(round, 'score', team) .. (s and ('-' .. s) or '')
return self.args[string.format(self.scorename_pattern, round, team, score)]
local value = args[argname]
return value
end
 
local function TeamBracket:getRoundNamegetTeamArg(round, type, team)
local nameargname = self.args['RD'getTeamArgName(round, ..type, round]team)
local value = args[argname]
if name then return name end
if isblank(value) then
local round_names = {"Finale", "Semifinali", "Quarti", "Ottavi"}
return ''
local roundFromLast = self.rounds - round + 1
if roundFromLast < 5 then
return round_names[roundFromLast]
else
return tostring(round) .. "° turno"
end
if mw.ustring.find(value, '[%s]*<[%s/]*[Bb][Rr][%s/]*>[%s ]*&[Nn][Bb][Ss][Pp];[%s]*') then
tcats = tcats .. '[[Categoria:Errori nella compilazione di TeamBracket|N]]'
end
return mw.ustring.gsub(value, '[%s]*<[%s/]*[Bb][Rr][%s/]*>[%s ]*&[Nn][Bb][Ss][Pp];[%s]*', '<br/>')
end
 
local function isHidden(r, team)
--[[ ===============================================================================
return isblank( getTeamArg(r, 'team', team) )
Aggiunge le righe grafiche di congiunzione delle celle per la riga index del
end
turno round. top e left indicano se deve essere generata rispettivamente la riga
sinistra o quella superiore
- row1 = prima riga del match superiore da cui esce il path
- row2 = prima riga del match inferiore da cui esce il path
- row_gap = ampiezza del path
- col = colonna in cui inizia il path
row1 nullo significa che il path parte solo da row2 e viceversa. Se entrambi sono
nulli la funzione non disegna niente.
===============================================================================]]
function TeamBracket:addPath(row1, row2, row_gap, next_match)
 
local function getRoundName(round)
local col = self.current_col + self.current_width
local half_gapname = row_gapargs['RD' /.. 2round]
if not isnotblank(row1 or row2name) then return end
return name
self.render_match[self.current_round+1][next_match] = true
-- first half
if row1 then
self.rows[row1+1]:tag('td'):cssText(style.path_bottom)
for r = row1+1, row1+3 do self.last_element[r] = col end
for r = row1+4, row1+4+half_gap-1 do self:addGap(r, col, 1, 'ap1') end
self.rows[row1+2]:tag('td')
:attr('rowspan', half_gap + 2)
:cssText(style.path_rigth_top)
end
local roundFromLast = rounds - round + 1
--second half
if row2roundFromLast == 1 then
return "Finale"
self.rows[row2+2]:tag('td'):cssText(style.path_top)
elseif roundFromLast == 2 then
for r = row2, row2+2 do self.last_element[r] = col end
return "Semifinali"
for r = row2-half_gap, row2-1 do self:addGap(r, col, 1, 'ap2') end
elseif roundFromLast == 3 then
self.rows[row2-half_gap]:tag('td')
return "Quarti di finale"
:attr('rowspan', half_gap+2)
elseif roundFromLast == 4 then
:cssText(style.path_right_bottom)
return "Ottavi di finale"
elseif roundFromLast == 5 then
return "Sedicesimi di finale"
elseif roundFromLast == 6 then
return "Trentaduesimi di finale"
elseif roundFromLast < 7 then
return round_names[roundFromLast]
else
return tostring(round) .. "º turno"
end
local middle_row
middle_row = (row1 and (row1 + 2 + half_gap)) or (row2 - half_gap -2)
for r = middle_row-1, middle_row+2 do self:addGap(r, col+1, 1, 'ap3') end
--self:addGap(middle_row, col+1, 1, 'ap3')
--self:addGap(middle_row+1, col+1, 1, 'ap3')
self.rows[middle_row]:tag('td'):cssText(style.path_bottom):attr('rowspan', '2')
self.rows[middle_row+2]:tag('td'):cssText(style.path_top):attr('rowspan', '2')
end
 
local function addPath(index, round, top, left, w)
--[[ ------------------------------------------------------------
local prop = top and 'border-bottom-width' or 'border-top-width'
Compare score values and return and return the winner of the match
if left and round == 1 then
(team with majority of win, 0 mean parity, 1 fist team win, 2
if compact then
second team win) and and array with winner for single scores (for
addBlank(index)
each single score 0 parity, 1 first team win, 2 second team win.
else
------------------------------------------------------------ --]]
addBlank(index, {['height'] = '7px'})
function TeamBracket:getWinner(first_team_number)
addBlank(index+1, {['height'] = '7px'})
local victories1 = 0
local victories2 = 0
local score_results = {}
for i = 1, self.scores[self.current_round] do
local score1 = self:getScore(self.current_round, first_team_number, i)
local score2 = self:getScore(self.current_round, first_team_number+1, i)
if score1 and score2 then
if score1 ~= score2 then
local first_winner = score1 > score2
if self.low_winner then first_winner = not first_winner end
if first_winner then
victories1 = victories1 + 1
score_results[i] = 1
else
victories2 = victories2 + 1
score_results[i] = 2
end
end
end
return nil
score_results[i] = score_results[i] or 0
else
local cell = addBlank(index,
{['border-width'] = '0',
['border-style'] = 'solid',
['border-color'] = 'var(--color-base, black)'}, (not compact) and 2 or 1)
if left or round < maxround and not left then
cell:css(prop, w or '2px')
end
return cell
end
if victories1 == victories2 then return 0, score_results end
if victories1 > victories2 then return 1, score_results end
return 2, score_results
end
 
local function renderTeam(row, round, team, top, otherbye, pad)
--[[ ===============================================================================
pad = (pad == nil or pad < 0) and 0 or pad
Disegna la cella per il team.
tcs = pad + 1
-- team_name: il nome del team
local seedCell
-- team_numer: il numero del team nella sequenza del round
local seedArg = getTeamArg(round, 'seed', team)
-- row: la riga della prima cella in cui disegnare il team
-- top:seed truevalue sefor èthe il primopaired team del match
local otherteam = team % 2 == 0 and team-1 or team+1
-- winner: il vincitore del match (1: il primo, 2: il secondo, 0:pari)
local pairSeedArg = otherbye and ''
-- score_results: risultato degli scores individuali (1: vinto dal primo team, 2 vinto dal secondo, 3 pari)
or getTeamArg(round, 'seed', otherteam)
===============================================================================]]
-- show seed if seed is defined for either or both
function TeamBracket:renderTeam(team_name, team_number, row, show_seed, top, winner, score_results, is_bye)
local showSeed = showSeeds
or isnotblank(seedArg)
or isnotblank(pairSeedArg)
if showSeed and (not hideSeeds) then
seedCell = row:tag('td')
:css('text-align', 'center')
:css('background-color', 'var(--background-color-neutral, #f2f2f2)')
:css('color', 'inherit')
:attr('rowspan', (not compact) and '2' or nil)
:wikitext(seedArg)
:newline()
addBorders(seedCell, top or otherbye, true, false)
end
 
local teamArg = getTeamArg(round, 'team', team)
self:addGap(row, self.current_col, self.current_width, 'rt')
if isblank(teamArg) then
self:addGap(row+1, self.current_col, self.current_width, 'rt')
teamArg = '&nbsp;'
-- seed cell
elseif boldwinner ~= '' then
local pos = (top and 1) or 2
teamArg = unboldParenthetical(teamArg)
local seedArg = self:getTeamArg(self.current_round, 'seed', team_number)
if show_seed and (not self.hideSeeds) then
local seedCell = self.rows[row]:tag('td'):attr('rowspan', '2'):cssText(style.seed_cell):wikitext(seedArg):newline()
if self.not_draw_top then seedCell:css('border-top-width', '0' ) end
if self.bold_winner and (winner == pos) then
seedCell:cssText(style.winner)
end
end
 
-- team cell
if not showSeed and (not hideSeeds) then
local teamCell = self.rows[row]:tag('td'):attr('rowspan', '2'):cssText(style.team_cell):wikitext(team_name):newline()
tcs = tcs + 1
--local teamCell = self.rows[row]:tag('td'):attr('rowspan', '2'):cssText(style.team_cell):wikitext(tostring(seedArg)):newline()
if not show_seed and (not self.hideSeeds) then
teamCell:attr('colspan', '2')
end
 
if self.not_draw_top then
local teamCell = row:csstag('border-top-widthtd', '0' )
:css('background-color', 'var(--background-color-neutral-subtle, #f9f9f9)')
:css('padding', '0 2px')
:css('color', 'inherit')
:attr('rowspan', (not compact) and '2' or nil)
:attr('colspan', (tcs > 1) and tcs or nil)
:wikitext(teamArg)
:newline()
addBorders(teamCell, top or otherbye, true, false)
 
local scoreCells = {}
local wins, otherwins = 0, 0
local sumscore, othersumscore = 0, 0
local teamcolspan = tcs
local hassum = false
for s = 1, legs[round] do
local fw = nil
local agg = legs[round] > 1 and s == legs[round] and true or false
local score1 = (agg and getScoreArg(round, team, 'agg') or nil) or
getScoreArg(round, team, s) or ((legs[round] == 1) and getScoreArg(round, team)) or nil
local score2 = (agg and getScoreArg(round, otherteam, 'agg') or nil) or
getScoreArg(round, otherteam, s) or ((legs[round] == 1) and getScoreArg(round, otherteam)) or nil
local showscore = true
if agg and aggregate ~= '' and score1 == nil and hassum then
score1 = (aggregate == 'score') and sumscore
or ((aggregate == 'legs' or aggregate == 'sets') and wins)
or nil
end
if agg and aggregate ~= '' and score2 == nil and hassum then
score2 = (aggregate == 'score') and othersumscore
or ((aggregate == 'legs' or aggregate == 'sets') and otherwins)
or nil
end
if (score1 == nil or score1 == '') and (score2 == nil or score2 == '') then
if hideomittedscores > 0 and s >= hideomittedscores then
teamcolspan = teamcolspan + 1
showscore = false
end
else
hassum = true
end
if showscore then
local winner = scoreCompare(score1, score2, boldwinner ~= 'low')
sumscore = sumScores(sumscore, score1)
othersumscore = sumScores(othersumscore, score2)
if winner == 1 then
if boldwinner ~= '' or (agg and (aggregate == 'score' or aggregate == 'legs' or aggregate == 'sets')) then
if agg and (aggregate == 'legs' or aggregate == 'sets') and (wins <= (legs[round] - 1)/2) then
else
fw = 'bold'
end
end
if not (agg and (aggregate == 'score' or aggregate == 'legs' or aggregate == 'sets')) then wins = wins + 1 end
elseif winner == 2 then
if not (agg and (aggregate == 'score' or aggregate == 'legs' or aggregate == 'sets')) then otherwins = otherwins + 1 end
end
scoreCells[s] = row:tag('td')
:css('text-align', 'center')
:css('background-color', getShadeArg(round, team, s))
:css('font-weight', fw)
:css('color', 'inherit')
:attr('rowspan', (not compact) and '2' or nil)
:wikitext(score1)
:newline()
addBorders(scoreCells[s], top or otherbye, false, s > 1 and s == legs[round] and aggsep or nil)
end
end
if self.bold_winnerteamcolspan and> winner == pos1 then
teamCell:cssTextattr(style.winner)'colspan', teamcolspan)
end
if self.current_roundboldwinner =~= self.rounds'' and winnerwins ~= 0 and> self.medalsotherwins then
if (aggregate == 'legs' or aggregate == 'sets') and (wins <= (legs[round] - 1)/2) then
if winner == pos then
else
if team_number < 3 then
if seedCell then
teamCell:cssText(style.first_place)
seedCell:css('font-weight', 'bold')
else
end
teamCell:cssText(style.third_place)
if teamCell then
teamCell:css('font-weight', 'bold')
end
elseif team_number < 3 then
teamCell:cssText(style.second_place)
end
end
-- scores cells
for i = 1, self.scores[self.current_round] do
local scoreCell = self.rows[row]
:tag('td')
:attr('rowspan', '2')
:cssText(style.score_cell)
:wikitext(self:getScoreArg(self.current_round, team_number, i))
:newline()
if self.not_draw_top then scoreCell:css('border-top-width', '0') end
if score_results[i] == pos then scoreCell:cssText(style.winner) end
end
self.not_draw_top = (self.current_round == 1) and (not self.not_draw_top)
end
 
local function TeamBracket:getScorerenderRound(round, team_numbercount, ir)
local scoreteams = stringmath.gsubpow(self:getScoreArg(round2, team_number,rounds i)- orr '', '%D',+ ''1)
local step = count / teams
return tonumber(score)
local topTeam = true -- is top row in match-up
end
local topPair = true -- is top match-up in pair of match-ups
local team = 1
local group = 1
 
for i = 1, count, step do
--[[ ===============================================================================
local offset, height, blank
Gestisce un match
-- match_number: il numero del match contando dall'alto (1, 2, 3, ...)
-- row_base: la prima riga della tabella in cui disegnare il batch
===============================================================================]]
 
local hideteam = false
function TeamBracket:renderMatch(match_number, row_base)
local otherhideteam = false
local hideleftpath = false
-- ottiene i nomi dei team del match, verifica che non siano bye e setta self.not_draw_top
local hiderightpath = false
-- per registrare se si deve disegnare o meno la riga superiore del match
if r <= byes then
-- ritorna i nomi dei team e se è un bye (true) o no (false)
hideteam = isHidden(r, team)
local function getTeams(team_number1, team_number2)
otherhideteam = isHidden(r, team % 2 == 0 and team-1 or team+1)
local team_name1 = self:getTeamArg(self.current_round, 'team', team_number1)
end
local team_name2 = self:getTeamArg(self.current_round, 'team', team_number2)
if team_name1(r == 'bye'1) orand team_name2(RD1seedmap[team] <== 'bye' or not (team_name1 and team_name20) then
self.not_draw_top hideteam = falsetrue
end
return '', '', true
if (r > 1) and (r <= (byes + 1)) then
hideleftpath = isHidden(r-1, 2*team-1) and isHidden(r-1, 2*team)
end
if (r == 2) and (RD1seedmap[2*team-1] <= 0 and RD1seedmap[2*team] <= 0) then
hideleftpath = true
end
if compactFinal and (r == rounds) then
hideleftpath = true
end
if (tonumber(args['RD' .. (r-1) .. '-RD' .. (r) .. '-path']) or 2) == 0 then
hideleftpath = true
end
if (tonumber(args['RD' .. (r) .. '-RD' .. (r + 1) .. '-path']) or 2) == 0 then
hiderightpath = true
end
return team_name1, team_name2, false
end
 
-- empty space above or below
local team_number2 = match_number * 2
if compact then
local team_number1 = team_number2 - 1
offset = topTeam and i or i + 1
local team_name1, team_name2, is_bye = getTeams(team_number1, team_number2)
height = step - 1
if is_bye then
-- leave room for groups for teams other than first and last
if self.render_match[self.current_round][match_number] then
elseif team == 1 or team == teams then
for r = row_base, row_base+3 do
offset = topTeam and i or i + 2
self:addGap(r, self.current_col, self.current_width, 'rm')
height = step - 2
end
else
local cell=self.rows[row_base]:tag('td')
offset = topTeam and i + 1 or i + 2
:attr('rowspan', '2')
height = step - 3
:attr('colspan', self.current_width)
:cssText(style.path_bottom)
if debug then cell:css('background-color', '#ADD8E6') end
cell = self.rows[row_base+2]:tag('td')
:attr('rowspan', '2')
:attr('colspan', self.current_width)
:cssText(style.path_top)
if debug then cell:css('background-color', '#ADD8E6') end
return row_base
end
if showThird and (r == rounds) and (not topTeam) then
return nil
height = offset - offsetThird
end
end
if row_base < self.min_row_used then self.min_row_used = row_base end
if compactFinal and (r == (maxround - 1)) then
if row_base + 3 > self.max_row_used then self.max_row_used = row_base + 3 end
if team == 2 then
local showSeed = false
height = height - 3
local winner, score_results = 0, {}
end
local seedArg1 = self:getTeamArg(self.current_round, 'seed', team_number1)
if team == 3 then
local seedArg2 = self:getTeamArg(self.current_round, 'seed', team_number2)
height = height - 1
local showSeed = self.showSeeds
offset = offset + 1
or (seedArg1 and seedArg1 ~= '-')
addBlank(offset-3, nil, 1, tonumber(hideSeeds and '2' or '3') + legs[r])
or (seedArg2 and seedArg2 ~= '-')
addBlank(offset-4)
if self.bold_winner then
addHeading(rows[offset-4], r + 1, getRoundName(r+1), legs[r] - legs[r+1])
winner, score_results = self:getWinner(team_number1)
local b = addBlank(offset-4, {
['border-color'] = 'var(--color-base, black)',
['border-style']= 'solid',
['border-width']= '0'}, 2)
b:css('border-right-width', '2px')
end
end
if height > 0 then
local pad = 0
local betweenTeams = (topTeam == false and topPair == true) or (topTeam == true and topPair == false)
if compactFinal and (r == maxround - 1) then
betweenTeams = false
end
if compactFinal and (r == maxround - 1) and legs[r+1] > legs[r] then
pad = legs[r+1] - legs[r]
end
if compact and betweenTeams then
addBlank(offset, nil, height, 1)
if topPair then
blank = addBlank(offset, nil, 2*height, tonumber(hideSeeds and '1' or '2') + legs[r] + pad)
if args['RD' .. r .. '-group' .. group] then
blank:wikitext(args['RD' .. r .. '-group' .. group])
blank:css('text-align', 'center')
end
group = group + 1
end
blank = addBlank(offset,
{['border-width'] = '0',
['border-style'] = 'solid',
['border-color'] = 'var(--color-base, black)'},
height, 1)
else
blank = addBlank(offset,
{['border-width'] = '0',
['border-style'] = 'solid',
['border-color'] = 'var(--color-base, black)'},
height, tonumber(hideSeeds and '3' or '4') + legs[r] + pad)
end
end
-- add bracket
local j = topTeam and i + step - (compact and 1 or 2) or i
-- add left path
addPath(j, r, topTeam, true, hideleftpath and '0' or '2px')
if hideteam then
addBlank(j, nil, (not compact) and 2 or nil, tonumber(hideSeeds and '1' or '2') + legs[r])
elseif rows[j] then
if compactFinal and (r == maxround) then
renderTeam(rows[j], r, team, topTeam, otherhideteam, legs[r-1] - legs[r])
elseif compactFinal and (r == maxround - 1) then
renderTeam(rows[j], r, team, topTeam, otherhideteam, legs[r+1] - legs[r])
else
renderTeam(rows[j], r, team, topTeam, otherhideteam)
end
end
local rightPath = addPath(j, r, topTeam, false, (hiderightpath or hideteam) and '0' or '2px')
if not topTeam then topPair = not topPair end
if not topPair and r < maxround and (not (hiderightpath or hideteam)) then
if blank then blank:css('border-right-width', '2px') end
rightPath:css('border-right-width', '2px')
end
if compactFinal and (r == maxround) then
local prop = (team == 1) and 'border-bottom-width' or 'border-top-width'
rightPath:css('border-right-width', '2px')
:css(prop, '2px')
end
team = team + 1
topTeam = not topTeam
end
self:renderTeam(team_name1, team_number1, row_base, showSeed, true, winner, score_results, is_bye)
self:renderTeam(team_name2, team_number2, row_base+2, showSeed, false, winner, score_results, is_bye)
return row_base
end
 
local function renderGroups(count, round)
--[[ ===============================================================================
local roundFromLast = rounds - round + 1
Disegna la finale per il terzo posto
local groups = math.pow(2, roundFromLast - 2)
--row: riga in cui iniziare a disegnare la finale
local step = count / groups
===============================================================================]]
local group = 1
local offset = 0
local team = 0
local wdef = (tonumber(args['RD' .. (round) .. '-RD' .. (round + 1) .. '-path']) or 2) .. 'px'
local w = wdef
 
for r = 1,round do
function TeamBracket:render_final_3(row)
offset = offset + (hideSeeds and 3 or 4) + legs[r]
local team_name1 = self:getTeamArg(self.rounds, 'team', 3)
local team_name2 = self:getTeamArg(self.rounds, 'team', 4)
if team_name1 == 'bye' or team_name2 == 'bye' then
return nil
end
for i = step / 2, count, step do
local seedArg1 = self:getTeamArg(self.rounds, 'seed', 3)
local seedArg2name = self:getTeamArg(self'RD' .. round ..rounds, 'seed-group', 4).. group
addBlank(i, {['height'] = '7px'})
local showSeed = self.showSeeds
addBlank(i+1, {['height'] = '7px'})
or (seedArg1 and seedArg1 == '-')
addBlank(i, {['text-align'] = 'center'}, 2, offset-2)
or (seedArg2 and seedArg2 == '-')
:wikitext(args[name])
local winner, score_results = 0, {}
:newline()
if self.bold_winner then
if (round <= byes) then
winner, score_results = self:getWinner(self.rounds, 3)
team = i/(step/2)
w = isHidden(round, 2*team-1) and isHidden(round, 2*team) and '0' or wdef
end
if (round < maxround) then
addBlank(i, {
['border-color'] = 'var(--color-base, black)',
['border-style'] = 'solid',
['border-width'] = '0 ' .. w .. ' 0 0'})
else
addBlank(i)
end
if (round <= byes) then
team = team + 1
w = isHidden(round, 2*team-1) and isHidden(round, 2*team) and '0' or wdef
end
if (round < maxround) then
addBlank(i+1, {
['border-color'] = 'var(--color-base, black)',
['border-style'] = 'solid',
['border-width'] = '0 ' .. w .. ' 0 0'})
else
addBlank(i+1)
end
group = group + 1
end
local seedArg1 = self:getTeamArg(self.rounds, 'seed', 3)
local seedArg2 = self:getTeamArg(self.rounds, 'seed', 4)
self:addGap(row, self.current_col, self.current_width, 'f3')
if row+4 > self.max_row_used then self.max_row_used = row + 4 end
self.rows[row]:tag('td')
:cssText(style.header_third_place)
:attr('colspan', self.current_width)
:wikitext("Finale 3° posto")
:newline()
self:renderTeam(team_name1, 3, row+2, showSeed, true, winner, score_results)
self:renderTeam(team_name2, 4, row+4, showSeed, false, winner, score_results)
end
 
local function TeamBracket:AddGroupgetThirdOffset(row, group_number)
local offset = (compact and 1 or 3) * (math.pow(2, rounds) - math.pow(2, rounds-3)) - (compact and 2 or 4)
local name = self.args[string.format('RD%d-group%d', self.current_round, group_number)]
if namerounds < 4 then
offset = compact and 8 or 17
local span = self.current_col + self.current_width - 2
if rounds < 3 then
self:addGap(row, self.current_col, self.current_col + span, 'g')
offset = compact and 6 or 10
self:addGap(row+1, self.current_col, self.current_col + span, 'g')
if rounds < 2 then
self.rows[row]:tag('td')
offset = compact and 4 or 7
:attr('rowspan', '2')
end
:attr('colspan', span)
end
:cssText(style.group)
:wikitext(name)
:newline()
end
return offset
end
 
local function TeamBracket:renderTreerenderThird(count)
local k = offsetThird
local function normal_gap(row_count, match_number)
local row = rows[k]
return (row_count + 2 - match_number * 4) / match_number
local blank
if rounds < 2 then
blank = addBlank(k-1, {['height'] = '7px'})
end
blank = addBlank(k, rounds < 2 and {['height'] = '7px'} or nil)
addHeading(row, rounds + 1, args['RD-finalina'] or 'Finale 3º posto')
if rounds < 2 then
for i = 1,(compact and 1 or 2) do
blank = addBlank(k+i, {['height'] = '7px'})
end
end
k = k + (compact and 2 or 3)
for i = 1,2 do
row = rows[k]
blank = addBlank(k, rounds < 2 and {['height'] = '7px'} or nil)
if row then
renderTeam(row, rounds + 1, i, i == 1, false)
end
if rounds < 2 and not compact then
blank = addBlank(k+1, {['height'] = '7px'})
end
k = k + (compact and 1 or 2)
end
end
 
local function compact_gapmaskRows(row_counttbl, match_numbercount, offsetcount)
local rmin = 1
return (row_count - 4 * match_number) / match_number
local rmax = count
for i = rmin, rmax do
mask[i] = false
end
if showThird then
for i = offsetThird,(offsetThird+ (compact and 3 or 5)) do
rmax = (i > rmax) and i or rmax
mask[i] = true
end
end
for r = 1, maxround do
local teams = math.pow(2, rounds - r + 1)
local step = count / teams
local topTeam = true -- is top row in match-up
local team = 1
 
for i = 1, count, step do
-- create 3 or 1 rows for every team
local offset, height, blank
local row_count = self.teams * 2 + (self.compact and 0 or (self.teams - 2))
local hideteam = false
self.min_row_used = row_count
if r <= byes then
self.max_row_used = 1
hideteam = isHidden(r, team)
local gap_function = (self.compact and compact_gap) or normal_gap
end
for i = 1, row_count do
if (r == 1) and (RD1seedmap[team] <= 0) then
self.rows[i] = mw.html.create('tr')
hideteam = true
self.rows[i]:tag('td'):css('height', style.row_height):wikitext(debug and i or '')
end
self.last_element[i] = 1
if not hideteam then
local j = topTeam and i + step - (compact and 1 or 2) or i
mask[j] = true
end
team = team + 1
topTeam = not topTeam
end
end
 
self.current_col = 2
for r = 1, maxround do
self.render_match = {}
local roundFromLast = rounds - r + 1
self.render_match[1] = {}
local groups = math.pow(2, roundFromLast - 2)
for round =1, self.rounds do
local step = count / groups
self.current_round = round
local group = 1
self.render_match[round+1] = {}
for i = step / 2, count, step do
self.current_width = (self.hideSeeds and 1 or 2) + self.scores[round]
if args['RD' .. r .. '-group' .. group] then
local match_number = math.pow(2, self.rounds - round)
mask[i] = true
local gap = gap_function(row_count, match_number)
mask[i+1] = true
local row_base = gap / 2 + (self.compact and 1 or 0)
local group_number = 1
for n = 1, match_number, 2 do
local match1 = self:renderMatch(n, row_base)
if round < self.rounds then
local match2 = self:renderMatch(n+1, row_base + gap + 4)
if not self.compact and round % 4 == 1 then
self:AddGroup(row_base+4, group_number)
group_number = group_number + 1
end
self:addPath(match1, match2, gap, (n+1)/2)
row_base = row_base + 2 * gap + 8
end
group = group + 1
end
self.current_col = self.current_col + self.current_width + 2
end
local mmin, mmax = rmax, rmin
local third_place = self:getTeamArg(self.rounds, 'team', 3)
for i = rmin, rmax do
--if true then return third_place end
if mask[i] == true then
if third_place then -- semifinale 3° e 4° posto
mmin = (i < mmin) and i or mmin
self.current_col = self.current_col - self.current_width - 2
local offset mmax = gap_function(row_count,i 1> mmax) / 2 + (self.compact and 1i or 0) + 6mmax
end
if offset+5 > row_count then
end
for i=row_count+1, offset+5 do
for i = mmin, mmax do
self.rows[i] = mw.html.create('tr')
rows[i] = addTableRow(tbl)
self.rows[i]:tag('td'):css('height', style.row_height):wikitext(debug and i or '')
end
self.last_element[i] = 1
end
 
local function renderTree(tbl)
-- create 3 or 1 rows for every team
local count = math.pow(2, rounds) * (compact and 1 or 3)
local offsetcount = 2 * (compact and 1 or 3) + (compact and 2 or 3)
offsetThird = getThirdOffset()
maskRows(tbl, count, offsetcount)
if showThird then
for i = (count+1), (offsetcount + offsetThird) do
if (rounds > 1) then
local blank = addBlank(i, nil, 1, tonumber(hideSeeds and '3' or '4') + legs[1])
if compact and (rounds > 2) then
blank = addBlank(i, nil, 1, tonumber(hideSeeds and '3' or '4') + legs[2])
end
end
end
end
self:render_final_3(offset)
if not compact then
end
-- fill rows with groups
for row = self.min_row_used, self.max_row_used do
for r = 1, rounds - 1 do
self.tbl:node(self.rows[row])
renderGroups(count, r)
end
end
-- fill rows with bracket
for r = 1, maxround do
renderRound(count, r)
end
if showThird then
renderThird(count, compact)
end
end
 
local function renderHeadings(tbl)
--[[ ===============================================================================
local titleRow = addTableRow((not hideHeadings) and tbl or mw.html.create('table'))
Disegna le righe di testata del template
local widthRow = addTableRow(tbl)
===============================================================================]]
for r = 1, (compactFinal and (maxround-1) or maxround) do
function TeamBracket:renderHeading()
local titleRow = self.tbl:tag('trtd')
local widthRow = self.tbl:tag('trtd'):css('width', r > 1 and '5px' or '1px')
if compactFinal and r == (maxround-1) then
local blank_text = self.compact and '' or '&nbsp;'
addHeading(titleRow, r, getRoundName(r), legs[r+1] - legs[r])
titleRow:tag('td')
else
local row_count = 1
addHeading(titleRow, r, getRoundName(r) )
widthRow:tag('td')
:css('width', style.buffer_sx_width)
:css('height', '5px')
:wikitext(debug and row_count or '')
row_count = row_count + 1
for round = 1, self.rounds do
local colspan = tostring((self.hideSeeds and 1 or 2) + self.scores[round])
local teamCell = titleRow:tag('td')
:cssText(style.header_cell)
:attr('colspan', colspan)
:wikitext(self:getRoundName(round))
:newline()
if not self.hideSeeds then
widthRow:tag('td'):css('width', style.seed_width):wikitext(debug and row_count or blank_text)
row_count = row_count + 1
end
local seedCell
teamCell = widthRow:tag('td'):css('width', style.team_width):wikitext(debug and row_count or blank_text)
if (not hideSeeds) then
row_count = row_count + 1
seedCell = widthRow:tag('td'):css('width', getWidth('seed', '28px'))
for i = 1, self.scores[round] do
widthRow:tag('td'):css('width', style.score_width):wikitext(debug and row_count or blank_text)
row_count = row_count + 1
end
local teamCell = widthRow:tag('td'):css('width', getWidth('team', '190px'))
if round < self.rounds then
local scoreCells = {}
titleRow:tag('td'):attr('colspan', '2')
local legsr = legs[r]
widthRow:tag('td'):css('width', style.row_width):wikitext(debug and row_count or blank_text)
if compactFinal and r == (maxround-1) then
row_count = row_count + 1
legsr = legs[r+1] > legs[r] and legs[r+1] or legs[r]
widthRow:tag('td'):css('width', style.row_width):wikitext(debug and row_count or blank_text)
end
row_count = row_count + 1
if showThird and r==maxround then
legsr = legs[r+1] > legs[r] and legs[r+1] or legs[r]
end
for s = 1, legsr do
local score_width = '30px'
if aggregate and aggregate ~= '' and s > 1 and s == legsr then
score_width = getWidth('agg', getWidth('score', score_width))
else
score_width = getWidth('score', score_width)
end
scoreCells[s] = widthRow:tag('td'):css('width', score_width)
end
titleRow:tag('td')
widthRow:tag('td'):css('width', r < rounds and '5px' or '1px')
 
if compact then
teamCell:css('height', '7px')
else
if seedCell then
seedCell:wikitext('&nbsp;')
end
teamCell:wikitext('&nbsp;')
for s = 1, legs[r] do
scoreCells[s]:wikitext('&nbsp;')
end
end
end
end
 
function p.main(frame)
-- =================================================================
parseArgs(frame)
-- Funzione di interfaccia con i template
rounds = tonumber(args.rounds) or 2
-- =================================================================
maxround = tonumber(args.maxround) or rounds
local teams = math.pow(2, rounds)
compact = (args['compact'] and (args['compact'] == 'yes' or args['compact'] == 'y'))
compactFinal = ((rounds > 4) and compact and args['compact-final'] and (args['compact-final'] == 'yes' or args['compact-final'] == 'y'))
sepwidth = tonumber(args['sepwidth'] or ((args.sets or args.legs) and 1) or (compact and 1) or 2) or 1
aggregate = (args['aggregate'] or ''):lower()
aggsep = args['aggsep'] or args['aggregate'] or nil
boldwinner = args['boldwinner'] or args['bold_winner'] or ''
local autoSeeds = (args['autoseeds'] and (args['autoseeds'] == 'yes' or args['autoseeds'] == 'y'))
hideSeeds = (args['seeds'] and (args['seeds'] == 'no' or args['seeds'] == 'n'))
showSeeds = (args['seeds'] and (args['seeds'] == 'yes' or args['seeds'] == 'y'))
byes = (args['byes'] and (args['byes'] == 'yes' or args['byes'] == 'y') and 1) or (tonumber(args['byes'] or '0') or 0)
hideomittedscores = (args['hideomittedscores'] and (args['hideomittedscores'] == 'yes' or args['hideomittedscores'] == 'y') and 1) or (tonumber(args['hideomittedscores'] or '0') or 0)
hideHeadings = (args['headings'] and (args['headings'] == 'no' or args['headings'] == 'n'))
showThird = isnotblank(args['3rd']) or isnotblank(args['3rd-team1']) or isnotblank(args['3rd-team2'])
local align = (args['float'] or args['align'] or ''):lower()
local clear = args['clear'] or 'none'
parseSeedmap(args['RD1-omit'])
parseLegs(args.sets or args.legs)
 
if autoSeeds then
function p.teamBracket(frame)
-- set default seeds for round 1
local args = getArgs(frame, {
local seeds = getSeeds()
-- se l'argomento è un seed lo ritorna così com'è anche se blank, tutti gli altri argomenti sono puliti
for i = 1, table.getn(seeds) do
valueFunc = function (key, value)
local argname = getTeamArgName(1, 'seed', i)
if not value then return nil end
if key:find("^RD%d%d?-seed")not args[argname] then return value end
args[argname] = seeds[i]
value = mw.text.trim(value)
end
if value == '' then return nil end
return value
end
}
)
if args['debug'] then
debug = in_array(args['debug'], yes_replies) or debug
end
 
local team_bracket = TeamBracket:new(args)
-- create the table
return tostring(team_bracket)
local tbl = mw.html.create('table')
:css('border-style', 'none')
:css('font-size', '90%')
:css('border-collapse', 'separate')
:css('border-spacing', '0')
:attr('cellpadding', '0')
 
if (args['nowrap'] and (args['nowrap'] == 'yes' or args['nowrap'] == 'y')) then
tbl:css('white-space', 'nowrap')
end
 
if align == 'right' then
tbl:css('float', 'right')
if clear ~= 'none' and clear ~= 'no' and clear ~= 'n' then
tbl:css('clear', 'right')
end
tbl:css('margin', '1em 0 1em 2em')
elseif align == 'left' then
tbl:css('float', 'left')
if clear ~= 'none' and clear ~= 'no' and clear ~= 'n' then
tbl:css('clear', 'left')
end
tbl:css('margin', '1em 2em 1em 0')
elseif align == 'center' or align == 'centre' then
tbl:css('margin', '1em auto')
else
tbl:css('margin', '1em 2em 1em 1em')
end
 
renderHeadings(tbl)
renderTree(tbl)
if (args['wide'] and (args['wide'] == 'y' or args['wide'] == 'yes')) then
return '<div class="noresize" style="overflow:auto">' .. tostring(tbl) .. '</div>' .. tcats
end
return tostring(tbl) .. tcats
end
 
function p.teamBracket(frame)
return p.main(frame)
end