Bug fix for dygraph point selection touch event.
[dygraphs.git] / tests / interaction.js
index 1449e71..6ce65a8 100644 (file)
@@ -1,3 +1,6 @@
+// Code for a variety of interaction models. Used in interaction.html, but split out from
+// that file so they can be tested in isolation.
+//
 function downV3(event, g, context) {
   context.initializeMouseDown(event, g, context);
   if (event.altKey || event.shiftKey) {
@@ -59,6 +62,12 @@ function offsetToPercentage(g, offsetX, offsetY) {
 function dblClickV3(event, g, context) {
   // Reducing by 20% makes it 80% the original size, which means
   // to restore to original size it must grow by 25%
+
+  if (!(event.offsetX && event.offsetY)){
+    event.offsetX = event.layerX - event.target.offsetLeft;
+    event.offsetY = event.layerY - event.target.offsetTop;
+  }
+
   var percentages = offsetToPercentage(g, event.offsetX, event.offsetY);
   var xPct = percentages[0];
   var yPct = percentages[1];
@@ -70,18 +79,35 @@ function dblClickV3(event, g, context) {
   }
 }
 
+var lastClickedGraph = null;
+
+function clickV3(event, g, context) {
+  lastClickedGraph = g;
+  event.preventDefault();
+  event.stopPropagation();
+}
+
 function scrollV3(event, g, context) {
+  if (lastClickedGraph != g) {
+    return;
+  }
   var normal = event.detail ? event.detail * -1 : event.wheelDelta / 40;
   // For me the normalized value shows 0.075 for one click. If I took
   // that verbatim, it would be a 7.5%.
   var percentage = normal / 50;
 
+  if (!(event.offsetX && event.offsetY)){
+    event.offsetX = event.layerX - event.target.offsetLeft;
+    event.offsetY = event.layerY - event.target.offsetTop;
+  }
+
   var percentages = offsetToPercentage(g, event.offsetX, event.offsetY);
   var xPct = percentages[0];
   var yPct = percentages[1];
 
   zoom(g, percentage, xPct, yPct);
-  Dygraph.cancelEvent(event);
+  event.preventDefault();
+  event.stopPropagation();
 }
 
 // Adjusts [x, y] toward each other by zoomInPercentage%
@@ -125,8 +151,9 @@ function moveV4(event, g, context) {
   var RANGE = 7;
 
   if (v4Active) {
-    var canvasx = Dygraph.pageX(event) - Dygraph.findPosX(g.graphDiv);
-    var canvasy = Dygraph.pageY(event) - Dygraph.findPosY(g.graphDiv);
+    var graphPos = Dygraph.findPos(g.graphDiv);
+    var canvasx = Dygraph.pageX(event) - graphPos.x;
+    var canvasy = Dygraph.pageY(event) - graphPos.y;
 
     var rows = g.numRows();
     // Row layout:
@@ -171,7 +198,7 @@ function upV4(event, g, context) {
 }
 
 function dblClickV4(event, g, context) {
-  restorePositioning(g4);
+  restorePositioning(g);
 }
 
 function drawV4(x, y) {