Difference between revisions of "Module:TeamBracket-Tennis"
Jump to navigation
Jump to search
blackwiki>SocietyBox (adapt from Module:TeamBracket) |
blackwiki>SocietyBox m (border-collapse) |
||
| Line 26: | Line 26: | ||
.css('border-width', '0') | .css('border-width', '0') | ||
.css('border-style', 'solid') | .css('border-style', 'solid') | ||
| − | .css('border-color', ' | + | .css('border-color', '#aaa') |
if width then | if width then | ||
cell.css('width', width) | cell.css('width', width) | ||
| Line 35: | Line 35: | ||
function addPath(rows, index, round, top, left) | function addPath(rows, index, round, top, left) | ||
local prop = top and 'border-bottom-width' or 'border-top-width' | local prop = top and 'border-bottom-width' or 'border-top-width' | ||
| − | local cell = addBlank(rows[index]) | + | local cell = addBlank(rows[index]).css('border-color', 'black') |
if left and round == 1 then | if left and round == 1 then | ||
return nil | return nil | ||
| Line 86: | Line 86: | ||
function renderTeam(row, round, team) | function renderTeam(row, round, team) | ||
local seedArg = getTeamArg(round, 'seed', team) | local seedArg = getTeamArg(round, 'seed', team) | ||
| − | row | + | local seedCell = addBlank(row) |
.css('text-align', 'center') | .css('text-align', 'center') | ||
.css('background-color', '#f2f2f2') | .css('background-color', '#f2f2f2') | ||
| − | .css('border', '1px | + | .css('border-width', '1px 2px 1px 1px') |
.wikitext(seedArg) | .wikitext(seedArg) | ||
| + | |||
local teamArg = getTeamArg(round, 'team', team) | local teamArg = getTeamArg(round, 'team', team) | ||
if not teamArg or string.len(teamArg) == 0 then | if not teamArg or string.len(teamArg) == 0 then | ||
teamArg = ' ' | teamArg = ' ' | ||
end | end | ||
| − | local teamCell = row | + | local teamCell = addBlank(row) |
.css('background-color', '#f9f9f9') | .css('background-color', '#f9f9f9') | ||
| − | .css('border', '1px | + | .css('border-width', '1px') |
.css('padding', '0 2px') | .css('padding', '0 2px') | ||
.wikitext(teamArg) | .wikitext(teamArg) | ||
| + | |||
for s = 1, sets do | for s = 1, sets do | ||
| − | row | + | addBlank(row) |
.css('text-align', 'center') | .css('text-align', 'center') | ||
| − | .css('border', '1px | + | .css('border-width', '1px') |
.css('background-color', '#f9f9f9') | .css('background-color', '#f9f9f9') | ||
.wikitext(getScore(round, team, s)) | .wikitext(getScore(round, team, s)) | ||
| Line 116: | Line 118: | ||
local team = 1 | local team = 1 | ||
for i = 1, count, step do | for i = 1, count, step do | ||
| − | + | if not top then open = not open end | |
local offset = top and i or i + 1 | local offset = top and i or i + 1 | ||
local height = step - 1 | local height = step - 1 | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
-- add bracket | -- add bracket | ||
| − | local j = top and i + | + | local j = top and i + height or i |
local left = addPath(rows, j, r, top, true) | local left = addPath(rows, j, r, top, true) | ||
renderTeam(rows[j], r, team) | renderTeam(rows[j], r, team) | ||
local right = addPath(rows, j, r, top, false) | local right = addPath(rows, j, r, top, false) | ||
| − | |||
if open and r < rounds then | if open and r < rounds then | ||
| − | |||
right.css('border-right-width', '2px') | right.css('border-right-width', '2px') | ||
end | end | ||
| + | -- add blank | ||
| + | for j = 0, height - 1 do | ||
| + | blank = addBlank(rows[offset + j]) | ||
| + | .css('border-color', 'black') | ||
| + | .attr('colspan', 4 + sets) | ||
| + | if open and r < rounds then | ||
| + | blank.css('border-right-width', '2px') | ||
| + | end | ||
| + | end | ||
| + | -- increment | ||
team = team + 1 | team = team + 1 | ||
top = not top | top = not top | ||
| Line 156: | Line 161: | ||
addBlank(titleRow) | addBlank(titleRow) | ||
addBlank(widthRow, r > 1 and '5px' or nil) | addBlank(widthRow, r > 1 and '5px' or nil) | ||
| − | titleRow | + | addBlank(titleRow) |
.attr('colspan', 2 + sets) | .attr('colspan', 2 + sets) | ||
.css('text-align', 'center') | .css('text-align', 'center') | ||
| − | .css('border', '1px | + | .css('border-width', '1px') |
.css('background-color', '#f2f2f2') | .css('background-color', '#f2f2f2') | ||
.wikitext(getRoundName(r)) | .wikitext(getRoundName(r)) | ||
| Line 181: | Line 186: | ||
.css('font-size', '90%') | .css('font-size', '90%') | ||
.css('margin', '1em 2em 1em 1em') | .css('margin', '1em 2em 1em 1em') | ||
| − | .css('border-collapse', ' | + | .css('border-collapse', 'collapse') |
.css('border-spacing', '0') | .css('border-spacing', '0') | ||
Revision as of 03:36, 19 January 2014
| This Lua module is used on 19,000+ pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages. Consider discussing changes at Wikipedia talk:High-risk templates before implementing them.
Transclusion count updated automatically (see documentation). |
| 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 template implements a variant of Module:TeamBracket for tennis tournaments. It is a generic visual representation of the tournament bracket. For common usage, use the templates in Category:Tennis tournament bracket templates.
Usage
{{#invoke: TeamBracket-Tennis | teamBracket
| rounds =
| sets =
| seeds = <!-- yes / no / or blank -->
| compact = <!-- yes / no / or blank -->
| nowrap = <!-- yes / no / or blank -->
| seed-width =
| team-width =
| score-width =
| RD1 =
| RD1-seed1 =
| RD1-team1 =
| RD1-score1-1 =
| RD1-score1-2 =
| RD1-score1-3 =
}}
Parameter list
The parameters are as follows:
seed-width –the width of the cells for seeds.team-width –the width of the cells for team names.score-width –the width of the cells for scores.compact –set toyesfor compact formatseeds –set tonoto omit seed cells, andyesto always show seed cellsnowrap –set toyesto prevent lines from wrappingbyes –set to1,2, ... to specify the maximum round number with byesheadings –set tonoto omit the column headings
RDn –The name of round n.RDn-seedm –The seed of team m in round n.RDn-teamm –The name of team m in round n.RDn-scorem-s –The score of set s for team m in round n.RDn-groupm –Label for the mth group in round n.
Examples
{{#invoke: TeamBracket-Tennis | teamBracket
| rounds = 2
| sets = 3
| RD1-seed1 = '''1'''
| RD1-seed2 = 4
| RD1-team1 = '''John'''
| RD1-team2 = Declan
| RD1-score1-1 = '''6'''
| RD1-score2-1 = 0
| RD1-score1-2 = 3
| RD1-score2-2 = '''6'''
| RD1-score1-3 = '''7'''
| RD1-score2-3 = 6
| RD1-seed3 = 2
| RD1-seed4 = 3
| RD1-team3 = Barry
| RD1-team4 = Steve
| RD2-seed1 = 1
| RD2-team1 = John
}}
Lua error in package.lua at line 80: module 'Module:HtmlBuilder' not found.
Templates using this module
- {{2TeamBracket-Tennis3}}
- {{2TeamBracket-Tennis5}}
- {{2TeamBracket-Tennis7}}
- {{2TeamBracket-Tennis9}}
- {{2TeamBracket-Compact-Tennis3}}
- {{2TeamBracket-Compact-Tennis5}}
- {{4TeamBracket-Tennis3}}
- {{4TeamBracket-Tennis5}}
- {{4TeamBracket-Tennis35}}
- {{4TeamBracket-Tennis3-with third}}
- {{4TeamBracket-Tennis35-with third}}
- {{4TeamBracket-Tennis5-with 3rd}}
- {{4TeamBracket-Tennis7-with 3rd}}
- {{4TeamBracket-Compact-Tennis3}}
- {{4TeamBracket-Compact-Tennis7}}
- {{8TeamBracket-Tennis3}}
- {{8TeamBracket-Tennis5}}
- {{8TeamBracket-Tennis35}}
- {{8TeamBracket-Tennis353}}
- {{8TeamBracket-Tennis355}}
- {{8TeamBracket-Tennis3-with third}}
- {{8TeamBracket-Tennis5-with third}}
- {{8TeamBracket-Tennis35-with third}}
- {{8TeamBracket-Compact-Tennis7}}
- {{16TeamBracket-Tennis3}}
- {{16TeamBracket-Tennis5}}
- {{16TeamBracket-Tennis5777}}
- {{16TeamBracket-Compact-Tennis3}}
- {{16TeamBracket-Compact-Tennis5}}
- {{16TeamBracket-Compact-Tennis35}}
- {{16TeamBracket-Compact-Tennis7}}
- {{16TeamBracket-Compact-Tennis3355}}
- {{16TeamBracket-Compact-Tennis3555}}
- {{16TeamBracket-Compact-Tennis3-with 3rd}}
- {{16TeamBracket-Compact-Tennis7-with 3rd}}
- {{32TeamBracket-Tennis3}}
- {{32TeamBracket-Tennis5}}
--
-- This module will implement {{16TeamBracket-Compact-Tennis5}}
--
local p = {}
local HtmlBuilder = require('Module:HtmlBuilder')
local args
local rounds
local sets
local function getArgs(frame)
local parent = frame:getParent();
local args = parent.args;
for k,v in pairs(frame.args) do
args[k] = v
end
return parent.args;
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', '#aaa')
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'
local cell = addBlank(rows[index]).css('border-color', 'black')
if left and round == 1 then
return nil
else
if left or round < rounds and not left then
cell.css(prop, '2px')
end
return cell
end
end
function getWidth(param, default)
local arg = args[param .. '-width']
if not arg or string.len(arg) == 0 then
arg = default
end
if tonumber(arg) ~= nil then
arg = arg .. 'px'
end
return arg
end
function getTeamArg(round, type, team)
local argname = string.format("RD%d-%s%02d",round, type, team)
return args[argname]
end
function getScore(round, team, set)
local argname = string.format("RD%d-score%02d-%d",round, team, set)
return args[argname]
end
function getRoundName(round)
local name = args['RD' .. round]
if name and string.len(name) > 0 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)
local seedArg = getTeamArg(round, 'seed', team)
local seedCell = addBlank(row)
.css('text-align', 'center')
.css('background-color', '#f2f2f2')
.css('border-width', '1px 2px 1px 1px')
.wikitext(seedArg)
local teamArg = getTeamArg(round, 'team', team)
if not teamArg or string.len(teamArg) == 0 then
teamArg = ' '
end
local teamCell = addBlank(row)
.css('background-color', '#f9f9f9')
.css('border-width', '1px')
.css('padding', '0 2px')
.wikitext(teamArg)
for s = 1, sets do
addBlank(row)
.css('text-align', 'center')
.css('border-width', '1px')
.css('background-color', '#f9f9f9')
.wikitext(getScore(round, team, s))
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
if not top then open = not open end
local offset = top and i or i + 1
local height = step - 1
-- add bracket
local j = top and i + height or i
local left = addPath(rows, j, r, top, true)
renderTeam(rows[j], r, team)
local right = addPath(rows, j, r, top, false)
if open and r < rounds then
right.css('border-right-width', '2px')
end
-- add blank
for j = 0, height - 1 do
blank = addBlank(rows[offset + j])
.css('border-color', 'black')
.attr('colspan', 4 + sets)
if open and r < rounds then
blank.css('border-right-width', '2px')
end
end
-- increment
team = team + 1
top = not top
end
end
function renderTree(tbl)
local count = math.pow(2, rounds)
local rows = {}
for i = 1, count do
rows[i] = addTableRow(tbl)
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)
addBlank(titleRow)
.attr('colspan', 2 + sets)
.css('text-align', 'center')
.css('border-width', '1px')
.css('background-color', '#f2f2f2')
.wikitext(getRoundName(r))
addBlank(widthRow, getWidth('seed', '25px')).wikitext(' ')
addBlank(widthRow, getWidth('team', '150px')).wikitext(' ')
for s = 1, sets do
addBlank(widthRow, getWidth('score', '17px')).wikitext(' ')
end
addBlank(titleRow)
addBlank(widthRow, r < rounds and '5px' or nil)
end
end
function p.teamBracket(frame)
args = getArgs(frame)
rounds = tonumber(args.rounds) or 4
sets = tonumber(args.sets) or 5
local tbl = HtmlBuilder.create('table')
.css('border-style', 'none')
.css('font-size', '90%')
.css('margin', '1em 2em 1em 1em')
.css('border-collapse', 'collapse')
.css('border-spacing', '0')
renderHeading(tbl)
renderTree(tbl)
return tostring(tbl)
end
return p