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

two bugs fixed in the calculations of pinch-zoom #990

Merged
merged 2 commits into from
Dec 8, 2022

Conversation

Alpt
Copy link

@Alpt Alpt commented Apr 9, 2020

In dygraph-interaction-model.js, DygraphInteraction.moveTouch, the following is done:

 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
    ];

However, it seems that swipe.dataX is not properly scaled. It should be:
c_init.dataX - swipe.dataX / xScale + (context.initialRange.x[0] - c_init.dataX) / xScale

In startTouch(), pageX, pageY is not appropriate for the calculation 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.

With this two changes, dygraph behaves normally in my graphs and is usable.

@coveralls
Copy link

coveralls commented Apr 9, 2020

Coverage Status

Coverage decreased (-0.02%) to 90.176% when pulling ef5fe4d on Alpt:master into e9155b2 on danvk:master.

…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.
@Alpt Alpt changed the title swip.dataX was not scaled during the pinch. two bugs fixed in the calculations of pinch-zoom Apr 11, 2020
@Alpt Alpt mentioned this pull request Apr 11, 2020
Shinbar pushed a commit to Shinbar/dygraphs that referenced this pull request Apr 13, 2020
@mirabilos mirabilos merged commit d21949c into danvk:master Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants