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.
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. m is the zero-padded position.
RDn-scorem
The score of team m in round n. m is the zero-padded position.
---- This module will implement {{TeamBracket}}--localp={}localargslocalroundslocalpaddinglocalhideSeedslocalshowSeedslocaltracking=''functiongetSeeds()localseeds={1,2}localcount=2localbefore=falseforr=2,roundsdolocalmax=math.pow(2,r)fori=1,countdolocalpos=i*2ifbeforethenpos=pos-1endtable.insert(seeds,pos,max-seeds[i*2-1]+1)before=notbeforeendcount=count*2endreturnseedsendfunctionaddTableRow(tbl)returntbl:tag('tr')endfunctionaddBlank(row,width)localcell=row:tag('td')ifwidththencell:css('width',width)endreturncellendfunctionaddPath(rows,index,round,top,left)localprop=topand'border-bottom-width'or'border-top-width'ifleftandround==1thenaddBlank(rows[index]):css('height','7px')addBlank(rows[index+1]):css('height','7px')returnnilelselocalcell=addBlank(rows[index]):attr('rowspan','2'):css('border-width','0'):css('border-style','solid'):css('border-color','black')ifleftorround<roundsandnotleftthencell:css(prop,'2px')endreturncellendendfunctionaddCompactPath(rows,index,round,top,left)localprop=topand'border-bottom-width'or'border-top-width'ifleftandround==1thenaddBlank(rows[index])returnnilelselocalcell=addBlank(rows[index]):css('border-width','0'):css('border-style','solid'):css('border-color','black')ifleftorround<roundsandnotleftthencell:css(prop,'2px')endreturncellendendfunctiongetWidth(param,default)localarg=args[param..'-width']ifnotargorstring.len(arg)==0thenarg=defaultendiftonumber(arg)~=nilthenarg=arg..'px'endreturnargendfunctiongetTeamArg(round,type,team)returnargs[getTeamArgName(round,type,team)]endfunctiongetTeamArgName(round,type,team)returnstring.format('RD%d-%s'..padding,round,type,team)endfunctiongetRoundName(round)localname=args['RD'..round]ifnameandstring.len(name)>0thenreturnnameendlocalroundFromLast=rounds-round+1ifroundFromLast==1thenreturn"Finals"elseifroundFromLast==2thenreturn"Semifinals"elseifroundFromLast==3thenreturn"Quarterfinals"elsereturn"Round of "..math.pow(2,roundFromLast)endendfunctionrenderTeam(row,round,team,top,compact)localseedCelllocalseedArg=getTeamArg(round,'seed',team)-- seed value for the paired teamlocalpairSeedArg=getTeamArg(round,'seed',team%2==0andteam-1orteam+1)-- show seed if seed is defined for either or bothlocalshowSeed=showSeedsor(seedArgandstring.len(seedArg)>0)or(pairSeedArgandstring.len(pairSeedArg)>0)ifshowSeedand(nothideSeeds)thenseedCell=row:tag('td'):css('text-align','center'):css('background-color','#f2f2f2'):css('border-color','#aaa'):css('border-style','solid'):css('border-top-width','1px'):css('border-left-width','1px'):css('border-right-width','1px'):css('border-bottom-width','0'):wikitext(seedArg):newline()endlocalteamArg=getTeamArg(round,'team',team)ifnotteamArgorstring.len(teamArg)==0thenteamArg=' 'endlocalteamCell=row:tag('td'):css('background-color','#f9f9f9'):css('border-color','#aaa'):css('border-style','solid'):css('border-top-width','1px'):css('border-left-width','1px'):css('border-right-width','0'):css('border-bottom-width','0'):css('padding','0 2px'):wikitext(teamArg):newline()ifnotshowSeedand(nothideSeeds)thenteamCell:attr('colspan','2')endlocalscoreCell=row:tag('td'):css('text-align','center'):css('border-color','#aaa'):css('border-style','solid'):css('border-top-width','1px'):css('border-left-width','1px'):css('border-right-width','1px'):css('border-bottom-width','0'):css('background-color','#f9f9f9'):wikitext(getTeamArg(round,'score',team)):newline()ifnotcompactthenifseedCellthenseedCell:attr('rowspan','2'):css('border-bottom-width','1px')endscoreCell:attr('rowspan','2'):css('border-bottom-width','1px')teamCell:attr('rowspan','2'):css('border-right-width','1px'):css('border-bottom-width','1px')elseifnottopthenifseedCellthenseedCell:css('border-bottom-width','1px')endteamCell:css('border-bottom-width','1px')scoreCell:css('border-bottom-width','1px')endendendfunctionrenderRound(rows,count,r)localteams=math.pow(2,rounds-r+1)localstep=count/teamslocaltopTeam=true-- is top row in match-uplocaltopPair=true-- is top match-up in pair of match-upslocalteam=1fori=1,count,stepdolocaloffset,height,blank-- leave room for groups for teams other than first and lastifteam==1orteam==teamsthenoffset=topTeamandiori+2height=step-2elseoffset=topTeamandi+1ori+2height=step-3endifheight>0thenblank=addBlank(rows[offset]):attr('colspan',hideSeedsand'4'or'5'):attr('rowspan',height):css('border-color','black'):css('border-style','solid'):css('border-width','0')end-- add bracketlocalj=topTeamandi+step-2ori-- add left pathaddPath(rows,j,r,topTeam,true)renderTeam(rows[j],r,team,topTeam,false)localrightPath=addPath(rows,j,r,topTeam,false)ifnottopTeamthentopPair=nottopPairendifnottopPairandr<roundsthenifblankthenblank:css('border-right-width','2px')endrightPath:css('border-right-width','2px')endteam=team+1topTeam=nottopTeamendendfunctionrenderCompactRound(rows,count,r)localteams=math.pow(2,rounds-r+1)localstep=count/teamslocaltopTeam=true-- is top row in match-uplocaltopPair=true-- is top match-up in pair of match-upslocalteam=1fori=1,count,stepdolocaloffset,height,blank-- empty space above or belowlocaloffset=topTeamandiori+1localheight=step-1ifheight>0thenblank=addBlank(rows[offset]):attr('colspan',hideSeedsand'4'or'5'):css('border-color','black'):css('border-style','solid'):css('border-width','0'):attr('rowspan',height)end-- add bracketlocalj=topTeamandi+step-1ori-- add left pathaddCompactPath(rows,j,r,topTeam,true)renderTeam(rows[j],r,team,topTeam,true)localrightPath=addCompactPath(rows,j,r,topTeam,false)ifnottopTeamthentopPair=nottopPairendifnottopPairandr<roundsthenifblankthenblank:css('border-right-width','2px')endrightPath:css('border-right-width','2px')endteam=team+1topTeam=nottopTeamendendfunctionrenderGroups(rows,count,round)localroundFromLast=rounds-round+1localgroups=math.pow(2,roundFromLast-2)localstep=count/groupslocalgroup=1fori=step/2,count,stepdolocalname='RD'..round..'-group'..groupaddBlank(rows[i]):css('height','7px')addBlank(rows[i+1]):css('height','7px')addBlank(rows[i]):attr('rowspan','2'):attr('colspan',(hideSeedsand4or5)*round-1):css('text-align','center'):css('border-color','black'):css('border-style','solid'):css('border-width','0 2px 0 0'):wikitext(args[name]):newline()group=group+1endendfunctionrenderTree(tbl,compact)-- create 3 or 1 rows for every teamlocalcount=math.pow(2,rounds)*(compactand1or3)localrows={}fori=1,countdorows[i]=addTableRow(tbl)endifnotcompactthen-- fill rows with groupsforr=1,rounds-1dorenderGroups(rows,count,r)endend-- fill rows with bracketforr=1,roundsdoifcompactthenrenderCompactRound(rows,count,r)elserenderRound(rows,count,r)endendendfunctionrenderHeading(tbl,compact)localtitleRow=addTableRow(tbl)localwidthRow=addTableRow(tbl)forr=1,roundsdoaddBlank(titleRow)addBlank(widthRow,r>1and'5px'ornil)titleRow:tag('td'):attr('colspan',hideSeedsand'2'or'3'):css('text-align','center'):css('border','1px solid #aaa'):css('background-color','#f2f2f2'):wikitext(getRoundName(r)):newline()localseedCellifnothideSeedsthenseedCell=addBlank(widthRow,getWidth('seed','25px'))endlocalteamCell=addBlank(widthRow,getWidth('team','150px'))localscoreCell=addBlank(widthRow,getWidth('score','25px'))addBlank(titleRow)addBlank(widthRow,r<roundsand'5px'ornil)ifcompactthenteamCell:css('height','7px')elseifseedCellthenseedCell:wikitext(' ')endteamCell:wikitext(' ')scoreCell:wikitext(' ')endendendfunctionp.teamBracket(frame)localgetArgs=require('Module:Arguments').getArgsargs=getArgs(frame,{trim=false,removeBlanks=false})-- exit early if this section is not to be transcludedifargs['section']andargs['transcludesection']andargs['section']~=args['transcludesection']thenreturn''endrounds=tonumber(args.rounds)or2localteams=math.pow(2,rounds)padding='%0'..(teams<10and1or2)..'d'localcompact=(args['compact']and(args['compact']=='yes'orargs['compact']=='y'))localautoSeeds=(args['autoseeds']and(args['autoseeds']=='yes'orargs['autoseeds']=='y'))hideSeeds=(args['seeds']and(args['seeds']=='no'orargs['seeds']=='n'))showSeeds=(args['seeds']and(args['seeds']=='yes'orargs['seeds']=='y'))ifautoSeedsthen-- set default seeds for round 1localseeds=getSeeds()fori=1,table.getn(seeds)dolocalargname=getTeamArgName(1,'seed',i)ifnotargs[argname]thenargs[argname]=seeds[i]endendendlocaltbl=mw.html.create('table'):css('border-style','none'):css('font-size','90%'):css('margin','1em 2em 1em 1em'):css('border-collapse','separate'):css('border-spacing','0')if(args['nowrap']and(args['nowrap']=='yes'orargs['nowrap']=='y'))thentbl:css('white-space','nowrap')endifcompactthentbl:css('font-size','90%'):attr('cellpadding','0')endrenderHeading(tbl,compact)renderTree(tbl,compact)returntostring(tbl)..trackingendreturnp