Skip to content

Commit

Permalink
Merge pull request #48 from niutski/master
Browse files Browse the repository at this point in the history
#38: Fix drag zoom inaccuracy by offsetting X coordinates
  • Loading branch information
etimberg authored Oct 18, 2016
2 parents a3abfe7 + 4db7b64 commit 212782f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
10 changes: 6 additions & 4 deletions Chart.Zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,9 @@ var zoomPlugin = {
var chartArea = chartInstance.chartArea;
var yAxis = getYAxis(chartInstance);
var beginPoint = chartInstance._dragZoomStart;
var startX = Math.min(beginPoint.x, event.x) ;
var endX = Math.max(beginPoint.x, event.x);
var offsetX = beginPoint.target.getBoundingClientRect().left;
var startX = Math.min(beginPoint.x, event.x) - offsetX;
var endX = Math.max(beginPoint.x, event.x) - offsetX;
var dragDistance = endX - startX;
var chartDistance = chartArea.right - chartArea.left;
var zoom = 1 + ((chartDistance - dragDistance) / chartDistance );
Expand Down Expand Up @@ -429,8 +430,9 @@ var zoomPlugin = {
var yAxis = getYAxis(chartInstance);
var beginPoint = chartInstance._dragZoomStart;
var endPoint = chartInstance._dragZoomEnd;
var startX = Math.min(beginPoint.x, endPoint.x);
var endX = Math.max(beginPoint.x, endPoint.x);
var offsetX = beginPoint.target.getBoundingClientRect().left;
var startX = Math.min(beginPoint.x, endPoint.x) - offsetX;
var endX = Math.max(beginPoint.x, endPoint.x) - offsetX;
var rectWidth = endX - startX;


Expand Down
2 changes: 1 addition & 1 deletion Chart.Zoom.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions src/chart.zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,9 @@ var zoomPlugin = {
var chartArea = chartInstance.chartArea;
var yAxis = getYAxis(chartInstance);
var beginPoint = chartInstance._dragZoomStart;
var startX = Math.min(beginPoint.x, event.x) ;
var endX = Math.max(beginPoint.x, event.x);
var offsetX = beginPoint.target.getBoundingClientRect().left;
var startX = Math.min(beginPoint.x, event.x) - offsetX;
var endX = Math.max(beginPoint.x, event.x) - offsetX;
var dragDistance = endX - startX;
var chartDistance = chartArea.right - chartArea.left;
var zoom = 1 + ((chartDistance - dragDistance) / chartDistance );
Expand Down Expand Up @@ -417,8 +418,9 @@ var zoomPlugin = {
var yAxis = getYAxis(chartInstance);
var beginPoint = chartInstance._dragZoomStart;
var endPoint = chartInstance._dragZoomEnd;
var startX = Math.min(beginPoint.x, endPoint.x);
var endX = Math.max(beginPoint.x, endPoint.x);
var offsetX = beginPoint.target.getBoundingClientRect().left;
var startX = Math.min(beginPoint.x, endPoint.x) - offsetX;
var endX = Math.max(beginPoint.x, endPoint.x) - offsetX;
var rectWidth = endX - startX;


Expand Down

0 comments on commit 212782f

Please sign in to comment.