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 = &#039;&#039;<br /> <br /> local function isnotblank(s)<br /> return s and s ~= &#039;&#039;<br /> end<br /> <br /> local function isblank(s)<br /> return (not s) or (s == &#039;&#039;)<br /> end<br /> <br /> local function sumScores(s1, s2)<br /> s1 = mw.ustring.gsub(s1 or &#039;&#039;, &#039;^[\&#039;%s]*([%d%.]*).-$&#039;, &#039;%1&#039;)<br /> s2 = mw.ustring.gsub(s2 or &#039;&#039;, &#039;^[\&#039;%s]*([%d%.]*).-$&#039;, &#039;%1&#039;)<br /> if s1 ~= &#039;&#039; and s2 ~= &#039;&#039; 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 &#039;&#039;, &#039;^[\&#039;%s]*([%d%.]*)[\&#039;%s]*%([\&#039;%s]*([%d%.]*)[\&#039;%s]*%).-$&#039;, &#039;%2&#039;)<br /> local ps2 = mw.ustring.gsub(s2 or &#039;&#039;, &#039;^[\&#039;%s]*([%d%.]*)[\&#039;%s]*%([\&#039;%s]*([%d%.]*)[\&#039;%s]*%).-$&#039;, &#039;%2&#039;)<br /> s1 = mw.ustring.gsub(s1 or &#039;&#039;, &#039;^[\&#039;%s]*([%d%.]*).-$&#039;, &#039;%1&#039;)<br /> s2 = mw.ustring.gsub(s2 or &#039;&#039;, &#039;^[\&#039;%s]*([%d%.]*).-$&#039;, &#039;%1&#039;)<br /> <br /> if s1 ~= &#039;&#039; and s2 ~= &#039;&#039; 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 &gt; s2) and 1) or ((s1 &lt; s2) and 2) or 0<br /> else<br /> return ((s2 &gt; s1) and 1) or ((s2 &lt; 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, &#039;(%(%[%[[^%[%]]*%]%]%))&#039;, &#039;&lt;span style=&quot;font-weight:normal&quot;&gt;%1&lt;/span&gt;&#039;)<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 &#039;&#039;) or tonumber(pargs.rounds or &#039;&#039;) or 2<br /> local teams = math.pow(2, r)<br /> local rdstr = &#039;RD&#039; .. tostring(r)<br /> local rdbstr = &#039;RD&#039; .. tostring(r) .. &#039;b&#039;<br /> local rdp1str = &#039;RD&#039; .. 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) == &#039;string&#039; then<br /> if k:find(&#039;^[R3][Dr][d1-9]b?%-[a-z]+00*&#039;) then<br /> k = mw.ustring.gsub(k, &#039;^([R3][Dr][d1-9]b?%-[a-z]+)00*&#039;, &#039;%1&#039;)<br /> if (teams &lt; 10) then <br /> tcats = tcats .. &#039;[[Category:Pages using a team bracket with deprecated syntax|P]]&#039;<br /> end<br /> end<br /> if k:find(&#039;^&#039; .. rdp1str) then<br /> k = mw.ustring.gsub(k, &#039;^&#039; .. rdp1str, &#039;3rd&#039;)<br /> tcats = tcats .. &#039;[[Category:Pages using a team bracket with deprecated syntax|3]]&#039;<br /> elseif k:find(&#039;^&#039; .. rdbstr) then<br /> k = mw.ustring.gsub(k, &#039;^&#039; .. rdbstr, &#039;3rd&#039;)<br /> elseif k:find(&#039;^&#039; .. rdstr .. &#039;%-[a-z]+3&#039;) then<br /> k = mw.ustring.gsub(k, &#039;^&#039; .. rdstr .. &#039;(%-[a-z]+)3&#039;, &#039;3rd%11&#039;)<br /> elseif k:find(&#039;^&#039; .. rdstr .. &#039;%-[a-z]+4&#039;) then<br /> k = mw.ustring.gsub(k, &#039;^&#039; .. rdstr .. &#039;(%-[a-z]+)4&#039;, &#039;3rd%12&#039;)<br /> elseif k:find(&#039;^Consol&#039;) then<br /> k = mw.ustring.gsub(k, &#039;^Consol&#039;, &#039;3rd&#039;)<br /> tcats = tcats .. &#039;[[Category:Pages using a team bracket with deprecated syntax|3]]&#039;<br /> elseif k:find(&#039;^group[0-9]&#039;) then<br /> tcats = tcats .. &#039;[[Category:Pages using a team bracket with deprecated syntax|G]]&#039;<br /> end<br /> end<br /> args[k] = v<br /> end<br /> end<br /> <br /> if (args[&#039;byes&#039;] and (args[&#039;byes&#039;] == &#039;yes&#039; or args[&#039;byes&#039;] == &#039;y&#039;)) then<br /> tcats = tcats .. &#039;[[Category:Pages using a team bracket with deprecated syntax|B]]&#039;<br /> end<br /> end<br /> <br /> local function parseSeedmap(s)<br /> s = mw.text.split((s or &#039;0&#039;) .. &#039;/&#039;, &#039;[%s]*/[%s]*&#039;)<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 &#039;x&#039;) 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] &gt; 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 &#039;1&#039;) .. &#039;/&#039;, &#039;[%s]*/[%s]*&#039;)<br /> if aggregate == &#039;n&#039; or aggregate == &#039;no&#039; or aggregate == &#039;0&#039; then<br /> aggregate = &#039;&#039;<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] &gt; 1 and aggregate ~= &#039;&#039; 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(&#039;tr&#039;)<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(&#039;td&#039;) or mw.html.create(&#039;td&#039;)<br /> if rowspan and rowspan &gt; 1 then<br /> cell:attr(&#039;rowspan&#039;, rowspan)<br /> end<br /> if colspan and colspan &gt; 1 then<br /> cell:attr(&#039;colspan&#039;, 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 &gt; 1 then topcell = true end<br /> if seedorteam then<br /> cell:css(&#039;border&#039;, &#039;1px solid var(--border-color-base,#a2a9b1)&#039;)<br /> :css(&#039;border-top-width&#039;, topcell and &#039;1px&#039; or &#039;0&#039;)<br /> else<br /> cell:css(&#039;border-color&#039;, &#039;var(--border-color-base,#a2a9b1)&#039;)<br /> :css(&#039;border-style&#039;, &#039;solid&#039;)<br /> :css(&#039;border-top-width&#039;, topcell and &#039;1px&#039; or &#039;0&#039;)<br /> :css(&#039;border-left-width&#039;, (extrasep and &#039;1px&#039;) or ((sepwidth &gt; 1) and &#039;1px&#039;) or &#039;0&#039;)<br /> :css(&#039;border-right-width&#039;, &#039;1px&#039;)<br /> :css(&#039;border-bottom-width&#039;, &#039;1px&#039;)<br /> end<br /> end<br /> <br /> local function addHeading(row, r, text, pad)<br /> pad = (pad == nil or pad &lt; 0) and 0 or pad<br /> local cell = row:tag(&#039;td&#039;)<br /> :attr(&#039;colspan&#039;, tonumber(hideSeeds and &#039;1&#039; or &#039;2&#039;) + legs[r] + pad)<br /> :css(&#039;text-align&#039;, &#039;center&#039;)<br /> :css(&#039;border&#039;, &#039;1px solid var(--border-color-base,#a2a9b1)&#039;)<br /> :css(&#039;color&#039;, &#039;var(--color-base,#202122)&#039;)<br /> :css(&#039;overflow&#039;, &#039;inherit&#039;) -- Added due to strange interactions with dark mode and Vector 2022.<br /> :css(&#039;background-color&#039;, args[&#039;RD-shade&#039;] or &#039;var(--background-color-neutral,#eaecf0)&#039;)<br /> :wikitext(text)<br /> :newline()<br /> <br /> if args[&#039;RD-shade&#039;] then<br /> cell:css(&#039;color&#039;, &#039;#202122&#039;) -- Makes text dark if there&#039;s a custom colour underneath it<br /> end<br /> end<br /> <br /> local function getWidth(param, default)<br /> local arg = args[param .. &#039;-width&#039;]<br /> if isblank(arg) then<br /> arg = default<br /> end<br /> if tonumber(arg) then<br /> arg = arg .. &#039;px&#039;<br /> end<br /> return arg<br /> end<br /> <br /> local function getTeamArgName(round, type, team)<br /> if round &gt; rounds then<br /> return string.format(&#039;3rd-%s%d&#039;, type, team)<br /> else<br /> if (round == 1) then<br /> team = RD1seedmap[team]<br /> if team == 0 then<br /> return &#039;NIL&#039;<br /> end<br /> end<br /> return string.format(&#039;RD%d-%s%d&#039;, round, type, team)<br /> end<br /> end<br /> <br /> local function getShadeArg(round, team, s)<br /> local argname = getTeamArgName(round, &#039;shade&#039;, team) .. (s and (&#039;-&#039; .. s) or &#039;&#039;)<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, &#039;score&#039;, team) .. (s and (&#039;-&#039; .. s) or &#039;&#039;)<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 &#039;&#039;<br /> end<br /> if mw.ustring.find(value, &#039;[%s]*&lt;[%s/]*[Bb][Rr][%s/]*&gt;[%s ]*&amp;[Nn][Bb][Ss][Pp];[%s]*&#039;) then<br /> tcats = tcats .. &#039;[[Category:Pages using a team bracket with nbsp]]&#039;<br /> end<br /> return mw.ustring.gsub(value, &#039;[%s]*&lt;[%s/]*[Bb][Rr][%s/]*&gt;[%s ]*&amp;[Nn][Bb][Ss][Pp];[%s]*&#039;, &#039;&lt;br/&gt;&#039;)<br /> end<br /> <br /> local function isHidden(r, team)<br /> return isblank( getTeamArg(r, &#039;team&#039;, team) )<br /> end<br /> <br /> local function getRoundName(round)<br /> local name = args[&#039;RD&#039; .. round]<br /> if isnotblank(name) then<br /> return name<br /> end<br /> local roundFromLast = rounds - round + 1<br /> if roundFromLast == 1 then<br /> return &quot;Finals&quot;<br /> elseif roundFromLast == 2 then<br /> return &quot;Semifinals&quot;<br /> elseif roundFromLast == 3 then<br /> return &quot;Quarterfinals&quot;<br /> else<br /> return &quot;Round of &quot; .. math.pow(2, roundFromLast)<br /> end<br /> end<br /> <br /> local function addPath(index, round, top, left, w)<br /> local prop = top and &#039;border-bottom-width&#039; or &#039;border-top-width&#039;<br /> if left and round == 1 then<br /> if compact then<br /> addBlank(index)<br /> else<br /> addBlank(index, {[&#039;height&#039;] = &#039;7px&#039;})<br /> addBlank(index+1, {[&#039;height&#039;] = &#039;7px&#039;})<br /> end<br /> return nil<br /> else<br /> local cell = addBlank(index, <br /> {[&#039;border-width&#039;] = &#039;0&#039;,<br /> [&#039;border-style&#039;] = &#039;solid&#039;,<br /> [&#039;border-color&#039;] = &#039;inherit&#039;}, (not compact) and 2 or 1)<br /> if left or round &lt; maxround and not left then<br /> cell:css(prop, w or &#039;2px&#039;)<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 &lt; 0) and 0 or pad<br /> local tcs = pad + 1<br /> local seedCell<br /> local shade = getShadeArg(round, team) or &#039;var(--background-color-neutral-subtle,#f8f9fa)&#039;<br /> local shadeseed = getShadeArg(round, team, &#039;seed&#039;) or getShadeArg(round, team) or &#039;var(--background-color-neutral,#eaecf0)&#039;<br /> local seedArg = getTeamArg(round, &#039;seed&#039;, 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 &#039;&#039; <br /> or getTeamArg(round, &#039;seed&#039;, 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(&#039;td&#039;)<br /> :css(&#039;text-align&#039;, &#039;center&#039;)<br /> :css(&#039;color&#039;, &#039;var(--color-base,#202122)&#039;)<br /> :css(&#039;overflow&#039;, &#039;inherit&#039;) -- Added due to strange interactions with dark mode and Vector 2022.<br /> :css(&#039;background-color&#039;, shadeseed)<br /> :attr(&#039;rowspan&#039;, (not compact) and &#039;2&#039; or nil)<br /> :wikitext(seedArg)<br /> :newline()<br /> <br /> if (shadeseed ~= &#039;var(--background-color-neutral,#eaecf0)&#039;) then<br /> seedCell:css(&#039;color&#039;, &#039;#202122&#039;) -- Makes text dark if there&#039;s a custom colour underneath it<br /> end<br /> addBorders(seedCell, top or otherbye, true, false)<br /> end<br /> <br /> local teamArg = getTeamArg(round, &#039;team&#039;, team)<br /> if isblank(teamArg) then<br /> teamArg = &#039;&amp;nbsp;&#039;<br /> elseif boldwinner ~= &#039;&#039; 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(&#039;td&#039;)<br /> :css(&#039;color&#039;, &#039;var(--color-base,#202122)&#039;)<br /> :css(&#039;overflow&#039;, &#039;inherit&#039;) -- Added due to strange interactions with dark mode and Vector 2022.<br /> :css(&#039;background-color&#039;, shade)<br /> :css(&#039;padding&#039;, &#039;0 2px&#039;)<br /> :attr(&#039;rowspan&#039;, (not compact) and &#039;2&#039; or nil)<br /> :attr(&#039;colspan&#039;, (tcs &gt; 1) and tcs or nil)<br /> :wikitext(teamArg)<br /> :newline()<br /> <br /> if (shade ~= &#039;var(--background-color-neutral-subtle,#f8f9fa)&#039;) then<br /> teamCell:css(&#039;color&#039;, &#039;#202122&#039;) -- Makes text dark if there&#039;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] &gt; 1 and s == legs[round] and true or false<br /> local score1 = (agg and getScoreArg(round, team, &#039;agg&#039;) 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, &#039;agg&#039;) 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 ~= &#039;&#039; and score1 == nil and hassum then<br /> score1 = (aggregate == &#039;score&#039;) and sumscore <br /> or ((aggregate == &#039;legs&#039; or aggregate == &#039;sets&#039;) and wins)<br /> or nil<br /> end<br /> if agg and aggregate ~= &#039;&#039; and score2 == nil and hassum then<br /> score2 = (aggregate == &#039;score&#039;) and othersumscore<br /> or ((aggregate == &#039;legs&#039; or aggregate == &#039;sets&#039;) and otherwins)<br /> or nil<br /> end<br /> if (score1 == nil or score1 == &#039;&#039;) and (score2 == nil or score2 == &#039;&#039;) then<br /> if hideomittedscores &gt; 0 and s &gt;= 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 ~= &#039;low&#039;)<br /> sumscore = sumScores(sumscore, score1)<br /> othersumscore = sumScores(othersumscore, score2)<br /> if winner == 1 then<br /> if boldwinner ~= &#039;&#039; or (agg and (aggregate == &#039;score&#039; or aggregate == &#039;legs&#039; or aggregate == &#039;sets&#039;)) then <br /> if agg and (aggregate == &#039;legs&#039; or aggregate == &#039;sets&#039;) and (wins &lt;= (legs[round] - 1)/2) then<br /> else<br /> fw = &#039;bold&#039;<br /> end<br /> end<br /> if not (agg and (aggregate == &#039;score&#039; or aggregate == &#039;legs&#039; or aggregate == &#039;sets&#039;)) then wins = wins + 1 end<br /> elseif winner == 2 then<br /> if not (agg and (aggregate == &#039;score&#039; or aggregate == &#039;legs&#039; or aggregate == &#039;sets&#039;)) then otherwins = otherwins + 1 end<br /> end<br /> <br /> local shadearg = getShadeArg(round, team, s) or shade<br /> scoreCells[s] = row:tag(&#039;td&#039;)<br /> :css(&#039;text-align&#039;, &#039;center&#039;)<br /> :css(&#039;color&#039;, &#039;var(--color-base,#202122)&#039;)<br /> :css(&#039;overflow&#039;, &#039;inherit&#039;) -- Added due to strange interactions with dark mode and Vector 2022.<br /> :css(&#039;background-color&#039;, shadearg)<br /> :css(&#039;font-weight&#039;, fw)<br /> :attr(&#039;rowspan&#039;, (not compact) and &#039;2&#039; or nil)<br /> :wikitext(score1)<br /> :newline()<br /> <br /> if (shadearg ~= &#039;var(--background-color-neutral-subtle,#f8f9fa)&#039;) then<br /> scoreCells[s]:css(&#039;color&#039;, &#039;#202122&#039;) -- Makes text dark if there&#039;s a custom colour underneath it<br /> end<br /> <br /> addBorders(scoreCells[s], top or otherbye, false, s &gt; 1 and s == legs[round] and aggsep or nil)<br /> end<br /> end<br /> if teamcolspan &gt; 1 then<br /> teamCell:attr(&#039;colspan&#039;, teamcolspan)<br /> end<br /> if boldwinner ~= &#039;&#039; and wins &gt; otherwins then<br /> if (aggregate == &#039;legs&#039; or aggregate == &#039;sets&#039;) and (wins &lt;= (legs[round] - 1)/2) then<br /> else<br /> if seedCell then<br /> seedCell:css(&#039;font-weight&#039;, &#039;bold&#039;)<br /> end<br /> if teamCell then<br /> teamCell:css(&#039;font-weight&#039;, &#039;bold&#039;)<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 &lt;= 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] &lt;= 0) then<br /> hideteam = true<br /> end<br /> if (r &gt; 1) and (r &lt;= (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] &lt;= 0 and RD1seedmap[2*team] &lt;= 0) then<br /> hideleftpath = true<br /> end<br /> if compactFinal and (r == rounds) then<br /> hideleftpath = true<br /> end<br /> if (tonumber(args[&#039;RD&#039; .. (r-1) .. &#039;-RD&#039; .. (r) .. &#039;-path&#039;]) or 2) == 0 then<br /> hideleftpath = true<br /> end<br /> if (tonumber(args[&#039;RD&#039; .. (r) .. &#039;-RD&#039; .. (r + 1) .. &#039;-path&#039;]) 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 &#039;2&#039; or &#039;3&#039;) + 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 /> [&#039;border-color&#039;] = &#039;inherit&#039;,<br /> [&#039;border-style&#039;]= &#039;solid&#039;,<br /> [&#039;border-width&#039;]= &#039;0&#039;}, 2)<br /> b:css(&#039;border-right-width&#039;, &#039;2px&#039;)<br /> end<br /> end<br /> if height &gt; 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] &gt; 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 &#039;1&#039; or &#039;2&#039;) + legs[r] + pad)<br /> if args[&#039;RD&#039; .. r .. &#039;-group&#039; .. group] then<br /> blank:wikitext(args[&#039;RD&#039; .. r .. &#039;-group&#039; .. group])<br /> blank:css(&#039;text-align&#039;, &#039;center&#039;)<br /> end<br /> group = group + 1<br /> end<br /> blank = addBlank(offset, <br /> {[&#039;border-width&#039;] = &#039;0&#039;,<br /> [&#039;border-style&#039;] = &#039;solid&#039;,<br /> [&#039;border-color&#039;] = &#039;inherit&#039;},<br /> height, 1)<br /> else<br /> blank = addBlank(offset, <br /> {[&#039;border-width&#039;] = &#039;0&#039;,<br /> [&#039;border-style&#039;] = &#039;solid&#039;,<br /> [&#039;border-color&#039;] = &#039;inherit&#039;},<br /> height, tonumber(hideSeeds and &#039;3&#039; or &#039;4&#039;) + 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 &#039;0&#039; or &#039;2px&#039;)<br /> if hideteam then<br /> addBlank(j, nil, (not compact) and 2 or nil, tonumber(hideSeeds and &#039;1&#039; or &#039;2&#039;) + 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 &#039;0&#039; or &#039;2px&#039;)<br /> if not topTeam then topPair = not topPair end<br /> if not topPair and r &lt; maxround and (not (hiderightpath or hideteam)) then<br /> if blank then blank:css(&#039;border-right-width&#039;, &#039;2px&#039;) end<br /> rightPath:css(&#039;border-right-width&#039;, &#039;2px&#039;)<br /> end<br /> if compactFinal and (r == maxround) then<br /> local prop = (team == 1) and &#039;border-bottom-width&#039; or &#039;border-top-width&#039;<br /> rightPath:css(&#039;border-right-width&#039;, &#039;2px&#039;)<br /> :css(prop, &#039;2px&#039;)<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[&#039;RD&#039; .. (round) .. &#039;-RD&#039; .. (round + 1) .. &#039;-path&#039;]) or 2) .. &#039;px&#039;<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 = &#039;RD&#039; .. round .. &#039;-group&#039; .. group<br /> addBlank(i, {[&#039;height&#039;] = &#039;7px&#039;})<br /> addBlank(i+1, {[&#039;height&#039;] = &#039;7px&#039;})<br /> addBlank(i, {[&#039;text-align&#039;] = &#039;center&#039;}, 2, offset-2)<br /> :wikitext(args[name])<br /> :newline()<br /> if (round &lt;= byes) then<br /> team = i/(step/2)<br /> w = isHidden(round, 2*team-1) and isHidden(round, 2*team) and &#039;0&#039; or wdef<br /> end<br /> if (round &lt; maxround) then<br /> addBlank(i, {<br /> [&#039;border-color&#039;] = &#039;inherit&#039;,<br /> [&#039;border-style&#039;] = &#039;solid&#039;, <br /> [&#039;border-width&#039;] = &#039;0 &#039; .. w .. &#039; 0 0&#039;})<br /> else<br /> addBlank(i)<br /> end<br /> if (round &lt;= byes) then<br /> team = team + 1<br /> w = isHidden(round, 2*team-1) and isHidden(round, 2*team) and &#039;0&#039; or wdef<br /> end<br /> if (round &lt; maxround) then<br /> addBlank(i+1, {<br /> [&#039;border-color&#039;] = &#039;inherit&#039;,<br /> [&#039;border-style&#039;] = &#039;solid&#039;, <br /> [&#039;border-width&#039;] = &#039;0 &#039; .. w .. &#039; 0 0&#039;})<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 &lt; 2 then<br /> offset = compact and 4 or 7<br /> elseif rounds &lt; 3 then<br /> offset = compact and 6 or 10<br /> elseif rounds &lt; 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 &lt; 2 then<br /> blank = addBlank(k-1, {[&#039;height&#039;] = &#039;7px&#039;})<br /> end<br /> blank = addBlank(k, rounds &lt; 2 and {[&#039;height&#039;] = &#039;7px&#039;} or nil)<br /> addHeading(row, rounds + 1, args[&#039;3rd&#039;] or &#039;Third place&#039;)<br /> if rounds &lt; 2 then<br /> for i = 1,(compact and 1 or 2) do<br /> blank = addBlank(k+i, {[&#039;height&#039;] = &#039;7px&#039;})<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 &lt; 2 and {[&#039;height&#039;] = &#039;7px&#039;} or nil)<br /> if row then<br /> renderTeam(row, rounds + 1, i, i == 1, false)<br /> end<br /> if rounds &lt; 2 and not compact then<br /> blank = addBlank(k+1, {[&#039;height&#039;] = &#039;7px&#039;})<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 &gt; 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 &lt;= byes then<br /> hideteam = isHidden(r, team)<br /> end<br /> if (r == 1) and (RD1seedmap[team] &lt;= 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[&#039;RD&#039; .. r .. &#039;-group&#039; .. 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 &gt; 1) then<br /> local blank = addBlank(i, nil, 1, tonumber(hideSeeds and &#039;3&#039; or &#039;4&#039;) + legs[1])<br /> if compact and (rounds &gt; 2) then<br /> blank = addBlank(i, nil, 1, tonumber(hideSeeds and &#039;3&#039; or &#039;4&#039;) + 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(&#039;table&#039;))<br /> local widthRow = addTableRow(tbl)<br /> for r = 1, (compactFinal and (maxround-1) or maxround) do<br /> titleRow:tag(&#039;td&#039;)<br /> widthRow:tag(&#039;td&#039;):css(&#039;width&#039;, r &gt; 1 and &#039;5px&#039; or &#039;1px&#039;)<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(&#039;td&#039;):css(&#039;width&#039;, getWidth(&#039;seed&#039;, &#039;25px&#039;))<br /> end<br /> local teamCell = widthRow:tag(&#039;td&#039;):css(&#039;width&#039;, getWidth(&#039;team&#039;, &#039;150px&#039;))<br /> local scoreCells = {}<br /> local legsr = legs[r]<br /> if compactFinal and r == (maxround-1) then<br /> legsr = legs[r+1] &gt; legs[r] and legs[r+1] or legs[r]<br /> end<br /> for s = 1, legsr do<br /> local score_width = &#039;25px&#039;<br /> if aggregate and aggregate ~= &#039;&#039; and s &gt; 1 and s == legsr then<br /> score_width = getWidth(&#039;agg&#039;, getWidth(&#039;score&#039;, score_width))<br /> else<br /> score_width = getWidth(&#039;score&#039;, score_width)<br /> end<br /> scoreCells[s] = widthRow:tag(&#039;td&#039;):css(&#039;width&#039;, score_width)<br /> end<br /> titleRow:tag(&#039;td&#039;)<br /> widthRow:tag(&#039;td&#039;):css(&#039;width&#039;, r &lt; rounds and &#039;5px&#039; or &#039;1px&#039;)<br /> <br /> if compact then<br /> teamCell:css(&#039;height&#039;, &#039;7px&#039;)<br /> else<br /> if seedCell then<br /> seedCell:wikitext(&#039;&amp;nbsp;&#039;)<br /> end<br /> teamCell:wikitext(&#039;&amp;nbsp;&#039;)<br /> for s = 1, legs[r] do<br /> scoreCells[s]:wikitext(&#039;&amp;nbsp;&#039;)<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[&#039;compact&#039;] == &#039;yes&#039; or args[&#039;compact&#039;] == &#039;y&#039;)<br /> compactFinal = ((rounds &gt; 4) and compact and args[&#039;compact-final&#039;] and (args[&#039;compact-final&#039;] == &#039;yes&#039; or args[&#039;compact-final&#039;] == &#039;y&#039;))<br /> sepwidth = tonumber(args[&#039;sepwidth&#039;] or ((args.sets or args.legs) and 1) or (compact and 1) or 2) or 1<br /> aggregate = (args[&#039;aggregate&#039;] or &#039;&#039;):lower()<br /> aggsep = args[&#039;aggsep&#039;] or args[&#039;aggregate&#039;]<br /> boldwinner = args[&#039;boldwinner&#039;] or args[&#039;bold_winner&#039;] or &#039;&#039;<br /> local autoSeeds = (args[&#039;autoseeds&#039;] == &#039;yes&#039; or args[&#039;autoseeds&#039;] == &#039;y&#039;)<br /> hideSeeds = (args[&#039;seeds&#039;] == &#039;no&#039; or args[&#039;seeds&#039;] == &#039;n&#039;)<br /> showSeeds = (args[&#039;seeds&#039;] == &#039;yes&#039; or args[&#039;seeds&#039;] == &#039;y&#039;)<br /> byes = (args[&#039;byes&#039;] and (args[&#039;byes&#039;] == &#039;yes&#039; or args[&#039;byes&#039;] == &#039;y&#039;) and 1) or (tonumber(args[&#039;byes&#039;] or &#039;0&#039;) or 0)<br /> hideomittedscores = (args[&#039;hideomittedscores&#039;] and (args[&#039;hideomittedscores&#039;] == &#039;yes&#039; or args[&#039;hideomittedscores&#039;] == &#039;y&#039;) and 1) or (tonumber(args[&#039;hideomittedscores&#039;] or &#039;0&#039;) or 0)<br /> hideHeadings = (args[&#039;headings&#039;] == &#039;no&#039; or args[&#039;headings&#039;] == &#039;n&#039;)<br /> showThird = isnotblank(args[&#039;3rd&#039;]) or isnotblank(args[&#039;3rd-team1&#039;]) or isnotblank(args[&#039;3rd-team2&#039;])<br /> local align = (args[&#039;float&#039;] or args[&#039;align&#039;] or &#039;&#039;):lower()<br /> local clear = args[&#039;clear&#039;] or &#039;none&#039;<br /> parseSeedmap(args[&#039;RD1-omit&#039;])<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, &#039;seed&#039;, i)<br /> args[argname] = args[argname] or seeds[i]<br /> end<br /> end<br /> <br /> -- create the table<br /> local tbl = mw.html.create(&#039;table&#039;)<br /> :css(&#039;border-style&#039;, &#039;none&#039;)<br /> :css(&#039;font-size&#039;, &#039;90%&#039;)<br /> :css(&#039;border-collapse&#039;, &#039;separate&#039;)<br /> :css(&#039;border-spacing&#039;, &#039;0&#039;)<br /> :attr(&#039;cellpadding&#039;, &#039;0&#039;)<br /> <br /> if (args[&#039;nowrap&#039;] and (args[&#039;nowrap&#039;] == &#039;yes&#039; or args[&#039;nowrap&#039;] == &#039;y&#039;)) then<br /> tbl:css(&#039;white-space&#039;, &#039;nowrap&#039;)<br /> end<br /> <br /> if align == &#039;right&#039; then<br /> tbl:css(&#039;float&#039;, &#039;right&#039;)<br /> if clear ~= &#039;none&#039; and clear ~= &#039;no&#039; and clear ~= &#039;n&#039; then<br /> tbl:css(&#039;clear&#039;, &#039;right&#039;)<br /> end<br /> tbl:css(&#039;margin&#039;, &#039;1em 0 1em 2em&#039;)<br /> elseif align == &#039;left&#039; then<br /> tbl:css(&#039;float&#039;, &#039;left&#039;)<br /> if clear ~= &#039;none&#039; and clear ~= &#039;no&#039; and clear ~= &#039;n&#039; then<br /> tbl:css(&#039;clear&#039;, &#039;left&#039;)<br /> end<br /> tbl:css(&#039;margin&#039;, &#039;1em 2em 1em 0&#039;)<br /> elseif align == &#039;center&#039; or align == &#039;centre&#039; then<br /> tbl:css(&#039;margin&#039;, &#039;1em auto&#039;)<br /> else<br /> tbl:css(&#039;margin&#039;, &#039;1em 2em 1em 1em&#039;)<br /> end<br /> <br /> renderHeadings(tbl)<br /> renderTree(tbl)<br /> if (args[&#039;wide&#039;] and (args[&#039;wide&#039;] == &#039;y&#039; or args[&#039;wide&#039;] == &#039;yes&#039;)) then<br /> return &#039;&lt;div class=&quot;noresize&quot; style=&quot;overflow:auto&quot;&gt;&#039; .. tostring(tbl) .. &#039;&lt;/div&gt;&#039; .. 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