From: Robert Konigsberg Date: Sat, 9 Feb 2013 05:17:32 +0000 (-0500) Subject: Fix bug 153, findPosX and findPosY don't take borders into account. This also fixes... X-Git-Tag: v1.0.0~85^2 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=abc8c570a4aac8be7ff4fb266e6e410b768277be;p=dygraphs.git Fix bug 153, findPosX and findPosY don't take borders into account. This also fixes the zoom operation when the graph is surrounded by something with a border. --- diff --git a/dygraph-utils.js b/dygraph-utils.js index d2051bf..0e8cf23 100644 --- a/dygraph-utils.js +++ b/dygraph-utils.js @@ -291,6 +291,8 @@ Dygraph.findPosX = function(obj) { if(obj.offsetParent) { var copyObj = obj; while(1) { + var borderLeft = getComputedStyle(copyObj).borderLeft || "0"; + curleft += parseInt(borderLeft, 10) ; curleft += copyObj.offsetLeft; if(!copyObj.offsetParent) { break; @@ -322,6 +324,8 @@ Dygraph.findPosY = function(obj) { if(obj.offsetParent) { var copyObj = obj; while(1) { + var borderTop = getComputedStyle(copyObj).borderTop || "0"; + curtop += parseInt(borderTop, 10) ; curtop += copyObj.offsetTop; if(!copyObj.offsetParent) { break; diff --git a/dygraph.js b/dygraph.js index 5b00632..a02d919 100644 --- a/dygraph.js +++ b/dygraph.js @@ -1621,9 +1621,13 @@ Dygraph.prototype.getArea = function() { * Returns a two-element array: [X, Y]. */ Dygraph.prototype.eventToDomCoords = function(event) { - var canvasx = Dygraph.pageX(event) - Dygraph.findPosX(this.mouseEventElement_); - var canvasy = Dygraph.pageY(event) - Dygraph.findPosY(this.mouseEventElement_); - return [canvasx, canvasy]; + if (event.offsetX && event.offsetY) { + return [ event.offsetX, event.offsetY ]; + } else { + var canvasx = Dygraph.pageX(event) - Dygraph.findPosX(this.mouseEventElement_); + var canvasy = Dygraph.pageY(event) - Dygraph.findPosY(this.mouseEventElement_); + return [canvasx, canvasy]; + } }; /**