Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing issue with no legend showing for touch events. #723

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/dygraph-interaction-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,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) {
Expand Down Expand Up @@ -474,6 +476,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++) {
Expand Down Expand Up @@ -580,6 +585,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.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 @@ -193,6 +193,7 @@ Dygraph.findPos = function(obj) {
* @private
*/
Dygraph.pageX = function(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 @@ -205,6 +206,7 @@ Dygraph.pageX = function(e) {
* @private
*/
Dygraph.pageY = function(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