Module:Team bracket
![]() | This Lua module is used on approximately 51,000 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes at Wikipedia talk:High-risk templates before implementing them. |
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
This module implements a generic visual representation of the bracket of a single-elimination tournament with any number of rounds. For common usage, use the {{64TeamBracket}}, {{32TeamBracket}}, {{16TeamBracket}}, {{8TeamBracket}}, {{4TeamBracket}}, {{2TeamBracket}} templates.
Usage
{{#invoke: Team bracket | main | rounds = | RD1-group1 = | RD1 = | RD1-seed1 = | RD1-team1 = | RD1-score1 = ... }}
Parameters
Parameter | Description |
---|---|
rounds |
number of rounds. Use 1 for a 2 team bracket, 2 for a 4 team bracket, 3 for an 8 team bracket, ...
|
maxround |
maximum round to display. This parameter should be omitted unless it is less than the default value set by rounds .
|
seed-width |
the width of the cells for seeds. Plain numbers are assumed to be in px units (e.g., 25 or 25px 2em for 2em or auto for automatic width sizing)
|
team-width |
the width of the cells for team names. Plain numbers are assumed to be in px units (e.g., 200 for 200px or 15em for 15em or auto for automatic width sizing)
|
score-width |
the width of the cells for scores. Plain numbers are assumed to be in px units (e.g., 25 or 25px 2em for 2em or auto for automatic width sizing)
|
compact |
set to yes for compact bracket and to disable groups.
|
seeds |
set to no to omit seed cells, and yes to always show seed cells
|
sets or legs |
the number of sets/legs in each round of matches (delimit with / for different numbers of sets or legs per round) |
nowrap |
set to yes to prevent lines from wrapping
|
byes |
set to 1 , 2 , ... to specify the maximum round number with byes
|
boldwinner |
set to high to automatically bold the seed/team/scores for the team with the highest score, and low for the lowest score
|
hideomittedscores |
set to 1 to hide all omitted score cells. To only omit score cells from the second set or leg onwards, use 2
|
sepwidth |
set to 1 or 2 to override the default separator width
|
headings |
set to no to omit the column headings
|
RDn |
The name of round n. Defaults are "Round of m", ..., "Quarterfinals", "Semifinals", and "Finals", where m is the number of teams in the round. |
RDn-groupm |
The name of group m in round n. For each round, every set of four teams is classified as a group. |
RDn-seedm |
The seed of team m in round n. For round 1, this value defaults to the conventional seed allocation for tournaments. If omitted, the cell is hidden. To hide seeds for round 1, the value must be explicitly set to be empty. m is the zero-padded position. |
RDn-teamm |
The name of team m in round n. |
RDn-scorem |
The score of team m in round n. |
RDn-scorem-s |
The score of team m in round n and set s (or leg for multileg matches). Alternatively, the last score in the round can be specified using the -agg suffix.
|
RD1-omit |
Selectively omit teams from the first round. For example, use 1 / 2 / 5 / 6 to omit team1, team2, team5, and team6 from the first round.
|
RD-shade |
Background color for the RDn headings
|
RDn-shadem-s |
Background coloring for team m in round n and set s (or leg for multileg matches). |
RDn-RDn+1-path |
Set to 0 to omit the path between round n and round n+1.
|
float |
Float the bracket to the left or right or center or centre of the page.
|
clear |
Set to no to prevent "clearing" the left/right side of the page before floating to the left/right. This parameter is only valid with |float=left or |float=right .
|
aggregate |
Set to sets or legs to sum the sets/legs won and append to the end of the scores. Set to score to sum the scores from each set/leg and append to the end of the scores. Set to y or yes to enable the -agg suffix, but without any auto computation. Only works when there are two or more legs/sets in the round. Any automatically computed value can be overridden by setting the value manually with the -agg suffix for the score.
|
Alternatives to avoid Wikipedia's Post-expand include size limit
Pages with many brackets or large brackets, especially those containing flag icons, may come close to or exceed Wikipedia's Post-expand include size limit. In these cases consider using modules directly instead:
- In most cases, the name of the bracket template can be used as the function name for {{#invoke:Bracket|function}}, e.g.
{{16TeamBracket-Compact-Tennis3}}
→{{#invoke:bracket|16TeamBracket-Compact-Tennis3}}
. - In most cases, flag templates can be replaced with {{#invoke:flag|function}}, e.g.
{{flag|CAN}}
→{{#invoke:flag||CAN}}
or{{flag athlete|CAN}}
→{{#invoke:flag|athlete|CAN}}
.
Examples
No seeds
{{#invoke: Team bracket | main | rounds = 2 | seeds = no }}
Lua error in package.lua at line 80: module 'Module:HtmlBuilder' not found.
Compact
{{#invoke: Team bracket | main | rounds = 2 | compact = yes }}
Lua error in package.lua at line 80: module 'Module:HtmlBuilder' not found.
Third place
{{#invoke: Team bracket | main | rounds = 2 | seeds = no | RD2b = Third place }}
Lua error in package.lua at line 80: module 'Module:HtmlBuilder' not found.
Groups
{{#invoke: Team bracket | main | autoseeds = y | rounds = 3 | RD1-group1 = Pacific | RD1-group2 = Mountain | RD2-group1 = West }}
Lua error in package.lua at line 80: module 'Module:HtmlBuilder' not found.
Sets
{{#invoke: Team bracket | main | autoseeds = y | rounds = 3 | sets = 3 / 5 / 5 }}
Lua error in package.lua at line 80: module 'Module:HtmlBuilder' not found.
Aggregate
{{#invoke: Team bracket | main | autoseeds = y | rounds = 3 | legs = 2 | aggregate = y }}
Lua error in package.lua at line 80: module 'Module:HtmlBuilder' not found.
Bold winner with byes and hide omitted scores
{{#invoke: Team bracket | main |rounds=3|byes=1|legs=3/5/5|sepwidth=1|boldwinner=high|hideomittedscores = 1 |RD1-seed3=4|RD1-team3=[[BC Vienna|Hallmann Vienna]]|RD1-score3-1=80|RD1-score3-2=66|RD1-score3-3=64 |RD1-seed4=5|RD1-team4=[[WBC Wels|WBC Raiffeisen Wels]]|RD1-score4-1=64|RD1-score4-2=81|RD1-score4-3=69 |RD1-seed7=3|RD1-team7=[[Kapfenberg Bulls|ece Bulls Kapfenberg]]|RD1-score7-1=97|RD1-score7-2=95 |RD1-seed8=6|RD1-team8=[[Arkadia Traiskirchen Lions]]|RD1-score8-1=80|RD1-score8-2=82 <!--SF--> |RD2-seed1=1|RD2-team1=[[Oberwart Gunners|Redwell Gunners Oberwart]]|RD2-score1-1=75|RD2-score1-2=89|RD2-score1-3=57|RD2-score1-4=79|RD2-score1-5=77 |RD2-seed2=5|RD2-team2=[[WBC Wels|WBC Raiffeisen Wels]]|RD2-score2-1=84|RD2-score2-2=83|RD2-score2-3=63|RD2-score2-4=62|RD2-score2-5=67 |RD2-seed3=2|RD2-team3=[[Swans Gmunden]]|RD2-score3-1=73|RD2-score3-2=79|RD2-score3-3=68|RD2-score3-4=59 |RD2-seed4=3|RD2-team4=[[Kapfenberg Bulls|ece Bulls Kapfenberg]]|RD2-score4-1=92|RD2-score4-2=65|RD2-score4-3=81|RD2-score4-4=61 <!--F--> |RD3-seed1=1|RD3-team1=[[Oberwart Gunners|Redwell Gunners Oberwart]]|RD3-score1-1=61|RD3-score1-2=56|RD3-score1-3=55|RD3-score1-4=72|RD3-score1-5=64 |RD3-seed2=3|RD3-team2=[[Kapfenberg Bulls|ece Bulls Kapfenberg]]|RD3-score2-1=57|RD3-score2-2=66|RD3-score2-3=56|RD3-score2-4=73|RD3-score2-5=73 }}
Lua error in package.lua at line 80: module 'Module:HtmlBuilder' not found.
See also
--
-- This module will implement {{TeamBracket}}
--
local p = {}
local HtmlBuilder = require('Module:HtmlBuilder')
local args
local rounds
local function getArgs(frame)
local args = frame.args;
-- if there are any arguments, then assume that we've got proper ones
for k,v in pairs(args) do
return args
end
-- otherwise, return args from the parent
local parent = frame:getParent();
return parent.args;
end
function getSeeds()
local seeds = {1}
local count = 1
for r = 1, rounds do
local max = math.pow(2, r)
for i = 1, count do
table.insert(seeds, i * 2, max - seeds[i * 2 - 1] + 1)
end
count = count * 2
end
return seeds
end
function addTableRow(tbl)
return tbl.tag('tr')
end
function addBlank(row, width)
local cell = row.tag('td')
.css('border-width', '0')
.css('border-style', 'solid')
.css('border-color', 'black')
if width then
cell.css('width', width)
end
return cell
end
function addPath(rows, index, round, top, left)
local prop = top and 'border-bottom-width' or 'border-top-width'
if left and round == 1 then
addBlank(rows[index]).css('height', '7px')
addBlank(rows[index + 1]).css('height', '7px')
return nil
else
local cell = addBlank(rows[index]).attr('rowspan', '2')
if left or round < rounds and not left then
cell.css(prop, '2px')
end
return cell
end
end
function renderGroups(rows, count, r)
local groups = math.pow(2, r - 2)
local step = count / groups
local group = 1
for i = step / 2, count, step do
addBlank(rows[i]).css('height', '7px')
addBlank(rows[i+1]).css('height', '7px')
addBlank(rows[i])
.attr('rowspan', '2')
.attr('colspan', 5 * (rounds - r + 1) - 1)
.css('text-align', 'center')
.css('border-right-width', '2px')
.wikitext(args['RD' .. r .. '-group' .. group])
group = group + 1
end
end
function renderRound(rows, count, r)
local teams = math.pow(2, rounds - r + 1)
local step = count / teams
local top = true
local open = false
local team = 1
for i = 1, count, step do
local offset, height, blank
if team == 1 or team == teams then
offset = top and i or i + 2
height = step - 2
else
offset = top and i + 1 or i + 2
height = step - 3
end
if height > 0 then
blank = addBlank(rows[offset])
.attr('colspan', '5')
.attr('rowspan', height)
end
local j = top and i + step - 2 or i
addPath(rows, j, r, top, true)
renderTeam(rows[j], r, team)
local right = addPath(rows, j, r, top, false)
if not top then open = not open end
if open and r < rounds then
if blank then blank.css('border-right-width', '2px') end
right.css('border-right-width', '2px')
end
team = team + 1
top = not top
end
end
function getTeamArg(round, type, team)
return args['RD' .. round .. '-' .. type .. '0' .. team] or
args['RD' .. round .. '-' .. type .. team]
end
function getRoundName(round)
local name = args['RD' .. round]
if name then
return name
end
local roundFromLast = rounds - round + 1
if roundFromLast == 1 then
return "Finals"
elseif roundFromLast == 2 then
return "Semifinals"
elseif roundFromLast == 3 then
return "Quarterfinals"
else
return "Round of " .. math.pow(2, roundFromLast)
end
end
function renderTeam(row, round, team)
row.tag('td')
.attr('rowspan', '2')
.css('text-align', 'center')
.css('background-color', '#f2f2f2')
.css('border', '1px solid #aaa')
.wikitext(getTeamArg(round, 'seed', team))
row.tag('td')
.attr('rowspan', '2')
.css('background-color', '#f9f9f9')
.css('border', '1px solid #aaa')
.wikitext(getTeamArg(round, 'team', team))
row.tag('td')
.attr('rowspan', '2')
.css('text-align', 'center')
.css('border', '1px solid #aaa')
.css('background-color', '#f9f9f9')
.wikitext(getTeamArg(round, 'score', team))
end
function renderTree(tbl)
local count = math.pow(2, rounds) * 3
local rows = {}
for i = 1, count do
rows[i] = addTableRow(tbl)
end
for r = 2, rounds do
renderGroups(rows, count, r)
end
for r = 1, rounds do
renderRound(rows, count, r)
end
end
function renderHeading(tbl)
local titleRow = addTableRow(tbl)
local widthRow = addTableRow(tbl)
for r = 1, rounds do
addBlank(titleRow)
addBlank(widthRow, r > 1 and '5px' or nil)
titleRow.tag('td')
.attr('colspan', '3')
.css('text-align', 'center')
.css('border', '1px solid #aaa')
.css('background-color', '#f2f2f2')
.wikitext(getRoundName(r))
addBlank(widthRow, args['seed-width'] or '25px').wikitext(' ')
addBlank(widthRow, args['team-width'] or '150px').wikitext(' ')
addBlank(widthRow, args['score-width'] or '25px').wikitext(' ')
addBlank(titleRow)
addBlank(widthRow, r < rounds and '5px' or nil)
end
end
function p.teamBracket(frame)
args = getArgs(frame)
rounds = tonumber(args.rounds) or 2
local seeds = getSeeds()
for i = 1, table.getn(seeds) do
if not args['RD1-seed' .. i] then
args['RD1-seed' .. i] = seeds[i]
end
end
local tbl = HtmlBuilder.create('table')
.css('border-style', 'none')
.css('font-size', '90%')
.css('margin', '1em 2em 1em 1em')
.css('border-collapse', 'separate')
.css('border-spacing', '0')
renderHeading(tbl)
renderTree(tbl)
return tostring(tbl)
end
return p