From b9b516595572bfcd2883698d4272f050d76340e9 Mon Sep 17 00:00:00 2001 From: Tuukka Ikkala <10980802+ikkala@users.noreply.github.com> Date: Fri, 14 Jul 2023 10:50:13 +0300 Subject: [PATCH 1/3] Don't trigger the zoom on legends area Fixes chartjs#256 --- src/handlers.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/handlers.js b/src/handlers.js index af1e63ae..5d699f5c 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) { @@ -58,6 +58,12 @@ function zoomStart(chart, event, zoomOptions) { } export function mouseDown(chart, event) { + const rect = event.target.getBoundingClientRect(); + const offsetX = event.clientX - rect.left; + const offsetY = event.clientY - rect.top; + if (chart.legend && _isPointInArea({x: offsetX, y: offsetY}, chart.legend)) { + return; + } const state = getState(chart); const {pan: panOptions, zoom: zoomOptions = {}} = state.options; if ( From e1cd506986ef410b12d7de9381b9ac5ec40ef27e Mon Sep 17 00:00:00 2001 From: Tuukka Ikkala <10980802+ikkala@users.noreply.github.com> Date: Fri, 15 Nov 2024 22:21:59 +0200 Subject: [PATCH 2/3] Make cleaner, suggested by @kurkle Co-authored-by: Jukka Kurkela --- src/handlers.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/handlers.js b/src/handlers.js index 5d699f5c..224f72eb 100644 --- a/src/handlers.js +++ b/src/handlers.js @@ -58,12 +58,12 @@ function zoomStart(chart, event, zoomOptions) { } export function mouseDown(chart, event) { - const rect = event.target.getBoundingClientRect(); - const offsetX = event.clientX - rect.left; - const offsetY = event.clientY - rect.top; - if (chart.legend && _isPointInArea({x: offsetX, y: offsetY}, chart.legend)) { + 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 ( From 26d3176389870a582f75559bf2c73865eb73ee9e Mon Sep 17 00:00:00 2001 From: Jukka Kurkela Date: Sat, 16 Nov 2024 09:34:57 +0200 Subject: [PATCH 3/3] fix: lint --- src/handlers.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/handlers.js b/src/handlers.js index 224f72eb..832122d3 100644 --- a/src/handlers.js +++ b/src/handlers.js @@ -61,9 +61,9 @@ export function mouseDown(chart, event) { if (chart.legend) { const point = getRelativePosition(event, chart); if (_isPointInArea(point, chart.legend)) { - return; + return; } - } + } const state = getState(chart); const {pan: panOptions, zoom: zoomOptions = {}} = state.options; if (