Skip to content

Commit

Permalink
Merge branch 'PR723'
Browse files Browse the repository at this point in the history
This merges changes by @kbaggott in danvk/dygraphs PR danvk#723,
to allow points to be selected (and thus legends to show up)
on touchscreens.
  • Loading branch information
adrianiainlam committed Jul 31, 2018
2 parents da2a028 + 7a180bd commit 91e3b7f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/dygraph-interaction-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,9 @@ DygraphInteraction.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) {
Expand Down Expand Up @@ -475,6 +477,9 @@ DygraphInteraction.startTouch = function(event, g, context) {
DygraphInteraction.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++) {
Expand Down Expand Up @@ -581,6 +586,13 @@ DygraphInteraction.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.isTouchOver = true;
g.mouseMove(event);
}

context.startTimeForDoubleTapMs = now;
context.doubleTapX = t.screenX;
context.doubleTapY = t.screenY;
Expand Down
2 changes: 2 additions & 0 deletions src/dygraph-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export function findPos(obj) {
* @private
*/
export function pageX(e) {
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;
};

Expand All @@ -211,6 +212,7 @@ export function pageX(e) {
* @private
*/
export function pageY(e) {
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;
};

Expand Down

0 comments on commit 91e3b7f

Please sign in to comment.