From 457cb0db2059d6634cbbba71aed6a0a220750979 Mon Sep 17 00:00:00 2001 From: andrea Date: Thu, 9 Apr 2020 16:31:26 +0200 Subject: [PATCH 01/13] swip.dataX was not scaled during the pinch. This caused problems (blow ups in the zoom in/out). --- src/dygraph-interaction-model.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/dygraph-interaction-model.js b/src/dygraph-interaction-model.js index 494b63849..cc8157692 100644 --- a/src/dygraph-interaction-model.js +++ b/src/dygraph-interaction-model.js @@ -531,9 +531,10 @@ 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; } @@ -545,8 +546,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; } From 8a7b38c4a6214586d1a1811160d9d8fe7295038b Mon Sep 17 00:00:00 2001 From: andrea Date: Fri, 10 Apr 2020 00:01:10 +0200 Subject: [PATCH 02/13] disallow too small pinches. disable diagonal calculation. --- src/dygraph-interaction-model.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/dygraph-interaction-model.js b/src/dygraph-interaction-model.js index cc8157692..a87861a1d 100644 --- a/src/dygraph-interaction-model.js +++ b/src/dygraph-interaction-model.js @@ -457,8 +457,10 @@ DygraphInteraction.startTouch = function(event, g, context) { if (initialAngle > 90) initialAngle = 90 - initialAngle; context.touchDirections = { - x: (initialAngle < (90 - 45/2)), - y: (initialAngle > 45/2) + //x: (initialAngle < (90 - 45/2)), + // y: (initialAngle > 45/2) + x: true, + y: true }; } @@ -516,18 +518,25 @@ DygraphInteraction.moveTouch = function(event, g, context) { if (touches.length == 1) { xScale = 1.0; yScale = 1.0; - } else if (touches.length >= 2) { + } else { + xScale = 1.0; + yScale = 1.0; var initHalfWidth = (initialTouches[1].pageX - c_init.pageX); - xScale = (touches[1].pageX - c_now.pageX) / initHalfWidth; - var initHalfHeight = (initialTouches[1].pageY - c_init.pageY); - yScale = (touches[1].pageY - c_now.pageY) / initHalfHeight; + if (touches.length >= 2) { + if (Math.abs(initHalfWidth) > 50) + xScale = (touches[1].pageX - c_now.pageX) / initHalfWidth; + + if (Math.abs(initHalfHeight) > 50) + yScale = (touches[1].pageY - c_now.pageY) / initHalfHeight; + } } // Clip scaling to [1/8, 8] to prevent too much blowup. xScale = Math.min(8, Math.max(0.125, xScale)); yScale = Math.min(8, Math.max(0.125, yScale)); + var didZoom = false; if (context.touchDirections.x) { g.dateWindow_ = [ From e404f8ea1ca54757fbc435d2b7cfb80391f4515a Mon Sep 17 00:00:00 2001 From: andrea Date: Fri, 10 Apr 2020 01:15:52 +0200 Subject: [PATCH 03/13] other fixes/hacks for sensitiveness of pinch-zoom --- src/dygraph-interaction-model.js | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/dygraph-interaction-model.js b/src/dygraph-interaction-model.js index a87861a1d..f2f143c70 100644 --- a/src/dygraph-interaction-model.js +++ b/src/dygraph-interaction-model.js @@ -511,6 +511,10 @@ DygraphInteraction.moveTouch = function(event, g, context) { var dataHeight = context.initialRange.y[0] - context.initialRange.y[1]; swipe.dataX = (swipe.pageX / g.plotter_.area.w) * dataWidth; swipe.dataY = (swipe.pageY / g.plotter_.area.h) * dataHeight; + + const xExtremes = g.xAxisExtremes() + const yExtremes = g.yAxisExtremes() + var xScale, yScale; // The residual bits are usually split into scale & rotate bits, but we split @@ -524,11 +528,17 @@ DygraphInteraction.moveTouch = function(event, g, context) { var initHalfWidth = (initialTouches[1].pageX - c_init.pageX); var initHalfHeight = (initialTouches[1].pageY - c_init.pageY); if (touches.length >= 2) { - if (Math.abs(initHalfWidth) > 50) - xScale = (touches[1].pageX - c_now.pageX) / initHalfWidth; + const minAllowed = 50 + if (Math.abs(initHalfWidth) > minAllowed) { + // sensitiveness dampening: smaller pinches count much less + const damp = 1 / (Math.abs(initHalfWidth) - minAllowed) + xScale = (touches[1].pageX - c_now.pageX + damp) / (initHalfWidth + damp); + } - if (Math.abs(initHalfHeight) > 50) - yScale = (touches[1].pageY - c_now.pageY) / initHalfHeight; + if (Math.abs(initHalfHeight) > minAllowed) { + const damp = 1 / (Math.abs(initHalfHeight) - minAllowed) + yScale = (touches[1].pageY - c_now.pageY + damp) / (initHalfHeight + damp); + } } } @@ -543,7 +553,12 @@ DygraphInteraction.moveTouch = function(event, g, context) { 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 ]; - + if (xExtremes[0] < xExtremes[1]) { + if (g.dateWindow_[0] < xExtremes[0]) + g.dateWindow_[0] = xExtremes[0] + if (g.dateWindow_[1] > xExtremes[1]) + g.dateWindow_[1] = xExtremes[1] + } didZoom = true; } @@ -558,6 +573,12 @@ DygraphInteraction.moveTouch = function(event, g, context) { 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 ]; + if (yExtremes[i][0] < yExtremes[i][1]) { + if (axis.valueRange[0] < yExtremes[i][0]) + axis.valueRange[0] = yExtremes[i][0] + if (axis.valueRange[1] > yExtremes[i][1]) + axis.valueRange[1] = yExtremes[i][1] + } didZoom = true; } } From 2ed4ac01d9f186a7e94736fcd1c963fc21bb97c7 Mon Sep 17 00:00:00 2001 From: andrea Date: Fri, 10 Apr 2020 11:29:04 +0200 Subject: [PATCH 04/13] checking if touches >= 2 --- src/dygraph-interaction-model.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/dygraph-interaction-model.js b/src/dygraph-interaction-model.js index f2f143c70..0b937b0c2 100644 --- a/src/dygraph-interaction-model.js +++ b/src/dygraph-interaction-model.js @@ -515,16 +515,11 @@ DygraphInteraction.moveTouch = function(event, g, context) { const xExtremes = g.xAxisExtremes() const yExtremes = g.yAxisExtremes() - var xScale, yScale; + var xScale = 1.0, yScale = 1.0; // The residual bits are usually split into scale & rotate bits, but we split // them into x-scale and y-scale bits. - if (touches.length == 1) { - xScale = 1.0; - yScale = 1.0; - } else { - xScale = 1.0; - yScale = 1.0; + if (touches.length >= 2) { var initHalfWidth = (initialTouches[1].pageX - c_init.pageX); var initHalfHeight = (initialTouches[1].pageY - c_init.pageY); if (touches.length >= 2) { From aafa8e1ddabc8d8639577c6c49cb4ced28c682e9 Mon Sep 17 00:00:00 2001 From: andrea Date: Fri, 10 Apr 2020 21:20:35 +0200 Subject: [PATCH 05/13] context.pinchOutOfExtremes --- src/dygraph-interaction-model.js | 40 ++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/src/dygraph-interaction-model.js b/src/dygraph-interaction-model.js index 0b937b0c2..d24279f00 100644 --- a/src/dygraph-interaction-model.js +++ b/src/dygraph-interaction-model.js @@ -405,6 +405,15 @@ DygraphInteraction.endZoom = function(event, g, context) { context.dragStartY = null; }; +// isOutOfExtremes: checks that number p is out of extremes ex. +// ex is a tuple [a, b], with a <= b +function isOutOfExtremes(p, ex) { + + return p < ex[0] || p > ex[1] + + // note on ex[0] < ex[1]: sometimes extremes are invalid, + // ex[0] must be less than or equal to ex[1] +} /** * @private */ @@ -429,6 +438,25 @@ DygraphInteraction.startTouch = function(event, g, context) { } context.initialTouches = touches; + let pinchCenter + if (touches.length >= 2) { + pinchCenter = { + pageX: 0.5 * (touches[0].pageX + touches[1].pageX), + pageY: 0.5 * (touches[0].pageY + touches[1].pageY), + + // TODO(danvk): remove + dataX: 0.5 * (touches[0].dataX + touches[1].dataX), + dataY: 0.5 * (touches[0].dataY + touches[1].dataY) + }; + + const xExtremes = g.xAxisExtremes() + const yExtremes = g.yAxisExtremes() + if (xExtremes[0] >= xExtremes[1] || isOutOfExtremes(pinchCenter.dataX, xExtremes)) + context.pinchOutOfExtremes = true + if (yExtremes.find(yEx => yEx[0] >= yEx[1] || isOutOfExtremes(pinchCenter.dataY, yEx))) + context.pinchOutOfExtremes = true + } + if (touches.length == 1) { // This is just a swipe. context.initialPinchCenter = touches[0]; @@ -438,15 +466,7 @@ DygraphInteraction.startTouch = function(event, g, context) { // In case there are 3+ touches, we ignore all but the "first" two. // only screen coordinates can be averaged (data coords could be log scale). - context.initialPinchCenter = { - pageX: 0.5 * (touches[0].pageX + touches[1].pageX), - pageY: 0.5 * (touches[0].pageY + touches[1].pageY), - - // TODO(danvk): remove - dataX: 0.5 * (touches[0].dataX + touches[1].dataX), - dataY: 0.5 * (touches[0].dataY + touches[1].dataY) - }; - + context.initialPinchCenter = pinchCenter // Make pinches in a 45-degree swath around either axis 1-dimensional zooms. var initialAngle = 180 / Math.PI * Math.atan2( context.initialPinchCenter.pageY - touches[0].pageY, @@ -519,7 +539,7 @@ DygraphInteraction.moveTouch = function(event, g, context) { // The residual bits are usually split into scale & rotate bits, but we split // them into x-scale and y-scale bits. - if (touches.length >= 2) { + if (touches.length >= 2 && !context.pinchOutOfExtremes) { var initHalfWidth = (initialTouches[1].pageX - c_init.pageX); var initHalfHeight = (initialTouches[1].pageY - c_init.pageY); if (touches.length >= 2) { From 0765e371f84c2df02ee95dcaeb84c848c576225c Mon Sep 17 00:00:00 2001 From: andrea Date: Sat, 11 Apr 2020 04:32:26 +0200 Subject: [PATCH 06/13] pageX, pageY is not right for toDataXCoord(). Using t.clientX and t.target.getBoundingClientRect() --- src/dygraph-interaction-model.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/dygraph-interaction-model.js b/src/dygraph-interaction-model.js index d24279f00..dfb2da1ff 100644 --- a/src/dygraph-interaction-model.js +++ b/src/dygraph-interaction-model.js @@ -427,19 +427,23 @@ 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 }); } context.initialTouches = touches; - let pinchCenter + var pinchCenter + context.pinchOutOfExtremes = false if (touches.length >= 2) { + + // only screen coordinates can be averaged (data coords could be log scale). pinchCenter = { pageX: 0.5 * (touches[0].pageX + touches[1].pageX), pageY: 0.5 * (touches[0].pageY + touches[1].pageY), @@ -465,8 +469,8 @@ DygraphInteraction.startTouch = function(event, g, context) { // It's become a pinch! // In case there are 3+ touches, we ignore all but the "first" two. - // only screen coordinates can be averaged (data coords could be log scale). context.initialPinchCenter = pinchCenter + // Make pinches in a 45-degree swath around either axis 1-dimensional zooms. var initialAngle = 180 / Math.PI * Math.atan2( context.initialPinchCenter.pageY - touches[0].pageY, @@ -477,8 +481,9 @@ DygraphInteraction.startTouch = function(event, g, context) { if (initialAngle > 90) initialAngle = 90 - initialAngle; context.touchDirections = { + //TODO: it does not seem to work well //x: (initialAngle < (90 - 45/2)), - // y: (initialAngle > 45/2) + //y: (initialAngle > 45/2) x: true, y: true }; From d7ada5cfd84ad314aa2d31a007a63e11cd2b609b Mon Sep 17 00:00:00 2001 From: andrea Date: Sat, 11 Apr 2020 07:44:01 +0200 Subject: [PATCH 07/13] do not scale if just panning --- src/dygraph-interaction-model.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/dygraph-interaction-model.js b/src/dygraph-interaction-model.js index dfb2da1ff..c251c8851 100644 --- a/src/dygraph-interaction-model.js +++ b/src/dygraph-interaction-model.js @@ -569,15 +569,25 @@ DygraphInteraction.moveTouch = function(event, g, context) { var didZoom = false; if (context.touchDirections.x) { + var oldDateWindow = g.dateWindow_ g.dateWindow_ = [ 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 ]; if (xExtremes[0] < xExtremes[1]) { - if (g.dateWindow_[0] < xExtremes[0]) - g.dateWindow_[0] = xExtremes[0] - if (g.dateWindow_[1] > xExtremes[1]) - g.dateWindow_[1] = xExtremes[1] + var pef = g.getNumericOption("panEdgeFraction") || 1/10 + var a = xExtremes[0] - (xExtremes[1] - xExtremes[0]) * pef + var b = xExtremes[1] + (xExtremes[1] - xExtremes[0]) * pef + if (g.dateWindow_[0] < a) { + g.dateWindow_[0] = a + if (xScale == 1) // if it is a pan, do not scale the window + g.dateWindow_[1] = oldDateWindow[1] + } + if (g.dateWindow_[1] > b) { + g.dateWindow_[1] = b + if (xScale == 1) + g.dateWindow_[0] = oldDateWindow[0] + } } didZoom = true; } From 2249d7a74a115a1bffd22e60d4015c220ffdf0ce Mon Sep 17 00:00:00 2001 From: andrea Date: Sat, 11 Apr 2020 07:48:18 +0200 Subject: [PATCH 08/13] do not scale if just panning (y axis) --- src/dygraph-interaction-model.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/dygraph-interaction-model.js b/src/dygraph-interaction-model.js index c251c8851..5abfbbf99 100644 --- a/src/dygraph-interaction-model.js +++ b/src/dygraph-interaction-model.js @@ -599,16 +599,27 @@ DygraphInteraction.moveTouch = function(event, g, context) { if (logscale) { // TODO(danvk): implement } else { + var oldValueRange = axis.valueRange axis.valueRange = [ 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 ]; - if (yExtremes[i][0] < yExtremes[i][1]) { - if (axis.valueRange[0] < yExtremes[i][0]) - axis.valueRange[0] = yExtremes[i][0] - if (axis.valueRange[1] > yExtremes[i][1]) - axis.valueRange[1] = yExtremes[i][1] + if (yExtremes[i][0] < yExtremes[i][1]) { + var pef = g.getNumericOption("panEdgeFraction") || 1/10 + var a = yExtremes[i][0] - (yExtremes[i][1] - yExtremes[i][0]) * pef + var b = yExtremes[i][1] + (yExtremes[i][1] - yExtremes[i][0]) * pef + if (axis.valueRange[0] < a) { + axis.valueRange[0] = a + if (xScale == 1) // if it is a pan, do not scale + axis.valueRange[1] = oldValueRange[1] + } + if (axis.valueRange[1] > b) { + axis.valueRange[1] = b + if (xScale == 1) + axis.valueRange[0] = oldValueRange[0] + } } + didZoom = true; } } From 6a296f6e3a5b6f6821343989347fcff9d47efc25 Mon Sep 17 00:00:00 2001 From: andrea Date: Sat, 11 Apr 2020 07:58:55 +0200 Subject: [PATCH 09/13] with the pageX bug fixed, there is no need of large minAllowed --- 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 5abfbbf99..b99927797 100644 --- a/src/dygraph-interaction-model.js +++ b/src/dygraph-interaction-model.js @@ -548,7 +548,7 @@ DygraphInteraction.moveTouch = function(event, g, context) { var initHalfWidth = (initialTouches[1].pageX - c_init.pageX); var initHalfHeight = (initialTouches[1].pageY - c_init.pageY); if (touches.length >= 2) { - const minAllowed = 50 + const minAllowed = 5 if (Math.abs(initHalfWidth) > minAllowed) { // sensitiveness dampening: smaller pinches count much less const damp = 1 / (Math.abs(initHalfWidth) - minAllowed) From 04979b3309c92a1286afc7ea5a89ac20fc1cabe7 Mon Sep 17 00:00:00 2001 From: andrea Date: Sat, 11 Apr 2020 08:19:51 +0200 Subject: [PATCH 10/13] now need of minAllowed, it is enough --- src/dygraph-interaction-model.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/dygraph-interaction-model.js b/src/dygraph-interaction-model.js index b99927797..3a93307d7 100644 --- a/src/dygraph-interaction-model.js +++ b/src/dygraph-interaction-model.js @@ -453,8 +453,8 @@ DygraphInteraction.startTouch = function(event, g, context) { dataY: 0.5 * (touches[0].dataY + touches[1].dataY) }; - const xExtremes = g.xAxisExtremes() - const yExtremes = g.yAxisExtremes() + var xExtremes = g.xAxisExtremes() + var yExtremes = g.yAxisExtremes() if (xExtremes[0] >= xExtremes[1] || isOutOfExtremes(pinchCenter.dataX, xExtremes)) context.pinchOutOfExtremes = true if (yExtremes.find(yEx => yEx[0] >= yEx[1] || isOutOfExtremes(pinchCenter.dataY, yEx))) @@ -537,8 +537,8 @@ DygraphInteraction.moveTouch = function(event, g, context) { swipe.dataX = (swipe.pageX / g.plotter_.area.w) * dataWidth; swipe.dataY = (swipe.pageY / g.plotter_.area.h) * dataHeight; - const xExtremes = g.xAxisExtremes() - const yExtremes = g.yAxisExtremes() + var xExtremes = g.xAxisExtremes() + var yExtremes = g.yAxisExtremes() var xScale = 1.0, yScale = 1.0; @@ -548,17 +548,18 @@ DygraphInteraction.moveTouch = function(event, g, context) { var initHalfWidth = (initialTouches[1].pageX - c_init.pageX); var initHalfHeight = (initialTouches[1].pageY - c_init.pageY); if (touches.length >= 2) { - const minAllowed = 5 - if (Math.abs(initHalfWidth) > minAllowed) { - // sensitiveness dampening: smaller pinches count much less - const damp = 1 / (Math.abs(initHalfWidth) - minAllowed) - xScale = (touches[1].pageX - c_now.pageX + damp) / (initHalfWidth + damp); - } + // sensitiveness dampening: smaller pinches count much less + var nowHalfWidth = touches[1].pageX - c_now.pageX + var smallestHalfWidth = Math.min(Math.abs(nowHalfWidth), Math.abs(initHalfWidth)) + var damp = 1 / smallestHalfWidth + xScale = (nowHalfWidth + damp) / (initHalfWidth + damp); - if (Math.abs(initHalfHeight) > minAllowed) { - const damp = 1 / (Math.abs(initHalfHeight) - minAllowed) - yScale = (touches[1].pageY - c_now.pageY + damp) / (initHalfHeight + damp); - } + var nowHalfHeight = touches[1].pageY - c_now.pageY + var smallestHalfHeight = Math.min(Math.abs(nowHalfHeight), Math.abs(initHalfHeight)) + var damp = 1 / smallestHalfHeight + yScale = (nowHalfHeight + damp) / (initHalfHeight + damp); + + console.log(xScale, yScale) } } From fa075511746c0c94632035db53f48aa15b6f8f2f Mon Sep 17 00:00:00 2001 From: andrea Date: Sat, 11 Apr 2020 08:34:15 +0200 Subject: [PATCH 11/13] min allowed is better --- src/dygraph-interaction-model.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/dygraph-interaction-model.js b/src/dygraph-interaction-model.js index 3a93307d7..a8bf1792d 100644 --- a/src/dygraph-interaction-model.js +++ b/src/dygraph-interaction-model.js @@ -548,18 +548,22 @@ DygraphInteraction.moveTouch = function(event, g, context) { var initHalfWidth = (initialTouches[1].pageX - c_init.pageX); var initHalfHeight = (initialTouches[1].pageY - c_init.pageY); if (touches.length >= 2) { - // sensitiveness dampening: smaller pinches count much less - var nowHalfWidth = touches[1].pageX - c_now.pageX - var smallestHalfWidth = Math.min(Math.abs(nowHalfWidth), Math.abs(initHalfWidth)) - var damp = 1 / smallestHalfWidth - xScale = (nowHalfWidth + damp) / (initHalfWidth + damp); - - var nowHalfHeight = touches[1].pageY - c_now.pageY - var smallestHalfHeight = Math.min(Math.abs(nowHalfHeight), Math.abs(initHalfHeight)) - var damp = 1 / smallestHalfHeight - yScale = (nowHalfHeight + damp) / (initHalfHeight + damp); - - console.log(xScale, yScale) + var minAllowed = 5 + + if (Math.abs(initHalfWidth) > minAllowed) { + // sensitiveness dampening: smaller pinches count much less + var damp = 1 / (Math.abs(initHalfWidth)-minAllowed) + + var nowHalfWidth = touches[1].pageX - c_now.pageX + xScale = (nowHalfWidth + damp) / (initHalfWidth + damp); + } + + if (Math.abs(initHalfHeight) > minAllowed) { + var damp = 1 / (Math.abs(initHalfHeight) - minAllowed) + + var nowHalfHeight = touches[1].pageY - c_now.pageY + yScale = (nowHalfHeight + damp) / (initHalfHeight + damp); + } } } From 588c385aba4109820052b0f6dea84e024467b1d5 Mon Sep 17 00:00:00 2001 From: andrea Date: Sat, 11 Apr 2020 08:39:15 +0200 Subject: [PATCH 12/13] refactoring --- src/dygraph-interaction-model.js | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/dygraph-interaction-model.js b/src/dygraph-interaction-model.js index a8bf1792d..10ba36248 100644 --- a/src/dygraph-interaction-model.js +++ b/src/dygraph-interaction-model.js @@ -547,23 +547,21 @@ DygraphInteraction.moveTouch = function(event, g, context) { if (touches.length >= 2 && !context.pinchOutOfExtremes) { var initHalfWidth = (initialTouches[1].pageX - c_init.pageX); var initHalfHeight = (initialTouches[1].pageY - c_init.pageY); - if (touches.length >= 2) { - var minAllowed = 5 - - if (Math.abs(initHalfWidth) > minAllowed) { - // sensitiveness dampening: smaller pinches count much less - var damp = 1 / (Math.abs(initHalfWidth)-minAllowed) - - var nowHalfWidth = touches[1].pageX - c_now.pageX - xScale = (nowHalfWidth + damp) / (initHalfWidth + damp); - } + var minAllowed = 5 + + if (Math.abs(initHalfWidth) > minAllowed) { + // sensitiveness dampening: smaller pinches count much less + var damp = 1 / (Math.abs(initHalfWidth)-minAllowed) + + var nowHalfWidth = touches[1].pageX - c_now.pageX + xScale = (nowHalfWidth + damp) / (initHalfWidth + damp); + } - if (Math.abs(initHalfHeight) > minAllowed) { - var damp = 1 / (Math.abs(initHalfHeight) - minAllowed) + if (Math.abs(initHalfHeight) > minAllowed) { + var damp = 1 / (Math.abs(initHalfHeight) - minAllowed) - var nowHalfHeight = touches[1].pageY - c_now.pageY - yScale = (nowHalfHeight + damp) / (initHalfHeight + damp); - } + var nowHalfHeight = touches[1].pageY - c_now.pageY + yScale = (nowHalfHeight + damp) / (initHalfHeight + damp); } } From 87f18e338e74b9a290a61975eed1e4533cb701a6 Mon Sep 17 00:00:00 2001 From: andrea Date: Mon, 13 Apr 2020 18:10:28 +0200 Subject: [PATCH 13/13] guard on undefined valueRange / dateWindow --- src/dygraph-interaction-model.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dygraph-interaction-model.js b/src/dygraph-interaction-model.js index 10ba36248..8221bac05 100644 --- a/src/dygraph-interaction-model.js +++ b/src/dygraph-interaction-model.js @@ -572,7 +572,7 @@ DygraphInteraction.moveTouch = function(event, g, context) { var didZoom = false; if (context.touchDirections.x) { - var oldDateWindow = g.dateWindow_ + var oldDateWindow = g.dateWindow_ || context.initialRange.x g.dateWindow_ = [ 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 @@ -602,7 +602,7 @@ DygraphInteraction.moveTouch = function(event, g, context) { if (logscale) { // TODO(danvk): implement } else { - var oldValueRange = axis.valueRange + var oldValueRange = axis.valueRange || context.initialRange.y axis.valueRange = [ 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