|
|
|
@ -20,6 +20,7 @@ |
|
|
|
data-disabled="{{ match.disabled|lower }}" |
|
|
|
data-disabled="{{ match.disabled|lower }}" |
|
|
|
data-match-group-name="{{ match_group.name }}" |
|
|
|
data-match-group-name="{{ match_group.name }}" |
|
|
|
data-match-format="{{ match.format }}" |
|
|
|
data-match-format="{{ match.format }}" |
|
|
|
|
|
|
|
data-round-id="{{ match_group.round_id }}" |
|
|
|
class="match-template"> |
|
|
|
class="match-template"> |
|
|
|
{% include 'tournaments/bracket_match_cell.html' %} |
|
|
|
{% include 'tournaments/bracket_match_cell.html' %} |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
@ -29,13 +30,15 @@ |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
<script> |
|
|
|
<script> |
|
|
|
|
|
|
|
const tournamentId = "{{ tournament.id }}"; |
|
|
|
|
|
|
|
|
|
|
|
function renderBracket() { |
|
|
|
function renderBracket() { |
|
|
|
const bracket = document.getElementById('bracket'); |
|
|
|
const bracket = document.getElementById('bracket'); |
|
|
|
const matchTemplates = document.getElementById('match-templates').children; |
|
|
|
const matchTemplates = document.getElementById('match-templates').children; |
|
|
|
const rounds = []; |
|
|
|
const rounds = []; |
|
|
|
const matchPositions = []; |
|
|
|
const matchPositions = []; |
|
|
|
|
|
|
|
const doubleButterflyMode = {{ double_butterfly_mode|lower }}; |
|
|
|
|
|
|
|
const displayLoserFinal = {{ display_loser_final|lower }}; |
|
|
|
|
|
|
|
|
|
|
|
// Group matches by round |
|
|
|
// Group matches by round |
|
|
|
Array.from(matchTemplates).forEach(template => { |
|
|
|
Array.from(matchTemplates).forEach(template => { |
|
|
|
@ -56,7 +59,10 @@ function renderBracket() { |
|
|
|
const baseDistance = matchHeight + matchSpacing; |
|
|
|
const baseDistance = matchHeight + matchSpacing; |
|
|
|
bracket.innerHTML = ''; |
|
|
|
bracket.innerHTML = ''; |
|
|
|
const roundCount = rounds.length; |
|
|
|
const roundCount = rounds.length; |
|
|
|
const finalRoundIndex = (roundCount - 1) / 2; |
|
|
|
let finalRoundIndex = (roundCount - 1); |
|
|
|
|
|
|
|
if (doubleButterflyMode == true) { |
|
|
|
|
|
|
|
finalRoundIndex = finalRoundIndex / 2; |
|
|
|
|
|
|
|
} |
|
|
|
let nextMatchDistance = baseDistance; |
|
|
|
let nextMatchDistance = baseDistance; |
|
|
|
let minimumMatchDistance = 1; |
|
|
|
let minimumMatchDistance = 1; |
|
|
|
|
|
|
|
|
|
|
|
@ -77,10 +83,22 @@ function renderBracket() { |
|
|
|
const firstMatchTemplate = roundMatches[0].closest('.match-template'); |
|
|
|
const firstMatchTemplate = roundMatches[0].closest('.match-template'); |
|
|
|
const matchGroupName = firstMatchTemplate.dataset.matchGroupName; |
|
|
|
const matchGroupName = firstMatchTemplate.dataset.matchGroupName; |
|
|
|
const matchFormat = firstMatchTemplate.dataset.matchFormat; |
|
|
|
const matchFormat = firstMatchTemplate.dataset.matchFormat; |
|
|
|
|
|
|
|
const roundId = firstMatchTemplate.dataset.roundId; // Add this line |
|
|
|
|
|
|
|
|
|
|
|
const nameSpan = document.createElement('div'); |
|
|
|
let nameSpan = document.createElement('div'); |
|
|
|
nameSpan.className = 'round-name'; |
|
|
|
nameSpan.className = 'round-name'; |
|
|
|
nameSpan.textContent = matchGroupName; |
|
|
|
nameSpan.textContent = matchGroupName; |
|
|
|
|
|
|
|
if (roundIndex == finalRoundIndex) { |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
nameSpan = document.createElement('a'); |
|
|
|
|
|
|
|
nameSpan.className = 'round-name btn small-button'; |
|
|
|
|
|
|
|
nameSpan.textContent = matchGroupName; |
|
|
|
|
|
|
|
if (roundId) { |
|
|
|
|
|
|
|
nameSpan.href = `/tournament/${tournamentId}/round/${roundId}/bracket/`; |
|
|
|
|
|
|
|
nameSpan.style.cursor = 'pointer'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
nameSpan.style.textDecoration = 'None'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const formatSpan = document.createElement('div'); |
|
|
|
const formatSpan = document.createElement('div'); |
|
|
|
formatSpan.className = 'round-format'; |
|
|
|
formatSpan.className = 'round-format'; |
|
|
|
@ -92,13 +110,13 @@ function renderBracket() { |
|
|
|
// Create matches container |
|
|
|
// Create matches container |
|
|
|
const matchesContainer = document.createElement('div'); |
|
|
|
const matchesContainer = document.createElement('div'); |
|
|
|
matchesContainer.className = 'matches-container'; |
|
|
|
matchesContainer.className = 'matches-container'; |
|
|
|
if (roundIndex >= finalRoundIndex - 1) { |
|
|
|
if (roundCount > 5 && doubleButterflyMode == true) { |
|
|
|
if (roundCount > 5) { |
|
|
|
if (roundIndex >= finalRoundIndex - 1) { |
|
|
|
matchesContainer.style.transform = `translateX(-50%)`; |
|
|
|
matchesContainer.style.transform = `translateX(-50%)`; |
|
|
|
if (roundIndex >= finalRoundIndex + 2) { |
|
|
|
if (roundIndex >= finalRoundIndex + 2) { |
|
|
|
matchesContainer.style.transform = `translateX(-100%)`; |
|
|
|
matchesContainer.style.transform = `translateX(-100%)`; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
roundDiv.appendChild(matchesContainer); |
|
|
|
roundDiv.appendChild(matchesContainer); |
|
|
|
|
|
|
|
|
|
|
|
@ -119,27 +137,51 @@ function renderBracket() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (roundIndex === 0) { |
|
|
|
if (roundIndex === 0) { |
|
|
|
const nextMatchesCount = rounds[roundIndex + 1].length; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (currentMatchesCount == nextMatchesCount) { |
|
|
|
if (roundCount > 1) { |
|
|
|
|
|
|
|
const nextMatchesCount = rounds[roundIndex + 1].length; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (currentMatchesCount == nextMatchesCount) { |
|
|
|
|
|
|
|
nextMatchDistance = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
nextMatchDistance = 0; |
|
|
|
nextMatchDistance = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
top = matchIndex * (matchHeight + matchSpacing) * minimumMatchDistance; |
|
|
|
top = matchIndex * (matchHeight + matchSpacing) * minimumMatchDistance; |
|
|
|
} else if (roundIndex === roundCount - 1) { |
|
|
|
|
|
|
|
|
|
|
|
if (roundCount == 3 && doubleButterflyMode) { |
|
|
|
|
|
|
|
top = top + (matchHeight + matchSpacing) / 2 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if (roundIndex === roundCount - 1 && doubleButterflyMode == true) { |
|
|
|
const nextMatchesCount = rounds[roundIndex - 1].length; |
|
|
|
const nextMatchesCount = rounds[roundIndex - 1].length; |
|
|
|
if (currentMatchesCount == nextMatchesCount) { |
|
|
|
if (currentMatchesCount == nextMatchesCount) { |
|
|
|
nextMatchDistance = 0; |
|
|
|
nextMatchDistance = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (roundIndex == finalRoundIndex) { |
|
|
|
} else if (roundIndex == finalRoundIndex) { |
|
|
|
|
|
|
|
if (doubleButterflyMode == true) { |
|
|
|
let lgth = matchPositions[0].length / 2; |
|
|
|
let lgth = matchPositions[0].length / 2; |
|
|
|
let index = lgth + matchIndex - 1; |
|
|
|
let index = lgth + matchIndex - 1; |
|
|
|
// If index goes negative, use 0 instead |
|
|
|
// If index goes negative, use 0 instead |
|
|
|
if (matchIndex == 0) { |
|
|
|
if (displayLoserFinal == true) { |
|
|
|
top = matchPositions[roundIndex - 1][0] - baseDistance / 2; |
|
|
|
if (matchIndex == 0) { |
|
|
|
|
|
|
|
top = matchPositions[roundIndex - 1][0] - baseDistance / 2; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
top = matchPositions[roundIndex - 1][0] + baseDistance / 2; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
nextMatchDistance = baseDistance; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
top = matchPositions[roundIndex - 1][0] + baseDistance / 2; |
|
|
|
top = matchPositions[roundIndex - 1][0]; |
|
|
|
|
|
|
|
nextMatchDistance = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
nextMatchDistance = baseDistance; |
|
|
|
} else { |
|
|
|
|
|
|
|
const parentIndex1 = matchIndex * 2; |
|
|
|
|
|
|
|
const parentIndex2 = parentIndex1 + 1; |
|
|
|
|
|
|
|
const parentPos1 = matchPositions[roundIndex - 1][parentIndex1]; |
|
|
|
|
|
|
|
const parentPos2 = matchPositions[roundIndex - 1][parentIndex2]; |
|
|
|
|
|
|
|
top = (parentPos1 + parentPos2) / 2; |
|
|
|
|
|
|
|
nextMatchDistance = 0; |
|
|
|
|
|
|
|
} |
|
|
|
} else if (roundIndex < finalRoundIndex) { |
|
|
|
} else if (roundIndex < finalRoundIndex) { |
|
|
|
const previousMatchesCount = rounds[roundIndex - 1].length; |
|
|
|
const previousMatchesCount = rounds[roundIndex - 1].length; |
|
|
|
const nextMatchesCount = rounds[roundIndex + 1].length; |
|
|
|
const nextMatchesCount = rounds[roundIndex + 1].length; |
|
|
|
@ -172,8 +214,8 @@ function renderBracket() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (roundIndex >= finalRoundIndex - 2) { |
|
|
|
if (roundCount > 5 && doubleButterflyMode == true) { |
|
|
|
if (roundCount > 5) { |
|
|
|
if (roundIndex >= finalRoundIndex - 2) { |
|
|
|
if (roundIndex == finalRoundIndex - 1) { |
|
|
|
if (roundIndex == finalRoundIndex - 1) { |
|
|
|
matchDiv.classList.add('inward'); |
|
|
|
matchDiv.classList.add('inward'); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -184,11 +226,12 @@ function renderBracket() { |
|
|
|
nextMatchDistance = nextMatchDistance - baseDistance; |
|
|
|
nextMatchDistance = nextMatchDistance - baseDistance; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (roundIndex == finalRoundIndex - 1 || roundIndex == finalRoundIndex + 1) { |
|
|
|
if (displayLoserFinal == true) { |
|
|
|
nextMatchDistance = baseDistance; |
|
|
|
if (doubleButterflyMode == true && (roundIndex == finalRoundIndex - 1 || roundIndex == finalRoundIndex + 1)) { |
|
|
|
|
|
|
|
nextMatchDistance = baseDistance; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
matchDiv.style.setProperty('--next-match-distance', `${nextMatchDistance}px`); |
|
|
|
matchDiv.style.setProperty('--next-match-distance', `${nextMatchDistance}px`); |
|
|
|
@ -212,12 +255,13 @@ function renderBracket() { |
|
|
|
// Position title above the first match |
|
|
|
// Position title above the first match |
|
|
|
titleDiv.style.top = `${top - 80}px`; // Adjust the 60px offset as needed |
|
|
|
titleDiv.style.top = `${top - 80}px`; // Adjust the 60px offset as needed |
|
|
|
titleDiv.style.position = 'absolute'; |
|
|
|
titleDiv.style.position = 'absolute'; |
|
|
|
if (roundIndex == finalRoundIndex - 1) { |
|
|
|
if (roundCount >= 5 && doubleButterflyMode == true) { |
|
|
|
titleDiv.style.marginLeft = '50px'; |
|
|
|
if (roundIndex == finalRoundIndex - 1) { |
|
|
|
} else if (roundIndex == finalRoundIndex + 1) { |
|
|
|
titleDiv.style.marginLeft = '50px'; |
|
|
|
titleDiv.style.marginLeft = '-50px'; |
|
|
|
} else if (roundIndex == finalRoundIndex + 1) { |
|
|
|
|
|
|
|
titleDiv.style.marginLeft = '-50px'; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
matchesContainer.appendChild(titleDiv); |
|
|
|
matchesContainer.appendChild(titleDiv); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -226,7 +270,7 @@ function renderBracket() { |
|
|
|
<div class="match-content ${isDisabled ? 'disabled' : ''}">${matchTemplate.innerHTML}</div> |
|
|
|
<div class="match-content ${isDisabled ? 'disabled' : ''}">${matchTemplate.innerHTML}</div> |
|
|
|
`; |
|
|
|
`; |
|
|
|
|
|
|
|
|
|
|
|
if (roundIndex == finalRoundIndex - 1) { |
|
|
|
if (roundIndex == finalRoundIndex - 1 && displayLoserFinal == true) { |
|
|
|
const matchDiv2 = document.createElement('div'); |
|
|
|
const matchDiv2 = document.createElement('div'); |
|
|
|
matchDiv2.className = 'butterfly-match'; |
|
|
|
matchDiv2.className = 'butterfly-match'; |
|
|
|
matchDiv2.classList.add('inward'); |
|
|
|
matchDiv2.classList.add('inward'); |
|
|
|
@ -295,8 +339,13 @@ function renderBracket() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.round-name { |
|
|
|
.round-name { |
|
|
|
font-size: 1.5em; /* Make the round name bigger */ |
|
|
|
font-size: 1.5em; |
|
|
|
margin-bottom: 5px; |
|
|
|
margin-bottom: 5px; |
|
|
|
|
|
|
|
transition: color 0.2s; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.round-name a:hover { |
|
|
|
|
|
|
|
color: orange; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.round-format { |
|
|
|
.round-format { |
|
|
|
|