diff --git a/app.js b/app.js index 13e2021..4846d1f 100644 --- a/app.js +++ b/app.js @@ -73,6 +73,16 @@ function navigateForward() { } } +// Go directly to root level +function goToRoot() { + if (drillDownHistory.length > 0 && historyIndex > 0) { + historyIndex = 0; + navigateToHistoryState(drillDownHistory[0]); + // Update browser history to reflect root state + history.replaceState({ drillDown: 0 }, ''); + } +} + // Listen for browser back/forward via popstate window.addEventListener('popstate', function(e) { // If a modal is open, close it and push state back to prevent navigation @@ -1602,9 +1612,16 @@ function navigateToPath(sunburstData, path) { // Select and load a specific month async function selectMonth(index) { - currentMonthIndex = index; const month = availableMonths[index]; + // If clicking on the already-selected month while drilled down, reset to root + if (index === currentMonthIndex && currentDrillPath.length > 0) { + goToRoot(); + return; + } + + currentMonthIndex = index; + // Update hidden select for compatibility const select = document.getElementById('month-select'); select.value = month;