Skip to content

Commit 845bb8f

Browse files
author
Richard Shine
committed
Allow follow legend to work on touchevents mobile devices
1 parent e9155b2 commit 845bb8f

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/dygraph-interaction-model.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,8 @@ DygraphInteraction.startTouch = function(event, g, context) {
430430
context.initialTouches = touches;
431431

432432
if (touches.length == 1) {
433+
// This is possibly a touchOver, save the last touch to check
434+
context.lastTouch = event;
433435
// This is just a swipe.
434436
context.initialPinchCenter = touches[0];
435437
context.touchDirections = { x: true, y: true };
@@ -476,6 +478,9 @@ DygraphInteraction.moveTouch = function(event, g, context) {
476478
// If the tap moves, then it's definitely not part of a double-tap.
477479
context.startTimeForDoubleTapMs = null;
478480

481+
// clear the last touch if it's doing something else
482+
context.lastTouch = null;
483+
479484
var i, touches = [];
480485
for (i = 0; i < event.touches.length; i++) {
481486
var t = event.touches[i];
@@ -581,6 +586,13 @@ DygraphInteraction.endTouch = function(event, g, context) {
581586
context.doubleTapY && Math.abs(context.doubleTapY - t.screenY) < 50) {
582587
g.resetZoom();
583588
} else {
589+
590+
if (context.lastTouch !== null) {
591+
// no double-tap, pan or pinch so its a touchover
592+
event.isTouchOver = true;
593+
g.mousemove(event);
594+
}
595+
584596
context.startTimeForDoubleTapMs = now;
585597
context.doubleTapX = t.screenX;
586598
context.doubleTapY = t.screenY;

src/dygraph-utils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ export function findPos(obj) {
199199
* @private
200200
*/
201201
export function pageX(e) {
202+
if (e.isTouchOver) return (!e.changedTouches[0] || e.changedTouches[0].pageX < 0) ? 0 : e.changedTouches[0].pageX;
202203
return (!e.pageX || e.pageX < 0) ? 0 : e.pageX;
203204
};
204205

@@ -211,6 +212,7 @@ export function pageX(e) {
211212
* @private
212213
*/
213214
export function pageY(e) {
215+
if (e.isTouchOver) return (!e.changedTouches[0] || e.changedTouches[0].pageY < 0) ? 0 : e.changedTouches[0].pageY;
214216
return (!e.pageY || e.pageY < 0) ? 0 : e.pageY;
215217
};
216218

0 commit comments

Comments
 (0)