Add Escape key to reset timeline legend filter

Extract resetLegendSelection into a reusable function exposed via
window._timelineResetLegend, allowing both the reset button click
and the Escape key handler to clear legend filtering.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Anton Volnuhin 2026-02-07 18:15:54 +03:00
parent 7e477269c0
commit 646c5959d1

30
app.js
View File

@ -754,6 +754,7 @@ function renderTimelineChart(drillPath, historyAction, legendSelected) {
drillPath = drillPath || []; drillPath = drillPath || [];
historyAction = historyAction || 'push'; historyAction = historyAction || 'push';
timelineDrillPath = drillPath; timelineDrillPath = drillPath;
window._timelineResetLegend = null;
myChart.off('click'); myChart.off('click');
myChart.off('mouseover'); myChart.off('mouseover');
@ -896,6 +897,19 @@ function renderTimelineChart(drillPath, historyAction, legendSelected) {
resetTop = nextRowTop + 11; resetTop = nextRowTop + 11;
} }
const resetLegendSelection = function() {
window._suppressLegendHistory = true;
allNames.forEach(name => {
myChart.dispatchAction({ type: 'legendSelect', name: name });
});
window._suppressLegendHistory = false;
const resetSelected = {};
allNames.forEach(name => { resetSelected[name] = true; });
updateTotalsAndResetBtn(resetSelected);
history.pushState({ timelineDrill: drillPath }, '');
};
window._timelineResetLegend = allSelected ? null : resetLegendSelection;
const resetGraphic = { const resetGraphic = {
type: 'text', type: 'text',
id: 'resetBtn', id: 'resetBtn',
@ -915,17 +929,7 @@ function renderTimelineChart(drillPath, historyAction, legendSelected) {
onmouseout: function() { onmouseout: function() {
if (this && this.setStyle) this.setStyle({ fill: '#999' }); if (this && this.setStyle) this.setStyle({ fill: '#999' });
}, },
onclick: function() { onclick: resetLegendSelection
window._suppressLegendHistory = true;
allNames.forEach(name => {
myChart.dispatchAction({ type: 'legendSelect', name: name });
});
window._suppressLegendHistory = false;
const resetSelected = {};
allNames.forEach(name => { resetSelected[name] = true; });
updateTotalsAndResetBtn(resetSelected);
history.pushState({ timelineDrill: drillPath }, '');
}
}; };
if (resetLeft !== null) { if (resetLeft !== null) {
resetGraphic.left = resetLeft + resetXOffset; resetGraphic.left = resetLeft + resetXOffset;
@ -1044,6 +1048,7 @@ function switchView(viewName) {
requestAnimationFrame(() => myChart.resize()); requestAnimationFrame(() => myChart.resize());
} else { } else {
container.classList.remove('timeline-mode'); container.classList.remove('timeline-mode');
window._timelineResetLegend = null;
// Remove all chart event listeners // Remove all chart event listeners
myChart.off('click'); myChart.off('click');
myChart.off('mouseover'); myChart.off('mouseover');
@ -3616,6 +3621,9 @@ function handleGlobalEscape(e) {
closeRowDetailModal(); closeRowDetailModal();
} else if (transactionModal.style.display !== 'none') { } else if (transactionModal.style.display !== 'none') {
closeTransactionModal(); closeTransactionModal();
} else if (currentView === 'timeline' && typeof window._timelineResetLegend === 'function') {
window._timelineResetLegend();
e.preventDefault();
} }
} }
} }