From 2fd819f24f47601caa2603a265dcceb60de451e8 Mon Sep 17 00:00:00 2001 From: Tuukka Ikkala Date: Fri, 8 May 2020 00:06:42 +0300 Subject: [PATCH] Fix: Honor zoom.mode (xy/x/y) when applying zoom.threshold Enhances https://github.com/chartjs/chartjs-plugin-zoom/issues/317 --- src/plugin.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/plugin.js b/src/plugin.js index 092159554..a73b877fb 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -482,20 +482,24 @@ var zoomPlugin = { chartInstance.$zoom._dragZoomStart = null; chartInstance.$zoom._dragZoomEnd = null; + var zoomOptions = chartInstance.$zoom._options.zoom; + var xEnabled = directionEnabled(zoomOptions.mode, 'x', chartInstance); + var yEnabled = directionEnabled(zoomOptions.mode, 'y', chartInstance); + var zoomThreshold = options.zoom && options.zoom.threshold || 0; - if (dragDistanceX <= zoomThreshold && dragDistanceY <= zoomThreshold) { + if (xEnabled && dragDistanceX <= zoomThreshold) { + return; + } + if (yEnabled && dragDistanceY <= zoomThreshold) { return; } var chartArea = chartInstance.chartArea; - var zoomOptions = chartInstance.$zoom._options.zoom; var chartDistanceX = chartArea.right - chartArea.left; - var xEnabled = directionEnabled(zoomOptions.mode, 'x', chartInstance); var zoomX = xEnabled && dragDistanceX ? 1 + ((chartDistanceX - dragDistanceX) / chartDistanceX) : 1; var chartDistanceY = chartArea.bottom - chartArea.top; - var yEnabled = directionEnabled(zoomOptions.mode, 'y', chartInstance); var zoomY = yEnabled && dragDistanceY ? 1 + ((chartDistanceY - dragDistanceY) / chartDistanceY) : 1; doZoom(chartInstance, zoomX, zoomY, {