https://de.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3ATeam_bracket
Modul:Team bracket - Versionsgeschichte
2025-06-09T13:02:19Z
Versionsgeschichte dieser Seite in Wikipedia
MediaWiki 1.45.0-wmf.4
https://de.wikipedia.org/w/index.php?title=Modul:Team_bracket&diff=250962179&oldid=prev
Antonsusi: Neu von en:WP.
2024-12-04T20:47:23Z
<p>Neu von en:WP.</p>
<p><b>Neue Seite</b></p><div>--<br />
-- This module implements many bracket templates<br />
--<br />
<br />
local p = {}<br />
local args = {}<br />
local rows = {}<br />
local mask = {}<br />
local rounds<br />
local maxround<br />
local legs = {}<br />
local compact<br />
local byes<br />
local hideSeeds<br />
local showSeeds<br />
local hideHeadings<br />
local showThird<br />
local offsetThird<br />
local compactFinal<br />
local sepwidth<br />
local aggsep<br />
local aggregate<br />
local boldwinner<br />
local hideomittedscores<br />
local RD1seedmap = {}<br />
local tcats = ''<br />
<br />
local function isnotblank(s)<br />
return s and s ~= ''<br />
end<br />
<br />
local function isblank(s)<br />
return (not s) or (s == '')<br />
end<br />
<br />
local function sumScores(s1, s2)<br />
s1 = mw.ustring.gsub(s1 or '', '^[\'%s]*([%d%.]*).-$', '%1')<br />
s2 = mw.ustring.gsub(s2 or '', '^[\'%s]*([%d%.]*).-$', '%1')<br />
if s1 ~= '' and s2 ~= '' then<br />
return tonumber(s1) + tonumber(s2)<br />
end<br />
return s1<br />
end<br />
<br />
local function scoreCompare(s1,s2,highwin)<br />
local ps1 = mw.ustring.gsub(s1 or '', '^[\'%s]*([%d%.]*)[\'%s]*%([\'%s]*([%d%.]*)[\'%s]*%).-$', '%2')<br />
local ps2 = mw.ustring.gsub(s2 or '', '^[\'%s]*([%d%.]*)[\'%s]*%([\'%s]*([%d%.]*)[\'%s]*%).-$', '%2')<br />
s1 = mw.ustring.gsub(s1 or '', '^[\'%s]*([%d%.]*).-$', '%1')<br />
s2 = mw.ustring.gsub(s2 or '', '^[\'%s]*([%d%.]*).-$', '%1')<br />
<br />
if s1 ~= '' and s2 ~= '' then<br />
s1 = tonumber(s1)<br />
s2 = tonumber(s2)<br />
if s1 and s2 then<br />
if (s1 == s2) then<br />
ps1 = tonumber(ps1)<br />
ps2 = tonumber(ps2)<br />
if ps1 and ps2 then<br />
s1 = ps1<br />
s2 = ps2<br />
end<br />
end<br />
if highwin then<br />
return ((s1 > s2) and 1) or ((s1 < s2) and 2) or 0<br />
else<br />
return ((s2 > s1) and 1) or ((s2 < s1) and 2) or 0<br />
end<br />
end<br />
end<br />
return 0<br />
end<br />
<br />
local function unboldParenthetical(s)<br />
if s then<br />
s = mw.ustring.gsub(s, '(%(%[%[[^%[%]]*%]%]%))', '<span style="font-weight:normal">%1</span>')<br />
end<br />
return s<br />
end<br />
<br />
local function parseArgs(frame)<br />
local fargs = frame.args<br />
local pargs = frame:getParent().args;<br />
<br />
local r = tonumber(fargs.rounds or '') or tonumber(pargs.rounds or '') or 2<br />
local teams = math.pow(2, r)<br />
local rdstr = 'RD' .. tostring(r)<br />
local rdbstr = 'RD' .. tostring(r) .. 'b'<br />
local rdp1str = 'RD' .. tostring(r+1)<br />
<br />
for i=1,2 do<br />
local targs = (i == 1) and pargs or fargs<br />
for k,v in pairs(targs) do<br />
if type(k) == 'string' then<br />
if k:find('^[R3][Dr][d1-9]b?%-[a-z]+00*') then<br />
k = mw.ustring.gsub(k, '^([R3][Dr][d1-9]b?%-[a-z]+)00*', '%1')<br />
if (teams < 10) then <br />
tcats = tcats .. '[[Category:Pages using a team bracket with deprecated syntax|P]]'<br />
end<br />
end<br />
if k:find('^' .. rdp1str) then<br />
k = mw.ustring.gsub(k, '^' .. rdp1str, '3rd')<br />
tcats = tcats .. '[[Category:Pages using a team bracket with deprecated syntax|3]]'<br />
elseif k:find('^' .. rdbstr) then<br />
k = mw.ustring.gsub(k, '^' .. rdbstr, '3rd')<br />
elseif k:find('^' .. rdstr .. '%-[a-z]+3') then<br />
k = mw.ustring.gsub(k, '^' .. rdstr .. '(%-[a-z]+)3', '3rd%11')<br />
elseif k:find('^' .. rdstr .. '%-[a-z]+4') then<br />
k = mw.ustring.gsub(k, '^' .. rdstr .. '(%-[a-z]+)4', '3rd%12')<br />
elseif k:find('^Consol') then<br />
k = mw.ustring.gsub(k, '^Consol', '3rd')<br />
tcats = tcats .. '[[Category:Pages using a team bracket with deprecated syntax|3]]'<br />
elseif k:find('^group[0-9]') then<br />
tcats = tcats .. '[[Category:Pages using a team bracket with deprecated syntax|G]]'<br />
end<br />
end<br />
args[k] = v<br />
end<br />
end<br />
<br />
if (args['byes'] and (args['byes'] == 'yes' or args['byes'] == 'y')) then<br />
tcats = tcats .. '[[Category:Pages using a team bracket with deprecated syntax|B]]'<br />
end<br />
end<br />
<br />
local function parseSeedmap(s)<br />
s = mw.text.split((s or '0') .. '/', '[%s]*/[%s]*')<br />
local teams = math.pow(2, rounds)<br />
for r=1,teams do<br />
RD1seedmap[r] = 1<br />
end<br />
for r=1,#s do<br />
if tonumber(s[r] or 'x') then<br />
RD1seedmap[tonumber(s[r])] = 0<br />
end<br />
end<br />
local c = 1<br />
for r=1,teams do<br />
if RD1seedmap[r] > 0 then<br />
RD1seedmap[r] = c<br />
c = c + 1<br />
end<br />
end<br />
end<br />
<br />
local function parseLegs(s)<br />
s = mw.text.split((s or '1') .. '/', '[%s]*/[%s]*')<br />
if aggregate == 'n' or aggregate == 'no' or aggregate == '0' then<br />
aggregate = ''<br />
end<br />
local n = showThird and (rounds + 1) or (rounds)<br />
local lastlegs = nil<br />
for r=1,n do<br />
if tonumber(s[r]) then<br />
legs[r] = tonumber(s[r])<br />
elseif lastlegs then<br />
legs[r] = lastlegs<br />
else<br />
legs[r] = 1<br />
end<br />
lastlegs = legs[r]<br />
if legs[r] > 1 and aggregate ~= '' then<br />
legs[r] = legs[r] + 1<br />
end<br />
end<br />
end<br />
<br />
local function getSeeds()<br />
local seeds = {1, 2}<br />
local count = 2<br />
local before = false<br />
for r = 2, rounds do<br />
local max = math.pow(2, r)<br />
for i = 1, count do<br />
local pos = i * 2<br />
if before then pos = pos - 1 end<br />
table.insert(seeds, pos, max - seeds[i * 2 - 1] + 1)<br />
before = not before<br />
end<br />
count = count * 2<br />
end<br />
return seeds<br />
end<br />
<br />
local function addTableRow(tbl)<br />
return tbl:tag('tr')<br />
end<br />
<br />
local function addBlank(i, css, rowspan, colspan)<br />
local row = rows[i]<br />
rowspan = rowspan or 1<br />
local jmax = i + rowspan - 1<br />
for j = i, jmax do<br />
if rows[j] == nil then<br />
rowspan = rowspan - 1<br />
elseif row == nil then<br />
row = rows[j]<br />
end<br />
end<br />
local cell = row and row:tag('td') or mw.html.create('td')<br />
if rowspan and rowspan > 1 then<br />
cell:attr('rowspan', rowspan)<br />
end<br />
if colspan and colspan > 1 then<br />
cell:attr('colspan', colspan)<br />
end<br />
if css then<br />
cell:css(css)<br />
end<br />
return cell<br />
end<br />
<br />
local function addBorders(cell, topcell, seedorteam, extrasep)<br />
if sepwidth > 1 then topcell = true end<br />
if seedorteam then<br />
cell:css('border', '1px solid var(--border-color-base,#a2a9b1)')<br />
:css('border-top-width', topcell and '1px' or '0')<br />
else<br />
cell:css('border-color', 'var(--border-color-base,#a2a9b1)')<br />
:css('border-style', 'solid')<br />
:css('border-top-width', topcell and '1px' or '0')<br />
:css('border-left-width', (extrasep and '1px') or ((sepwidth > 1) and '1px') or '0')<br />
:css('border-right-width', '1px')<br />
:css('border-bottom-width', '1px')<br />
end<br />
end<br />
<br />
local function addHeading(row, r, text, pad)<br />
pad = (pad == nil or pad < 0) and 0 or pad<br />
local cell = row:tag('td')<br />
:attr('colspan', tonumber(hideSeeds and '1' or '2') + legs[r] + pad)<br />
:css('text-align', 'center')<br />
:css('border', '1px solid var(--border-color-base,#a2a9b1)')<br />
:css('color', 'var(--color-base,#202122)')<br />
:css('overflow', 'inherit') -- Added due to strange interactions with dark mode and Vector 2022.<br />
:css('background-color', args['RD-shade'] or 'var(--background-color-neutral,#eaecf0)')<br />
:wikitext(text)<br />
:newline()<br />
<br />
if args['RD-shade'] then<br />
cell:css('color', '#202122') -- Makes text dark if there's a custom colour underneath it<br />
end<br />
end<br />
<br />
local function getWidth(param, default)<br />
local arg = args[param .. '-width']<br />
if isblank(arg) then<br />
arg = default<br />
end<br />
if tonumber(arg) then<br />
arg = arg .. 'px'<br />
end<br />
return arg<br />
end<br />
<br />
local function getTeamArgName(round, type, team)<br />
if round > rounds then<br />
return string.format('3rd-%s%d', type, team)<br />
else<br />
if (round == 1) then<br />
team = RD1seedmap[team]<br />
if team == 0 then<br />
return 'NIL'<br />
end<br />
end<br />
return string.format('RD%d-%s%d', round, type, team)<br />
end<br />
end<br />
<br />
local function getShadeArg(round, team, s)<br />
local argname = getTeamArgName(round, 'shade', team) .. (s and ('-' .. s) or '')<br />
local value = args[argname]<br />
if isblank(value) then<br />
return nil<br />
end<br />
return value<br />
end<br />
<br />
local function getScoreArg(round, team, s)<br />
local argname = getTeamArgName(round, 'score', team) .. (s and ('-' .. s) or '')<br />
local value = args[argname]<br />
return value<br />
end<br />
<br />
local function getTeamArg(round, type, team)<br />
local argname = getTeamArgName(round, type, team)<br />
local value = args[argname]<br />
if isblank(value) then<br />
return ''<br />
end<br />
if mw.ustring.find(value, '[%s]*<[%s/]*[Bb][Rr][%s/]*>[%s ]*&[Nn][Bb][Ss][Pp];[%s]*') then<br />
tcats = tcats .. '[[Category:Pages using a team bracket with nbsp]]'<br />
end<br />
return mw.ustring.gsub(value, '[%s]*<[%s/]*[Bb][Rr][%s/]*>[%s ]*&[Nn][Bb][Ss][Pp];[%s]*', '<br/>')<br />
end<br />
<br />
local function isHidden(r, team)<br />
return isblank( getTeamArg(r, 'team', team) )<br />
end<br />
<br />
local function getRoundName(round)<br />
local name = args['RD' .. round]<br />
if isnotblank(name) then<br />
return name<br />
end<br />
local roundFromLast = rounds - round + 1<br />
if roundFromLast == 1 then<br />
return "Finals"<br />
elseif roundFromLast == 2 then<br />
return "Semifinals"<br />
elseif roundFromLast == 3 then<br />
return "Quarterfinals"<br />
else<br />
return "Round of " .. math.pow(2, roundFromLast)<br />
end<br />
end<br />
<br />
local function addPath(index, round, top, left, w)<br />
local prop = top and 'border-bottom-width' or 'border-top-width'<br />
if left and round == 1 then<br />
if compact then<br />
addBlank(index)<br />
else<br />
addBlank(index, {['height'] = '7px'})<br />
addBlank(index+1, {['height'] = '7px'})<br />
end<br />
return nil<br />
else<br />
local cell = addBlank(index, <br />
{['border-width'] = '0',<br />
['border-style'] = 'solid',<br />
['border-color'] = 'inherit'}, (not compact) and 2 or 1)<br />
if left or round < maxround and not left then<br />
cell:css(prop, w or '2px')<br />
end<br />
return cell<br />
end<br />
end<br />
<br />
local function renderTeam(row, round, team, top, otherbye, pad)<br />
pad = (pad == nil or pad < 0) and 0 or pad<br />
local tcs = pad + 1<br />
local seedCell<br />
local shade = getShadeArg(round, team) or 'var(--background-color-neutral-subtle,#f8f9fa)'<br />
local shadeseed = getShadeArg(round, team, 'seed') or getShadeArg(round, team) or 'var(--background-color-neutral,#eaecf0)'<br />
local seedArg = getTeamArg(round, 'seed', team)<br />
-- seed value for the paired team<br />
local otherteam = team % 2 == 0 and team-1 or team+1<br />
local pairSeedArg = otherbye and '' <br />
or getTeamArg(round, 'seed', otherteam)<br />
-- show seed if seed is defined for either or both<br />
local showSeed = showSeeds<br />
or isnotblank(seedArg)<br />
or isnotblank(pairSeedArg)<br />
if showSeed and (not hideSeeds) then<br />
seedCell = row:tag('td')<br />
:css('text-align', 'center')<br />
:css('color', 'var(--color-base,#202122)')<br />
:css('overflow', 'inherit') -- Added due to strange interactions with dark mode and Vector 2022.<br />
:css('background-color', shadeseed)<br />
:attr('rowspan', (not compact) and '2' or nil)<br />
:wikitext(seedArg)<br />
:newline()<br />
<br />
if (shadeseed ~= 'var(--background-color-neutral,#eaecf0)') then<br />
seedCell:css('color', '#202122') -- Makes text dark if there's a custom colour underneath it<br />
end<br />
addBorders(seedCell, top or otherbye, true, false)<br />
end<br />
<br />
local teamArg = getTeamArg(round, 'team', team)<br />
if isblank(teamArg) then<br />
teamArg = '&nbsp;'<br />
elseif boldwinner ~= '' then<br />
teamArg = unboldParenthetical(teamArg)<br />
end<br />
<br />
if not showSeed and (not hideSeeds) then<br />
tcs = tcs + 1<br />
end<br />
<br />
local teamCell = row:tag('td')<br />
:css('color', 'var(--color-base,#202122)')<br />
:css('overflow', 'inherit') -- Added due to strange interactions with dark mode and Vector 2022.<br />
:css('background-color', shade)<br />
:css('padding', '0 2px')<br />
:attr('rowspan', (not compact) and '2' or nil)<br />
:attr('colspan', (tcs > 1) and tcs or nil)<br />
:wikitext(teamArg)<br />
:newline()<br />
<br />
if (shade ~= 'var(--background-color-neutral-subtle,#f8f9fa)') then<br />
teamCell:css('color', '#202122') -- Makes text dark if there's a custom colour underneath it<br />
end<br />
addBorders(teamCell, top or otherbye, true, false)<br />
<br />
local scoreCells = {}<br />
local wins, otherwins = 0, 0<br />
local sumscore, othersumscore = 0, 0<br />
local teamcolspan = tcs<br />
local hassum = false<br />
for s = 1, legs[round] do<br />
local fw = nil<br />
local agg = legs[round] > 1 and s == legs[round] and true or false<br />
local score1 = (agg and getScoreArg(round, team, 'agg') or nil) or <br />
getScoreArg(round, team, s) or ((legs[round] == 1) and getScoreArg(round, team)) or nil<br />
local score2 = (agg and getScoreArg(round, otherteam, 'agg') or nil) or <br />
getScoreArg(round, otherteam, s) or ((legs[round] == 1) and getScoreArg(round, otherteam)) or nil<br />
local showscore = true<br />
if agg and aggregate ~= '' and score1 == nil and hassum then<br />
score1 = (aggregate == 'score') and sumscore <br />
or ((aggregate == 'legs' or aggregate == 'sets') and wins)<br />
or nil<br />
end<br />
if agg and aggregate ~= '' and score2 == nil and hassum then<br />
score2 = (aggregate == 'score') and othersumscore<br />
or ((aggregate == 'legs' or aggregate == 'sets') and otherwins)<br />
or nil<br />
end<br />
if (score1 == nil or score1 == '') and (score2 == nil or score2 == '') then<br />
if hideomittedscores > 0 and s >= hideomittedscores then<br />
teamcolspan = teamcolspan + 1<br />
showscore = false<br />
end<br />
else<br />
hassum = true<br />
end<br />
if showscore then<br />
local winner = scoreCompare(score1, score2, boldwinner ~= 'low')<br />
sumscore = sumScores(sumscore, score1)<br />
othersumscore = sumScores(othersumscore, score2)<br />
if winner == 1 then<br />
if boldwinner ~= '' or (agg and (aggregate == 'score' or aggregate == 'legs' or aggregate == 'sets')) then <br />
if agg and (aggregate == 'legs' or aggregate == 'sets') and (wins <= (legs[round] - 1)/2) then<br />
else<br />
fw = 'bold'<br />
end<br />
end<br />
if not (agg and (aggregate == 'score' or aggregate == 'legs' or aggregate == 'sets')) then wins = wins + 1 end<br />
elseif winner == 2 then<br />
if not (agg and (aggregate == 'score' or aggregate == 'legs' or aggregate == 'sets')) then otherwins = otherwins + 1 end<br />
end<br />
<br />
local shadearg = getShadeArg(round, team, s) or shade<br />
scoreCells[s] = row:tag('td')<br />
:css('text-align', 'center')<br />
:css('color', 'var(--color-base,#202122)')<br />
:css('overflow', 'inherit') -- Added due to strange interactions with dark mode and Vector 2022.<br />
:css('background-color', shadearg)<br />
:css('font-weight', fw)<br />
:attr('rowspan', (not compact) and '2' or nil)<br />
:wikitext(score1)<br />
:newline()<br />
<br />
if (shadearg ~= 'var(--background-color-neutral-subtle,#f8f9fa)') then<br />
scoreCells[s]:css('color', '#202122') -- Makes text dark if there's a custom colour underneath it<br />
end<br />
<br />
addBorders(scoreCells[s], top or otherbye, false, s > 1 and s == legs[round] and aggsep or nil)<br />
end<br />
end<br />
if teamcolspan > 1 then<br />
teamCell:attr('colspan', teamcolspan)<br />
end<br />
if boldwinner ~= '' and wins > otherwins then<br />
if (aggregate == 'legs' or aggregate == 'sets') and (wins <= (legs[round] - 1)/2) then<br />
else<br />
if seedCell then<br />
seedCell:css('font-weight', 'bold')<br />
end<br />
if teamCell then<br />
teamCell:css('font-weight', 'bold')<br />
end<br />
end<br />
end<br />
end<br />
<br />
local function renderRound(count, r)<br />
local teams = math.pow(2, rounds - r + 1)<br />
local step = count / teams<br />
local topTeam = true -- is top row in match-up<br />
local topPair = true -- is top match-up in pair of match-ups<br />
local team = 1<br />
local group = 1<br />
<br />
for i = 1, count, step do<br />
local offset, height, blank<br />
<br />
local hideteam = false<br />
local otherhideteam = false<br />
local hideleftpath = false<br />
local hiderightpath = false<br />
if r <= byes then<br />
hideteam = isHidden(r, team)<br />
otherhideteam = isHidden(r, team % 2 == 0 and team-1 or team+1)<br />
end<br />
if (r == 1) and (RD1seedmap[team] <= 0) then<br />
hideteam = true<br />
end<br />
if (r > 1) and (r <= (byes + 1)) then<br />
hideleftpath = isHidden(r-1, 2*team-1) and isHidden(r-1, 2*team)<br />
end<br />
if (r == 2) and (RD1seedmap[2*team-1] <= 0 and RD1seedmap[2*team] <= 0) then<br />
hideleftpath = true<br />
end<br />
if compactFinal and (r == rounds) then<br />
hideleftpath = true<br />
end<br />
if (tonumber(args['RD' .. (r-1) .. '-RD' .. (r) .. '-path']) or 2) == 0 then<br />
hideleftpath = true<br />
end<br />
if (tonumber(args['RD' .. (r) .. '-RD' .. (r + 1) .. '-path']) or 2) == 0 then<br />
hiderightpath = true<br />
end<br />
<br />
-- empty space above or below<br />
if compact then<br />
offset = topTeam and i or i + 1<br />
height = step - 1<br />
-- leave room for groups for teams other than first and last<br />
elseif team == 1 or team == teams then<br />
offset = topTeam and i or i + 2<br />
height = step - 2<br />
else<br />
offset = topTeam and i + 1 or i + 2<br />
height = step - 3<br />
end<br />
if showThird and (r == rounds) and (not topTeam) then<br />
height = offset - offsetThird<br />
end<br />
if compactFinal and (r == (maxround - 1)) then<br />
if team == 2 then<br />
height = height - 3<br />
end<br />
if team == 3 then<br />
height = height - 1<br />
offset = offset + 1<br />
addBlank(offset-3, nil, 1, tonumber(hideSeeds and '2' or '3') + legs[r])<br />
addBlank(offset-4)<br />
addHeading(rows[offset-4], r + 1, getRoundName(r+1), legs[r] - legs[r+1])<br />
local b = addBlank(offset-4, {<br />
['border-color'] = 'inherit',<br />
['border-style']= 'solid',<br />
['border-width']= '0'}, 2)<br />
b:css('border-right-width', '2px')<br />
end<br />
end<br />
if height > 0 then<br />
local pad = 0<br />
local betweenTeams = (topTeam == false and topPair == true) or (topTeam == true and topPair == false)<br />
if compactFinal and (r == maxround - 1) then<br />
betweenTeams = false<br />
end<br />
if compactFinal and (r == maxround - 1) and legs[r+1] > legs[r] then<br />
pad = legs[r+1] - legs[r]<br />
end<br />
if compact and betweenTeams then<br />
addBlank(offset, nil, height, 1)<br />
if topPair then<br />
blank = addBlank(offset, nil, 2*height, tonumber(hideSeeds and '1' or '2') + legs[r] + pad)<br />
if args['RD' .. r .. '-group' .. group] then<br />
blank:wikitext(args['RD' .. r .. '-group' .. group])<br />
blank:css('text-align', 'center')<br />
end<br />
group = group + 1<br />
end<br />
blank = addBlank(offset, <br />
{['border-width'] = '0',<br />
['border-style'] = 'solid',<br />
['border-color'] = 'inherit'},<br />
height, 1)<br />
else<br />
blank = addBlank(offset, <br />
{['border-width'] = '0',<br />
['border-style'] = 'solid',<br />
['border-color'] = 'inherit'},<br />
height, tonumber(hideSeeds and '3' or '4') + legs[r] + pad)<br />
end<br />
end<br />
-- add bracket<br />
local j = topTeam and i + step - (compact and 1 or 2) or i<br />
-- add left path<br />
addPath(j, r, topTeam, true, hideleftpath and '0' or '2px')<br />
if hideteam then<br />
addBlank(j, nil, (not compact) and 2 or nil, tonumber(hideSeeds and '1' or '2') + legs[r])<br />
elseif rows[j] then<br />
if compactFinal and (r == maxround) then<br />
renderTeam(rows[j], r, team, topTeam, otherhideteam, legs[r-1] - legs[r])<br />
elseif compactFinal and (r == maxround - 1) then<br />
renderTeam(rows[j], r, team, topTeam, otherhideteam, legs[r+1] - legs[r])<br />
else<br />
renderTeam(rows[j], r, team, topTeam, otherhideteam)<br />
end<br />
end<br />
local rightPath = addPath(j, r, topTeam, false, (hiderightpath or hideteam) and '0' or '2px')<br />
if not topTeam then topPair = not topPair end<br />
if not topPair and r < maxround and (not (hiderightpath or hideteam)) then<br />
if blank then blank:css('border-right-width', '2px') end<br />
rightPath:css('border-right-width', '2px')<br />
end<br />
if compactFinal and (r == maxround) then<br />
local prop = (team == 1) and 'border-bottom-width' or 'border-top-width'<br />
rightPath:css('border-right-width', '2px')<br />
:css(prop, '2px')<br />
end<br />
team = team + 1<br />
topTeam = not topTeam<br />
end<br />
end<br />
<br />
local function renderGroups(count, round)<br />
local roundFromLast = rounds - round + 1<br />
local groups = math.pow(2, roundFromLast - 2)<br />
local step = count / groups<br />
local group = 1<br />
local offset = 0<br />
local team = 0<br />
local wdef = (tonumber(args['RD' .. (round) .. '-RD' .. (round + 1) .. '-path']) or 2) .. 'px'<br />
local w = wdef<br />
<br />
for r = 1,round do<br />
offset = offset + (hideSeeds and 3 or 4) + legs[r]<br />
end<br />
for i = step / 2, count, step do<br />
local name = 'RD' .. round .. '-group' .. group<br />
addBlank(i, {['height'] = '7px'})<br />
addBlank(i+1, {['height'] = '7px'})<br />
addBlank(i, {['text-align'] = 'center'}, 2, offset-2)<br />
:wikitext(args[name])<br />
:newline()<br />
if (round <= byes) then<br />
team = i/(step/2)<br />
w = isHidden(round, 2*team-1) and isHidden(round, 2*team) and '0' or wdef<br />
end<br />
if (round < maxround) then<br />
addBlank(i, {<br />
['border-color'] = 'inherit',<br />
['border-style'] = 'solid', <br />
['border-width'] = '0 ' .. w .. ' 0 0'})<br />
else<br />
addBlank(i)<br />
end<br />
if (round <= byes) then<br />
team = team + 1<br />
w = isHidden(round, 2*team-1) and isHidden(round, 2*team) and '0' or wdef<br />
end<br />
if (round < maxround) then<br />
addBlank(i+1, {<br />
['border-color'] = 'inherit',<br />
['border-style'] = 'solid', <br />
['border-width'] = '0 ' .. w .. ' 0 0'})<br />
else<br />
addBlank(i+1)<br />
end<br />
group = group + 1<br />
end<br />
end<br />
<br />
local function getThirdOffset()<br />
local offset = (compact and 1 or 3) * (math.pow(2, rounds) - math.pow(2, rounds-3)) - (compact and 2 or 4)<br />
if rounds < 2 then<br />
offset = compact and 4 or 7<br />
elseif rounds < 3 then<br />
offset = compact and 6 or 10<br />
elseif rounds < 4 then<br />
offset = compact and 8 or 17<br />
end<br />
return offset<br />
end<br />
<br />
local function renderThird(count)<br />
local k = offsetThird<br />
local row = rows[k]<br />
local blank<br />
if rounds < 2 then<br />
blank = addBlank(k-1, {['height'] = '7px'})<br />
end<br />
blank = addBlank(k, rounds < 2 and {['height'] = '7px'} or nil)<br />
addHeading(row, rounds + 1, args['3rd'] or 'Third place')<br />
if rounds < 2 then<br />
for i = 1,(compact and 1 or 2) do<br />
blank = addBlank(k+i, {['height'] = '7px'})<br />
end<br />
end<br />
k = k + (compact and 2 or 3)<br />
for i = 1,2 do<br />
row = rows[k]<br />
blank = addBlank(k, rounds < 2 and {['height'] = '7px'} or nil)<br />
if row then<br />
renderTeam(row, rounds + 1, i, i == 1, false)<br />
end<br />
if rounds < 2 and not compact then<br />
blank = addBlank(k+1, {['height'] = '7px'})<br />
end<br />
k = k + (compact and 1 or 2)<br />
end<br />
end<br />
<br />
local function maskRows(tbl, count, offsetcount)<br />
local rmin = 1<br />
local rmax = count<br />
for i = rmin, rmax do<br />
mask[i] = false<br />
end<br />
if showThird then<br />
for i = offsetThird,(offsetThird+ (compact and 3 or 5)) do<br />
rmax = (i > rmax) and i or rmax<br />
mask[i] = true<br />
end<br />
end<br />
for r = 1, maxround do<br />
local teams = math.pow(2, rounds - r + 1)<br />
local step = count / teams<br />
local topTeam = true -- is top row in match-up<br />
local team = 1<br />
<br />
for i = 1, count, step do<br />
local offset, height, blank<br />
local hideteam = false<br />
if r <= byes then<br />
hideteam = isHidden(r, team)<br />
end<br />
if (r == 1) and (RD1seedmap[team] <= 0) then<br />
hideteam = true<br />
end<br />
if not hideteam then<br />
local j = topTeam and i + step - (compact and 1 or 2) or i<br />
mask[j] = true<br />
end<br />
team = team + 1<br />
topTeam = not topTeam<br />
end<br />
end<br />
<br />
for r = 1, maxround do<br />
local roundFromLast = rounds - r + 1<br />
local groups = math.pow(2, roundFromLast - 2)<br />
local step = count / groups<br />
local group = 1<br />
for i = step / 2, count, step do<br />
if args['RD' .. r .. '-group' .. group] then<br />
mask[i] = true<br />
mask[i+1] = true<br />
end<br />
group = group + 1<br />
end<br />
end<br />
local mmin, mmax = rmax, rmin<br />
for i = rmin, rmax do<br />
if mask[i] == true then<br />
mmin = math.min(i, mmin)<br />
mmax = math.max(i, mmax)<br />
end<br />
end<br />
for i = mmin, mmax do<br />
rows[i] = addTableRow(tbl)<br />
end<br />
end<br />
<br />
local function renderTree(tbl)<br />
-- create 3 or 1 rows for every team<br />
local count = math.pow(2, rounds) * (compact and 1 or 3)<br />
local offsetcount = 2 * (compact and 1 or 3) + (compact and 2 or 3)<br />
offsetThird = getThirdOffset()<br />
maskRows(tbl, count, offsetcount)<br />
if showThird then<br />
for i = (count+1), (offsetcount + offsetThird) do<br />
if (rounds > 1) then<br />
local blank = addBlank(i, nil, 1, tonumber(hideSeeds and '3' or '4') + legs[1])<br />
if compact and (rounds > 2) then<br />
blank = addBlank(i, nil, 1, tonumber(hideSeeds and '3' or '4') + legs[2])<br />
end<br />
end<br />
end<br />
end<br />
if not compact then<br />
-- fill rows with groups<br />
for r = 1, rounds - 1 do<br />
renderGroups(count, r)<br />
end<br />
end<br />
-- fill rows with bracket<br />
for r = 1, maxround do<br />
renderRound(count, r)<br />
end<br />
if showThird then<br />
renderThird(count, compact)<br />
end<br />
end<br />
<br />
local function renderHeadings(tbl)<br />
local titleRow = addTableRow((not hideHeadings) and tbl or mw.html.create('table'))<br />
local widthRow = addTableRow(tbl)<br />
for r = 1, (compactFinal and (maxround-1) or maxround) do<br />
titleRow:tag('td')<br />
widthRow:tag('td'):css('width', r > 1 and '5px' or '1px')<br />
if compactFinal and r == (maxround-1) then<br />
addHeading(titleRow, r, getRoundName(r), legs[r+1] - legs[r])<br />
else<br />
addHeading(titleRow, r, getRoundName(r) )<br />
end<br />
local seedCell<br />
if (not hideSeeds) then<br />
seedCell = widthRow:tag('td'):css('width', getWidth('seed', '25px'))<br />
end<br />
local teamCell = widthRow:tag('td'):css('width', getWidth('team', '150px'))<br />
local scoreCells = {}<br />
local legsr = legs[r]<br />
if compactFinal and r == (maxround-1) then<br />
legsr = legs[r+1] > legs[r] and legs[r+1] or legs[r]<br />
end<br />
for s = 1, legsr do<br />
local score_width = '25px'<br />
if aggregate and aggregate ~= '' and s > 1 and s == legsr then<br />
score_width = getWidth('agg', getWidth('score', score_width))<br />
else<br />
score_width = getWidth('score', score_width)<br />
end<br />
scoreCells[s] = widthRow:tag('td'):css('width', score_width)<br />
end<br />
titleRow:tag('td')<br />
widthRow:tag('td'):css('width', r < rounds and '5px' or '1px')<br />
<br />
if compact then<br />
teamCell:css('height', '7px')<br />
else<br />
if seedCell then<br />
seedCell:wikitext('&nbsp;')<br />
end<br />
teamCell:wikitext('&nbsp;')<br />
for s = 1, legs[r] do<br />
scoreCells[s]:wikitext('&nbsp;')<br />
end<br />
end<br />
end<br />
end<br />
<br />
function p.main(frame)<br />
parseArgs(frame)<br />
rounds = tonumber(args.rounds) or 2<br />
maxround = tonumber(args.maxround) or rounds<br />
local teams = math.pow(2, rounds)<br />
compact = (args['compact'] == 'yes' or args['compact'] == 'y')<br />
compactFinal = ((rounds > 4) and compact and args['compact-final'] and (args['compact-final'] == 'yes' or args['compact-final'] == 'y'))<br />
sepwidth = tonumber(args['sepwidth'] or ((args.sets or args.legs) and 1) or (compact and 1) or 2) or 1<br />
aggregate = (args['aggregate'] or ''):lower()<br />
aggsep = args['aggsep'] or args['aggregate']<br />
boldwinner = args['boldwinner'] or args['bold_winner'] or ''<br />
local autoSeeds = (args['autoseeds'] == 'yes' or args['autoseeds'] == 'y')<br />
hideSeeds = (args['seeds'] == 'no' or args['seeds'] == 'n')<br />
showSeeds = (args['seeds'] == 'yes' or args['seeds'] == 'y')<br />
byes = (args['byes'] and (args['byes'] == 'yes' or args['byes'] == 'y') and 1) or (tonumber(args['byes'] or '0') or 0)<br />
hideomittedscores = (args['hideomittedscores'] and (args['hideomittedscores'] == 'yes' or args['hideomittedscores'] == 'y') and 1) or (tonumber(args['hideomittedscores'] or '0') or 0)<br />
hideHeadings = (args['headings'] == 'no' or args['headings'] == 'n')<br />
showThird = isnotblank(args['3rd']) or isnotblank(args['3rd-team1']) or isnotblank(args['3rd-team2'])<br />
local align = (args['float'] or args['align'] or ''):lower()<br />
local clear = args['clear'] or 'none'<br />
parseSeedmap(args['RD1-omit'])<br />
parseLegs(args.sets or args.legs)<br />
<br />
if autoSeeds then<br />
-- set default seeds for round 1<br />
local seeds = getSeeds()<br />
for i = 1, table.getn(seeds) do<br />
local argname = getTeamArgName(1, 'seed', i)<br />
args[argname] = args[argname] or seeds[i]<br />
end<br />
end<br />
<br />
-- create the table<br />
local tbl = mw.html.create('table')<br />
:css('border-style', 'none')<br />
:css('font-size', '90%')<br />
:css('border-collapse', 'separate')<br />
:css('border-spacing', '0')<br />
:attr('cellpadding', '0')<br />
<br />
if (args['nowrap'] and (args['nowrap'] == 'yes' or args['nowrap'] == 'y')) then<br />
tbl:css('white-space', 'nowrap')<br />
end<br />
<br />
if align == 'right' then<br />
tbl:css('float', 'right')<br />
if clear ~= 'none' and clear ~= 'no' and clear ~= 'n' then<br />
tbl:css('clear', 'right')<br />
end<br />
tbl:css('margin', '1em 0 1em 2em')<br />
elseif align == 'left' then<br />
tbl:css('float', 'left')<br />
if clear ~= 'none' and clear ~= 'no' and clear ~= 'n' then<br />
tbl:css('clear', 'left')<br />
end<br />
tbl:css('margin', '1em 2em 1em 0')<br />
elseif align == 'center' or align == 'centre' then<br />
tbl:css('margin', '1em auto')<br />
else<br />
tbl:css('margin', '1em 2em 1em 1em')<br />
end<br />
<br />
renderHeadings(tbl)<br />
renderTree(tbl)<br />
if (args['wide'] and (args['wide'] == 'y' or args['wide'] == 'yes')) then<br />
return '<div class="noresize" style="overflow:auto">' .. tostring(tbl) .. '</div>' .. tcats<br />
end<br />
return tostring(tbl) .. tcats<br />
end<br />
<br />
function p.teamBracket(frame)<br />
return p.main(frame)<br />
end<br />
<br />
return p</div>
Antonsusi