diff --git a/app.js b/app.js index f8338bc..0797f9a 100644 --- a/app.js +++ b/app.js @@ -14,6 +14,21 @@ function updateCenterLabel(month, amount, category = null) { labelEl.querySelector('.center-category').textContent = category || ''; labelEl.querySelector('.center-amount-num').textContent = formatRUB(amount); labelEl.querySelector('.center-rub').textContent = '\u202F₽'; + + // Show/hide home icon based on drill-down state + updateDrilledDownState(); +} + +// Update drilled-down visual state (home icon visibility) +function updateDrilledDownState() { + const labelEl = document.getElementById('center-label'); + if (!labelEl) return; + + if (historyIndex > 0) { + labelEl.classList.add('drilled-down'); + } else { + labelEl.classList.remove('drilled-down'); + } } // Initialize the chart @@ -1434,6 +1449,16 @@ async function loadAvailableMonths() { selectMonth(currentMonthIndex + 1); } }); + + // Set up home icon click handler (go back to root) + const homeIcon = document.querySelector('.center-home'); + if (homeIcon) { + homeIcon.addEventListener('click', () => { + if (historyIndex > 0) { + history.back(); + } + }); + } } // Transform children data for drill-down (extracted from click handler) diff --git a/index.html b/index.html index ca0d1f3..4f7879a 100644 --- a/index.html +++ b/index.html @@ -23,6 +23,12 @@
+
+ + + + +
diff --git a/styles.css b/styles.css index 40e913d..1a4fe33 100644 --- a/styles.css +++ b/styles.css @@ -176,6 +176,29 @@ body { display: none; } +.center-home { + display: none; + justify-content: center; + margin-bottom: 4px; + pointer-events: auto; + cursor: pointer; +} + +.center-home svg { + width: 20px; + height: 20px; + color: #666; + transition: color 0.2s; +} + +.center-home:hover svg { + color: #000; +} + +.center-label.drilled-down .center-home { + display: flex; +} + .center-amount { font-size: 22px; font-weight: 700; @@ -364,6 +387,17 @@ body { display: none; } + /* Still show home icon on narrow screens when drilled down */ + .center-label.drilled-down { + display: block; + } + + .center-label.drilled-down .center-month, + .center-label.drilled-down .center-category, + .center-label.drilled-down .center-amount { + display: none; + } + .chart-eye-btn { display: none !important; }