two bugs fixed in the calculations of pinch-zoom #990
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In dygraph-interaction-model.js, DygraphInteraction.moveTouch, the following is done:
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.