From ec079e1a7ab09f9078b9fde7a4d1fd9effeb58e7 Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Fri, 24 Oct 2025 08:28:44 +0200 Subject: [PATCH] Add debug logging to Round and Tournament Bracket fix annelise issue with match hide state detection --- tournaments/models/round.py | 68 +++++- .../tournaments/js/tournament_bracket.js | 213 +++++++++++++----- 2 files changed, 221 insertions(+), 60 deletions(-) diff --git a/tournaments/models/round.py b/tournaments/models/round.py index 65dda76..021a9ba 100644 --- a/tournaments/models/round.py +++ b/tournaments/models/round.py @@ -13,6 +13,15 @@ class Round(TournamentSubModel): group_stage_loser_bracket = models.BooleanField(default=False) loser_bracket_mode = models.IntegerField(default=0) + # Debug flag - set to False to disable all debug prints + DEBUG_PREPARE_MATCH_GROUP = False + + @staticmethod + def debug_print(*args, **kwargs): + """Print debug messages only if DEBUG_PREPARE_MATCH_GROUP is True""" + if Round.DEBUG_PREPARE_MATCH_GROUP: + print(*args, **kwargs) + def delete_dependencies(self): for round in self.children.all(): round.delete_dependencies() @@ -112,19 +121,35 @@ class Round(TournamentSubModel): return True def prepare_match_group(self, next_round, parent_round, loser_final, double_butterfly_mode, secondHalf): + Round.debug_print(f"\n[{self.name()}] === START prepare_match_group ===") + Round.debug_print(f"[{self.name()}] index={self.index}, nextRound={next_round.name() if next_round else None}, parentRound={parent_round.name() if parent_round else None}") + Round.debug_print(f"[{self.name()}] loserFinal={loser_final.name() if loser_final else None}, doubleButterfly={double_butterfly_mode}, secondHalf={secondHalf}") + short_names = double_butterfly_mode if double_butterfly_mode and self.tournament.rounds.filter(parent=None).count() < 3: short_names = False + Round.debug_print(f"[{self.name()}] Short names disabled (rounds < 3)") + matches = self.matches.filter(disabled=False).order_by('index') + Round.debug_print(f"[{self.name()}] Initial enabled matches: {len(matches)} - indices: {[m.index for m in matches]}") + if len(matches) == 0: + Round.debug_print(f"[{self.name()}] No matches, returning None") return None + if next_round: next_round_matches = next_round.matches.filter(disabled=False).order_by('index') + Round.debug_print(f"[{self.name()}] Next round matches: {len(next_round_matches)} - indices: {[m.index for m in next_round_matches]}") else: next_round_matches = [] + Round.debug_print(f"[{self.name()}] No next round") if len(matches) < len(next_round_matches): + Round.debug_print(f"[{self.name()}] FILTERING: matches({len(matches)}) < nextRoundMatches({len(next_round_matches)})") + all_matches = self.matches.order_by('index') + Round.debug_print(f"[{self.name()}] All matches (including disabled): {len(all_matches)} - indices: {[(m.index, m.disabled) for m in all_matches]}") + filtered_matches = [] # Process matches in pairs @@ -134,30 +159,43 @@ class Round(TournamentSubModel): current_match = all_matches[i] pair_match = all_matches[i+1] if i+1 < len(all_matches) else None + Round.debug_print(f"[{self.name()}] Pair {i//2}: current={current_match.index}(disabled={current_match.disabled}), pair={pair_match.index if pair_match else None}(disabled={pair_match.disabled if pair_match else None})") + # Only filter out the pair if both matches are disabled if current_match.disabled and pair_match and pair_match.disabled: + Round.debug_print(f"[{self.name()}] Both disabled, checking next_round for index {current_match.index // 2}") # Skip one of the matches in the pair if next_round_matches.filter(index=current_match.index // 2).exists(): filtered_matches.append(current_match) - filtered_matches.append(pair_match) - pass + # filtered_matches.append(pair_match) + # Keeping two was bugging the bracket + Round.debug_print(f"[{self.name()}] Next round match exists, keeping one") + else: + Round.debug_print(f"[{self.name()}] No next round match, skipping both") else: # Keep the current match if current_match.disabled == False: filtered_matches.append(current_match) + Round.debug_print(f"[{self.name()}] Keeping current match {current_match.index}") # If there's a pair match, keep it too if pair_match and pair_match.disabled == False: filtered_matches.append(pair_match) + Round.debug_print(f"[{self.name()}] Keeping pair match {pair_match.index}") # Move to the next pair i += 2 # Replace the matches list with our filtered list matches = filtered_matches + Round.debug_print(f"[{self.name()}] After filtering: {len(matches)} matches - indices: {[m.index for m in matches]}") if matches: if len(matches) > 1 and double_butterfly_mode: + Round.debug_print(f"[{self.name()}] SPLITTING: doubleButterfly with {len(matches)} matches") + if len(matches) % 2 == 1: + Round.debug_print(f"[{self.name()}] ODD number of matches - using smart split logic") + # Calculate expected index range for this round if self.index == 0: # Final: only index 0 @@ -168,47 +206,71 @@ class Round(TournamentSubModel): start_index = (2 ** self.index) - 1 expected_indices = list(range(start_index, start_index + expected_count)) + Round.debug_print(f"[{self.name()}] Expected indices: {expected_indices}") + # Get actual match indices actual_indices = [match.index for match in matches] missing_indices = [idx for idx in expected_indices if idx not in actual_indices] + Round.debug_print(f"[{self.name()}] Actual indices: {actual_indices}") + Round.debug_print(f"[{self.name()}] Missing indices: {missing_indices}") if missing_indices and len(expected_indices) > 1: # Split the expected range in half midpoint_index = len(expected_indices) // 2 first_half_expected = expected_indices[:midpoint_index] second_half_expected = expected_indices[midpoint_index:] + Round.debug_print(f"[{self.name()}] Expected halves: first={first_half_expected}, second={second_half_expected}") # Count actual matches in each theoretical half first_half_actual = sum(1 for idx in actual_indices if idx in first_half_expected) second_half_actual = sum(1 for idx in actual_indices if idx in second_half_expected) + Round.debug_print(f"[{self.name()}] Actual counts: first={first_half_actual}, second={second_half_actual}") # Give more display space to the half with more actual matches if first_half_actual > second_half_actual: midpoint = (len(matches) + 1) // 2 # More to first half + Round.debug_print(f"[{self.name()}] First half has more: midpoint={midpoint}") else: midpoint = len(matches) // 2 # More to second half + Round.debug_print(f"[{self.name()}] Second half has more: midpoint={midpoint}") else: # No missing indices or only one expected match, split normally midpoint = len(matches) // 2 + Round.debug_print(f"[{self.name()}] No missing indices: midpoint={midpoint}") else: # Even number of matches: split evenly midpoint = len(matches) // 2 + Round.debug_print(f"[{self.name()}] EVEN number of matches: midpoint={midpoint}") first_half_matches = matches[:midpoint] if secondHalf: first_half_matches = matches[midpoint:] + Round.debug_print(f"[{self.name()}] Using SECOND half: {len(first_half_matches)} matches - indices: {[m.index for m in first_half_matches]}") + else: + Round.debug_print(f"[{self.name()}] Using FIRST half: {len(first_half_matches)} matches - indices: {[m.index for m in first_half_matches]}") else: + Round.debug_print(f"[{self.name()}] NO SPLITTING: singleButterfly or single match") first_half_matches = list(matches) # Convert QuerySet to a list + Round.debug_print(f"[{self.name()}] Using all {len(first_half_matches)} matches - indices: {[m.index for m in first_half_matches]}") + if self.index == 0 and loser_final: loser_match = loser_final.matches.first() if loser_match: first_half_matches.append(loser_match) + Round.debug_print(f"[{self.name()}] Added loser final match: {loser_match.index}") if first_half_matches: name = self.plural_name() if parent_round and first_half_matches[0].name is not None: name = first_half_matches[0].name + Round.debug_print(f"[{self.name()}] Using custom name from first match: '{name}'") + else: + Round.debug_print(f"[{self.name()}] Using round name: '{name}'") + + Round.debug_print(f"[{self.name()}] Creating match_group: name='{name}', roundId={self.id}, roundIndex={self.index}, shortNames={short_names}") + Round.debug_print(f"[{self.name()}] Final matches in group: {[m.index for m in first_half_matches]}") + match_group = self.tournament.create_match_group( name=name, matches=first_half_matches, @@ -216,6 +278,8 @@ class Round(TournamentSubModel): round_index=self.index, short_names=short_names ) + Round.debug_print(f"[{self.name()}] === END prepare_match_group - SUCCESS ===\n") return match_group + Round.debug_print(f"[{self.name()}] === END prepare_match_group - NO MATCHES ===\n") return None diff --git a/tournaments/static/tournaments/js/tournament_bracket.js b/tournaments/static/tournaments/js/tournament_bracket.js index 98516ca..7881500 100644 --- a/tournaments/static/tournaments/js/tournament_bracket.js +++ b/tournaments/static/tournaments/js/tournament_bracket.js @@ -1,3 +1,12 @@ +// Debug flag - set to false to disable all debug console logs +const DEBUG_BRACKET = false; + +function debug_console(...args) { + if (DEBUG_BRACKET) { + console.log(...args); + } +} + function renderBracket(options) { const bracket = document.getElementById("bracket"); const matchTemplates = document.getElementById("match-templates").children; @@ -8,6 +17,12 @@ function renderBracket(options) { const displayLoserFinal = options.displayLoserFinal; const tournamentId = options.tournamentId; const isBroadcast = options.isBroadcast; + + debug_console("=== RENDER BRACKET START ==="); + debug_console( + `Options: doubleButterflyMode=${doubleButterflyMode}, displayLoserFinal=${displayLoserFinal}, isBroadcast=${isBroadcast}`, + ); + // Group matches by round Array.from(matchTemplates).forEach((template) => { const roundIndex = parseInt(template.dataset.matchRound); @@ -34,6 +49,10 @@ function renderBracket(options) { let nextMatchDistance = baseDistance; let minimumMatchDistance = 1; + debug_console( + `Dimensions: matchHeight=${matchHeight}, baseDistance=${baseDistance}, roundCount=${roundCount}, finalRoundIndex=${finalRoundIndex}`, + ); + const screenWidth = window.innerWidth; let roundTotalCount = roundCount; let initialPadding = 40; @@ -41,7 +60,7 @@ function renderBracket(options) { roundTotalCount = roundCount - 1; initialPadding = 46; } - const padding = initialPadding * roundTotalCount; // Account for some padding/margin + const padding = initialPadding * roundTotalCount; const availableWidth = screenWidth - padding; let responsiveMatchWidth = Math.min( 365, @@ -82,6 +101,10 @@ function renderBracket(options) { } } + debug_console( + `Layout: responsiveMatchWidth=${responsiveMatchWidth}, topMargin=${topMargin}`, + ); + rounds.forEach((roundMatches, roundIndex) => { if (rounds[0].length <= 2 && doubleButterflyMode) { minimumMatchDistance = 2; @@ -108,8 +131,13 @@ function renderBracket(options) { const firstMatchTemplate = roundMatches[0].closest(".match-template"); const matchGroupName = firstMatchTemplate.dataset.matchGroupName; const matchFormat = firstMatchTemplate.dataset.matchFormat; - const roundId = firstMatchTemplate.dataset.roundId; // Add this line - const realRoundIndex = firstMatchTemplate.dataset.roundIndex; // Add this line + const roundId = firstMatchTemplate.dataset.roundId; + const realRoundIndex = firstMatchTemplate.dataset.roundIndex; + + debug_console(`\n=== ROUND ${roundIndex} (${matchGroupName}) ===`); + debug_console( + `realRoundIndex=${realRoundIndex}, matches=${roundMatches.length}`, + ); let nameSpan = document.createElement("div"); nameSpan.className = "round-name"; @@ -145,10 +173,16 @@ function renderBracket(options) { if (matchPositions[roundIndex] == undefined) { matchPositions[roundIndex] = {}; } - matchDisabled[roundIndex] = []; // Initialize array for this round + matchDisabled[roundIndex] = []; + roundMatches.forEach((matchTemplate, matchIndex) => { const matchTitle = matchTemplate.dataset.matchTitle; const matchRealIndex = matchTemplate.dataset.matchRealIndex; + + debug_console( + `\n[${matchTitle}] START - roundIndex:${roundIndex}, matchIndex:${matchIndex}, realIndex:${matchRealIndex}`, + ); + const matchDiv = document.createElement("div"); matchDiv.className = "butterfly-match"; @@ -159,7 +193,11 @@ function renderBracket(options) { let isOutgoingLineIsDisabled = isDisabled; let top; const currentMatchesCount = roundMatches.length; + if (roundIndex > finalRoundIndex) { + debug_console( + `[${matchTitle}] CASE: Reverse bracket (roundIndex > finalRoundIndex)`, + ); matchDiv.classList.add("reverse-bracket"); if (roundIndex <= finalRoundIndex + 2) { @@ -167,18 +205,29 @@ function renderBracket(options) { matchPositions[roundCount - roundIndex - 1], ); top = values[matchIndex]; + debug_console( + `[${matchTitle}] Reverse pos from mirror: top=${top}, mirrorRound=${roundCount - roundIndex - 1}`, + ); } else { top = matchPositions[roundIndex][matchRealIndex]; - console.log(matchTitle, top); + debug_console(`[${matchTitle}] Reverse pos direct: top=${top}`); } } if (roundIndex === 0) { + debug_console(`[${matchTitle}] CASE: First round (roundIndex === 0)`); + if (doubleButterflyMode == false) { nextMatchDistance = 0; + debug_console( + `[${matchTitle}] Single butterfly: nextMatchDistance=0`, + ); } else { if (realRoundIndex > 1) { nextMatchDistance = 0; + debug_console( + `[${matchTitle}] Double butterfly realRound>1: nextMatchDistance=0`, + ); } } if (roundCount > 1) { @@ -186,53 +235,85 @@ function renderBracket(options) { if (currentMatchesCount == nextMatchesCount && roundCount > 2) { nextMatchDistance = 0; + debug_console( + `[${matchTitle}] Same match count: nextMatchDistance=0`, + ); } } top = matchIndex * (matchHeight + matchSpacing) * minimumMatchDistance; + debug_console( + `[${matchTitle}] Calc: top=${top} (matchIdx=${matchIndex}, spacing=${matchHeight + matchSpacing}, minDist=${minimumMatchDistance})`, + ); if (roundCount == 3 && doubleButterflyMode) { top = top + (matchHeight + matchSpacing) / 2; + debug_console(`[${matchTitle}] 3-round adjustment: top=${top}`); } } else if (roundIndex === roundCount - 1 && doubleButterflyMode == true) { + debug_console(`[${matchTitle}] CASE: Last round double butterfly`); + if (roundCount > 3) { nextMatchDistance = 0; + debug_console(`[${matchTitle}] Large bracket: nextMatchDistance=0`); } else { nextMatchDistance = nextMatchDistance / 2; + debug_console( + `[${matchTitle}] Small bracket: nextMatchDistance=${nextMatchDistance}`, + ); } } else if (roundIndex == finalRoundIndex && realRoundIndex == 0) { - //realRoundIndex 0 means final's round + debug_console(`[${matchTitle}] CASE: Final round (realRoundIndex=0)`); + const values = Object.values(matchPositions[roundIndex - 1]); const parentPos1 = values[0]; const parentPos2 = values[1]; + debug_console( + `[${matchTitle}] Parent positions: pos1=${parentPos1}, pos2=${parentPos2}`, + ); if (doubleButterflyMode == true) { + debug_console(`[${matchTitle}] Double butterfly final`); let lgth = matchPositions[0].length / 2; let index = lgth + matchIndex - 1; - // If index goes negative, use 0 instead + if (displayLoserFinal == true) { + debug_console(`[${matchTitle}] With loser final`); if (matchIndex == 0) { top = parentPos1 - baseDistance / 2; + debug_console(`[${matchTitle}] Winner final: top=${top}`); } else { top = parentPos1 + baseDistance / 2; + debug_console(`[${matchTitle}] Loser final: top=${top}`); } nextMatchDistance = 0; } else { top = parentPos1; nextMatchDistance = 0; + debug_console(`[${matchTitle}] Single final: top=${top}`); } } else { + debug_console(`[${matchTitle}] Single butterfly final`); top = (parentPos1 + parentPos2) / 2; + debug_console(`[${matchTitle}] Center between parents: top=${top}`); + if (matchIndex == 0) { nextMatchDistance = parentPos2 - parentPos1; + debug_console( + `[${matchTitle}] First final match: nextMatchDistance=${nextMatchDistance}`, + ); } else { nextMatchDistance = 0; + debug_console( + `[${matchTitle}] Second+ final match: nextMatchDistance=0`, + ); } if (displayLoserFinal == true) { if (matchIndex == 1) { top = matchPositions[roundIndex][0] + baseDistance + 80; isIncomingLineIsDisabled = true; + debug_console(`[${matchTitle}] Loser final offset: top=${top}`); } } } @@ -240,43 +321,72 @@ function renderBracket(options) { (roundIndex == finalRoundIndex && realRoundIndex != 0) || roundIndex < finalRoundIndex ) { + debug_console(`[${matchTitle}] CASE: Intermediate round`); + const parentIndex1 = matchRealIndex * 2 + 1; const parentIndex2 = matchRealIndex * 2 + 2; const parentPos1 = matchPositions[roundIndex - 1][parentIndex1]; const parentPos2 = matchPositions[roundIndex - 1][parentIndex2]; const parent1Disable = matchDisabled[roundIndex - 1][parentIndex1]; const parent2Disable = matchDisabled[roundIndex - 1][parentIndex2]; + + debug_console( + `[${matchTitle}] Parents: idx1=${parentIndex1}(pos=${parentPos1}, disabled=${parent1Disable}), idx2=${parentIndex2}(pos=${parentPos2}, disabled=${parent2Disable})`, + ); + if ( (parent1Disable == undefined || parent1Disable == true) && (parent2Disable == undefined || parent2Disable == true) ) { isIncomingLineIsDisabled = true; + debug_console( + `[${matchTitle}] Both parents disabled, incoming line disabled`, + ); } + if ( matchPositions[roundIndex - 1][parentIndex1] != undefined && matchPositions[roundIndex - 1][parentIndex2] != undefined ) { + debug_console(`[${matchTitle}] Both parents exist`); top = (parentPos1 + parentPos2) / 2; + if (parent1Disable && parent2Disable) { nextMatchDistance = 0; const keys = Object.keys(matchPositions[roundIndex]).map(Number); const lastKey = Math.max(...keys); top = (matchHeight + matchSpacing) * minimumMatchDistance * keys.length; + debug_console( + `[${matchTitle}] Both disabled: top=${top}, nextMatchDistance=0`, + ); } else { nextMatchDistance = parentPos2 - parentPos1; + debug_console( + `[${matchTitle}] Center calc: top=${top}, nextMatchDistance=${nextMatchDistance}`, + ); } } else if (matchPositions[roundIndex - 1][parentIndex1] != undefined) { + debug_console(`[${matchTitle}] Only parent1 exists`); nextMatchDistance = 0; top = matchPositions[roundIndex - 1][parentIndex1]; + debug_console(`[${matchTitle}] Use parent1: top=${top}`); } else if (matchPositions[roundIndex - 1][parentIndex2] != undefined) { + debug_console(`[${matchTitle}] Only parent2 exists`); nextMatchDistance = 0; top = matchPositions[roundIndex - 1][parentIndex2]; + debug_console(`[${matchTitle}] Use parent2: top=${top}`); } else { + debug_console(`[${matchTitle}] No parents exist`); nextMatchDistance = 0; top = 0; + debug_console(`[${matchTitle}] Default: top=0`); } } else if (roundIndex < roundCount) { + debug_console( + `[${matchTitle}] CASE: Setting future positions (roundIndex < roundCount)`, + ); + const parentIndex1 = matchRealIndex * 2 + 1; const parentIndex2 = matchRealIndex * 2 + 2; const parentMatch1 = rounds[roundIndex + 1].find( @@ -286,57 +396,64 @@ function renderBracket(options) { (match) => parseInt(match.dataset.matchRealIndex) === parentIndex2, ); + debug_console( + `[${matchTitle}] Looking for children: idx1=${parentIndex1}, idx2=${parentIndex2}`, + ); + debug_console( + `[${matchTitle}] Found: match1=${parentMatch1?.dataset.matchTitle || "none"}, match2=${parentMatch2?.dataset.matchTitle || "none"}`, + ); + if (matchPositions[roundIndex + 1] == undefined) { matchPositions[roundIndex + 1] = {}; } + if ( parentMatch1 != undefined && parentMatch2 != undefined && parentMatch1.dataset.disabled == "false" && parentMatch2.dataset.disabled == "false" ) { - console.log( - roundIndex, - matchTitle, - parentMatch1.dataset.matchTitle, - parentMatch2.dataset.matchTitle, - parentMatch1.dataset.disabled, - parentMatch2.dataset.disabled, - top, + debug_console( + `[${matchTitle}] Both children active - setting their positions`, ); nextMatchDistance = baseDistance; matchPositions[roundIndex + 1][parentIndex1] = top - baseDistance / 2; matchPositions[roundIndex + 1][parentIndex2] = top + baseDistance / 2; - console.log(matchPositions[roundIndex + 1]); - // } else if (parentMatch1 != undefined) { - // matchPositions[roundIndex + 1][parentIndex1] = top; - // nextMatchDistance = 0; - // } else if (parentMatch2 != undefined) { - // matchPositions[roundIndex + 1][parentIndex1] = top; - // nextMatchDistance = 0; + debug_console( + `[${matchTitle}] Set: [${parentIndex1}]=${matchPositions[roundIndex + 1][parentIndex1]}, [${parentIndex2}]=${matchPositions[roundIndex + 1][parentIndex2]}`, + ); } else if ( parentMatch2 != undefined && parentMatch2.dataset.disabled == "false" ) { + debug_console(`[${matchTitle}] Only child2 active`); if (realRoundIndex == 1 && doubleButterflyMode) { - //if missing match in quarterfinals in double butterfly mode nextMatchDistance = baseDistance; + debug_console( + `[${matchTitle}] Quarterfinal missing match: nextMatchDistance=${baseDistance}`, + ); } else { nextMatchDistance = 0; } matchPositions[roundIndex + 1][parentIndex2] = top; + debug_console(`[${matchTitle}] Set child2: [${parentIndex2}]=${top}`); } else if ( parentMatch1 != undefined && parentMatch1.dataset.disabled == "false" ) { + debug_console(`[${matchTitle}] Only child1 active`); if (realRoundIndex == 1 && doubleButterflyMode) { - //if missing match in quarterfinals in double butterfly mode nextMatchDistance = baseDistance; + debug_console( + `[${matchTitle}] Quarterfinal missing match: nextMatchDistance=${baseDistance}`, + ); } else { nextMatchDistance = 0; } matchPositions[roundIndex + 1][parentIndex1] = top; + debug_console(`[${matchTitle}] Set child1: [${parentIndex1}]=${top}`); } else { + debug_console(`[${matchTitle}] No active children`); isOutgoingLineIsDisabled = true; } } @@ -344,17 +461,24 @@ function renderBracket(options) { if (doubleButterflyMode == true) { if (roundIndex >= finalRoundIndex - 2) { if (roundIndex == finalRoundIndex - 1) { + debug_console(`[${matchTitle}] Semifinal adjustments`); matchDiv.classList.add("reverse-bracket"); isIncomingLineIsDisabled = true; nextMatchDistance = nextMatchDistance / 2; } if (roundIndex == finalRoundIndex + 1) { + debug_console(`[${matchTitle}] Post-final adjustments`); matchDiv.classList.remove("reverse-bracket"); isOutgoingLineIsDisabled = true; nextMatchDistance = nextMatchDistance; } } } + + debug_console( + `[${matchTitle}] FINAL: top=${top}, nextMatchDistance=${nextMatchDistance}, disabled=${isDisabled}`, + ); + matchDiv.style.setProperty( "--semi-final-distance", `${baseDistance / 2.3}px`, @@ -379,25 +503,13 @@ function renderBracket(options) { matchPositions[roundIndex][matchRealIndex] = top; if (matchIndex === 0) { - // // Add logo for final round - // if (roundIndex == finalRoundIndex) { - // const logoDiv = document.createElement('div'); - // logoDiv.className = 'round-logo'; - // const logoImg = document.createElement('img'); - // logoImg.src = '/static/tournaments/images/PadelClub_logo_512.png'; - // logoImg.alt = 'PadelClub Logo'; - // logoDiv.appendChild(logoImg); - // logoDiv.style.transform = `translateX(-50%)`; - // matchesContainer.appendChild(logoDiv); - // } - // Position title above the first match - titleDiv.style.top = `${topMargin - roundTopMargin}px`; // Adjust the 60px offset as needed + titleDiv.style.top = `${topMargin - roundTopMargin}px`; if ( (roundIndex == finalRoundIndex && realRoundIndex == 0) || isBroadcast == true ) { - titleDiv.style.top = `${top + topMargin - roundTopMargin}px`; // Adjust the 60px offset as needed + titleDiv.style.top = `${top + topMargin - roundTopMargin}px`; } titleDiv.style.position = "absolute"; if (roundCount >= 5 && doubleButterflyMode == true) { @@ -436,7 +548,7 @@ function renderBracket(options) { titleDiv.className = "round-title"; titleDiv.appendChild(nameSpan); titleDiv.appendChild(formatSpan); - titleDiv.style.top = `${top + topMargin - 80}px`; // Adjust the 60px offset as needed + titleDiv.style.top = `${top + topMargin - 80}px`; titleDiv.style.position = "absolute"; matchesContainer.appendChild(titleDiv); } @@ -479,24 +591,7 @@ function renderBracket(options) { } } - // if ( - // roundIndex == finalRoundIndex - 1 && - // displayLoserFinal == true && - // doubleButterflyMode == true - // ) { - // const matchDiv2 = document.createElement("div"); - // matchDiv2.className = "butterfly-match"; - // matchDiv2.classList.add("inward"); - // matchDiv2.classList.add("semi-final"); - // matchDiv2.style.setProperty( - // "--next-match-distance", - // `${baseDistance}px`, - // ); - // matchDiv2.style.top = `${top}px`; - // matchDiv2.innerHTML = `
${rounds[0][0].innerHTML}
`; - // matchesContainer.appendChild(matchDiv2); // Append to matchesContainer instead of roundDiv - // } - matchesContainer.appendChild(matchDiv); // Append to matchesContainer instead of roundDiv + matchesContainer.appendChild(matchDiv); }); bracket.appendChild(roundDiv); @@ -549,7 +644,7 @@ function renderBracket(options) { // Create a container that will sit at the same position for all rounds const footerContainer = document.createElement("div"); footerContainer.style.position = "absolute"; - footerContainer.style.top = `${globalMaxBottom}px`; // Same position for all footers + footerContainer.style.top = `${globalMaxBottom}px`; footerContainer.style.width = "100%"; footerContainer.appendChild(footerDiv); @@ -562,4 +657,6 @@ function renderBracket(options) { }); }, 100); } + + debug_console("=== RENDER BRACKET END ===\n"); }