From 3e0726d34fa17ae87bc225cf2fc21f0e43cbc4cd Mon Sep 17 00:00:00 2001 From: Anton Volnuhin Date: Sat, 31 Jan 2026 18:52:30 +0300 Subject: [PATCH] Add click-on-same-month to exit drill-down Clicking on the already-selected month button now returns to root view when drilled down, providing a quick way to reset the chart without using browser back or center click. Co-Authored-By: Claude Opus 4.5 --- app.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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;