Skip to content

Commit

Permalink
Don't trigger zoom outside the area of chart lines/bars
Browse files Browse the repository at this point in the history
If user starts mouse down for example in area of legends or axis the zoom starts. This fix limits the starting of zooming to the area of the actual graph.

Fixes chartjs#256
  • Loading branch information
Tuukka Ikkala committed May 7, 2020
1 parent 2fd819f commit 1d23a4e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,13 @@ var zoomPlugin = {
var panThreshold = options.pan && options.pan.threshold;

chartInstance.$zoom._mouseDownHandler = function(event) {
node.addEventListener('mousemove', chartInstance.$zoom._mouseMoveHandler);
chartInstance.$zoom._dragZoomStart = event;
var rect = event.target.getBoundingClientRect();
var offsetX = event.clientX - rect.left;
var offsetY = event.clientY - rect.top;
if (helpers.canvas._isPointInArea({x: offsetX, y: offsetY }, chartInstance.chartArea)) {
node.addEventListener('mousemove', chartInstance.$zoom._mouseMoveHandler);
chartInstance.$zoom._dragZoomStart = event;
}
};

chartInstance.$zoom._mouseMoveHandler = function(event) {
Expand Down

0 comments on commit 1d23a4e

Please sign in to comment.