From 4c794cbb8df260aa2b35d96d77af2f6705284f7e Mon Sep 17 00:00:00 2001 From: Tuukka Ikkala <10980802+ikkala@users.noreply.github.com> Date: Sat, 16 Nov 2024 09:37:55 +0200 Subject: [PATCH] Don't trigger the zoom on legends area (#772) * Don't trigger the zoom on legends area Fixes chartjs#256 * Make cleaner, suggested by @kurkle Co-authored-by: Jukka Kurkela * fix: lint --------- Co-authored-by: Jukka Kurkela --- src/handlers.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/handlers.js b/src/handlers.js index f9c195c2..9c11851c 100644 --- a/src/handlers.js +++ b/src/handlers.js @@ -1,6 +1,6 @@ import {directionEnabled, debounce, keyNotPressed, getModifierKey, keyPressed} from './utils'; import {zoom, zoomRect} from './core'; -import {callback as call, getRelativePosition} from 'chart.js/helpers'; +import {callback as call, getRelativePosition, _isPointInArea} from 'chart.js/helpers'; import {getState} from './state'; function removeHandler(chart, type) { @@ -61,6 +61,12 @@ function zoomStart(chart, event, zoomOptions) { } export function mouseDown(chart, event) { + if (chart.legend) { + const point = getRelativePosition(event, chart); + if (_isPointInArea(point, chart.legend)) { + return; + } + } const state = getState(chart); const {pan: panOptions, zoom: zoomOptions = {}} = state.options; if (