Skip to content

Commit

Permalink
In startTouch(), pageX, pageY is not appropriate for the calculation …
Browse files Browse the repository at this point in the history
…of dataX, dataY. This causes serious problems in the calculation of context.initialPinchCenter. The wrong calculations affect pinch-zoom when the x or y range is small and the graph div is farther to the bottom or right of the page.

For example, see http://jsfiddle.net/j63zvups/1/ and try to pinch-zoom in vertical, for scaling the y axis. You will get an ungovernable behaviour.

The solution is to use t.clientX and t.target.getBoundingClientRect().

To see that the old calculations were incorrect, consider this:

toDataYCoord(y) = yRange[0] + (area.y + area.h - y) / area.h * (yRange[1] - yRange[0]);

Now, if you pass y = pageY, you can see that (area.y + area.h - pageY) / area.h is wrong when pageY > area.y + area.h, which is the case when you scroll far enough.
  • Loading branch information
andrea committed Apr 11, 2020
1 parent 457cb0d commit ef5fe4d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/dygraph-interaction-model.js
Expand Up @@ -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
});
}
Expand Down

0 comments on commit ef5fe4d

Please sign in to comment.