From 7775fca8b30bf3089749da9e66e448f4f05e98fe Mon Sep 17 00:00:00 2001 From: Kyle Baggott Date: Mon, 1 Feb 2016 21:29:35 +0000 Subject: [PATCH 1/5] Saving the lastTouch to check for a "touchOVER" Saving the lastTouch and looking to see if other functions wipe it before passing a special param to tell the other functions that it's a touchOVER. --- src/dygraph-interaction-model.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/dygraph-interaction-model.js b/src/dygraph-interaction-model.js index 53e2f44d5..3347f06eb 100644 --- a/src/dygraph-interaction-model.js +++ b/src/dygraph-interaction-model.js @@ -414,6 +414,9 @@ Dygraph.Interaction.startTouch = function(event, g, context) { context.startTimeForDoubleTapMs = null; } + // save the last touch to check if it's a touchOVER + context.lastTouch = event; + var touches = []; for (var i = 0; i < event.touches.length; i++) { var t = event.touches[i]; @@ -474,6 +477,9 @@ Dygraph.Interaction.startTouch = function(event, g, context) { Dygraph.Interaction.moveTouch = function(event, g, context) { // If the tap moves, then it's definitely not part of a double-tap. context.startTimeForDoubleTapMs = null; + + // clear the last touch if it's doing something else + context.lastTouch = null; var i, touches = []; for (i = 0; i < event.touches.length; i++) { @@ -580,6 +586,13 @@ Dygraph.Interaction.endTouch = function(event, g, context) { context.doubleTapY && Math.abs(context.doubleTapY - t.screenY) < 50) { g.resetZoom(); } else { + + if (context.lastTouch !== null){ + // no double-tap, pan or pinch so it's a touchOVER + event.isLastTouch = true; + g.mouseMove(event); + } + context.startTimeForDoubleTapMs = now; context.doubleTapX = t.screenX; context.doubleTapY = t.screenY; From 3ca097d85f74f7c126ae73b6c520a4e49f94dc20 Mon Sep 17 00:00:00 2001 From: Kyle Baggott Date: Mon, 1 Feb 2016 21:33:34 +0000 Subject: [PATCH 2/5] Renaming the event to touchOVER as it makes more sense --- src/dygraph-interaction-model.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dygraph-interaction-model.js b/src/dygraph-interaction-model.js index 3347f06eb..6cc5ed1a3 100644 --- a/src/dygraph-interaction-model.js +++ b/src/dygraph-interaction-model.js @@ -589,7 +589,7 @@ Dygraph.Interaction.endTouch = function(event, g, context) { if (context.lastTouch !== null){ // no double-tap, pan or pinch so it's a touchOVER - event.isLastTouch = true; + event.isTouchOver = true; g.mouseMove(event); } From 83008f0ac1a69feb8a23d489cd706b464e69646b Mon Sep 17 00:00:00 2001 From: Kyle Baggott Date: Mon, 1 Feb 2016 21:38:56 +0000 Subject: [PATCH 3/5] Adding touchOVER check to the pageX/Y Adding touchOVER check to the pageX/Y as it only exists under touches for touch events. --- src/dygraph-utils.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/dygraph-utils.js b/src/dygraph-utils.js index a960ba7ae..682c4410c 100644 --- a/src/dygraph-utils.js +++ b/src/dygraph-utils.js @@ -193,6 +193,7 @@ Dygraph.findPos = function(obj) { * @private */ Dygraph.pageX = function(e) { + if (e.isTouchOver) return (!e.touches[0] || e.touches[0].pageX < 0) ? 0 : e.touches[0].pageX; return (!e.pageX || e.pageX < 0) ? 0 : e.pageX; }; @@ -205,6 +206,7 @@ Dygraph.pageX = function(e) { * @private */ Dygraph.pageY = function(e) { + if (e.isTouchOver) return (!e.touches[0] || e.touches[0].pageY < 0) ? 0 : e.touches[0].pageY; return (!e.pageY || e.pageY < 0) ? 0 : e.pageY; }; From 86ca574eef14ff7a301df9ceae0393c94ec9157a Mon Sep 17 00:00:00 2001 From: Kyle Baggott Date: Tue, 2 Feb 2016 10:38:40 +0000 Subject: [PATCH 4/5] moving the lastTouch save into the "one touch" more efficient --- src/dygraph-interaction-model.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/dygraph-interaction-model.js b/src/dygraph-interaction-model.js index 6cc5ed1a3..411aae491 100644 --- a/src/dygraph-interaction-model.js +++ b/src/dygraph-interaction-model.js @@ -414,9 +414,6 @@ Dygraph.Interaction.startTouch = function(event, g, context) { context.startTimeForDoubleTapMs = null; } - // save the last touch to check if it's a touchOVER - context.lastTouch = event; - var touches = []; for (var i = 0; i < event.touches.length; i++) { var t = event.touches[i]; @@ -432,7 +429,9 @@ Dygraph.Interaction.startTouch = function(event, g, context) { context.initialTouches = touches; if (touches.length == 1) { - // This is just a swipe. + // This is possbily a touchOVER, save the last touch to check + context.lastTouch = event; + // or This is just a swipe. context.initialPinchCenter = touches[0]; context.touchDirections = { x: true, y: true }; } else if (touches.length >= 2) { From 7a180bd1f113816214c5ed5d90b4a9314658c940 Mon Sep 17 00:00:00 2001 From: Kyle Baggott Date: Tue, 2 Feb 2016 10:55:20 +0000 Subject: [PATCH 5/5] using changedTouches instead of touches In testing on different devices it seems changedTouches is better supported cross platform, using this instead of the the touches object. Roughly tested on iOS and Android. --- src/dygraph-utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dygraph-utils.js b/src/dygraph-utils.js index 682c4410c..63be1d1bf 100644 --- a/src/dygraph-utils.js +++ b/src/dygraph-utils.js @@ -193,7 +193,7 @@ Dygraph.findPos = function(obj) { * @private */ Dygraph.pageX = function(e) { - if (e.isTouchOver) return (!e.touches[0] || e.touches[0].pageX < 0) ? 0 : e.touches[0].pageX; + if (e.isTouchOver) return (!e.changedTouches[0] || e.changedTouches[0].pageX < 0) ? 0 : e.changedTouches[0].pageX; return (!e.pageX || e.pageX < 0) ? 0 : e.pageX; }; @@ -206,7 +206,7 @@ Dygraph.pageX = function(e) { * @private */ Dygraph.pageY = function(e) { - if (e.isTouchOver) return (!e.touches[0] || e.touches[0].pageY < 0) ? 0 : e.touches[0].pageY; + if (e.isTouchOver) return (!e.changedTouches[0] || e.changedTouches[0].pageY < 0) ? 0 : e.changedTouches[0].pageY; return (!e.pageY || e.pageY < 0) ? 0 : e.pageY; };