From deaf6d87f6f920d959b33a22750aae02c2fcf47c Mon Sep 17 00:00:00 2001 From: Richard Shine Date: Mon, 13 Apr 2020 14:08:42 +0100 Subject: [PATCH] Have added pinch zoom ux #990, fix mobile device. --- src/dygraph-interaction-model.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/dygraph-interaction-model.js b/src/dygraph-interaction-model.js index 8d644aa22..a50795f7e 100644 --- a/src/dygraph-interaction-model.js +++ b/src/dygraph-interaction-model.js @@ -418,12 +418,13 @@ DygraphInteraction.startTouch = function(event, g, context) { var touches = []; for (var i = 0; i < event.touches.length; i++) { var t = event.touches[i]; + var rect = t.target.getBoundingClientRect(); // we dispense with 'dragGetX_' because all touchBrowsers support pageX touches.push({ pageX: t.pageX, pageY: t.pageY, - dataX: g.toDataXCoord(t.pageX), - dataY: g.toDataYCoord(t.pageY) + dataX: g.toDataXCoord(t.clientX-rect.left), + dataY: g.toDataYCoord(t.clientY-rect.top) // identifier: t.identifier }); } @@ -536,8 +537,8 @@ DygraphInteraction.moveTouch = function(event, g, context) { var didZoom = false; if (context.touchDirections.x) { g.dateWindow_ = [ - c_init.dataX - swipe.dataX + (context.initialRange.x[0] - c_init.dataX) / xScale, - c_init.dataX - swipe.dataX + (context.initialRange.x[1] - c_init.dataX) / xScale + c_init.dataX - swipe.dataX / xScale + (context.initialRange.x[0] - c_init.dataX) / xScale, + c_init.dataX - swipe.dataX / xScale + (context.initialRange.x[1] - c_init.dataX) / xScale ]; didZoom = true; } @@ -550,8 +551,8 @@ DygraphInteraction.moveTouch = function(event, g, context) { // TODO(danvk): implement } else { axis.valueRange = [ - c_init.dataY - swipe.dataY + (context.initialRange.y[0] - c_init.dataY) / yScale, - c_init.dataY - swipe.dataY + (context.initialRange.y[1] - c_init.dataY) / yScale + c_init.dataY - swipe.dataY / yScale + (context.initialRange.y[0] - c_init.dataY) / yScale, + c_init.dataY - swipe.dataY / yScale + (context.initialRange.y[1] - c_init.dataY) / yScale ]; didZoom = true; } @@ -591,9 +592,6 @@ DygraphInteraction.endTouch = function(event, g, context) { // no double-tap, pan or pinch so its a touchover event.isTouchOver = true; g.mouseMoveHandler_(event); - // g.mousemove(event);f - - }