Skip to content

Commit

Permalink
Fix: Honor zoom.mode (xy/x/y) when applying zoom.threshold
Browse files Browse the repository at this point in the history
Enhances #317
  • Loading branch information
Tuukka Ikkala committed May 7, 2020
1 parent 9fa7036 commit 2fd819f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down

0 comments on commit 2fd819f

Please sign in to comment.