Fix bug 153, findPosX and findPosY don't take borders into account. This also fixes...
authorRobert Konigsberg <konigsberg@gmail.com>
Sat, 9 Feb 2013 05:17:32 +0000 (00:17 -0500)
committerRobert Konigsberg <konigsberg@gmail.com>
Sat, 9 Feb 2013 05:17:32 +0000 (00:17 -0500)
dygraph-utils.js
dygraph.js

index d2051bf..0e8cf23 100644 (file)
@@ -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;
index 5b00632..a02d919 100644 (file)
@@ -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];
+  }
 };
 
 /**