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

Avoid zooming in when zooming out over certain areas of chart #574

Merged
merged 2 commits into from
Sep 20, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/scale.types.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@ function zoomDelta(scale, zoom, center) {
const newRange = range * (zoom - 1);

const centerPoint = scale.isHorizontal() ? center.x : center.y;
const minPercent = (scale.getValueForPixel(centerPoint) - scale.min) / range || 0;
// `scale.getValueForPixel()` can return a value
// less than the minimum value
// and greater than the maximum value
// when `centerPoint` is past the minimum/maximum values
// (e.g., on the y-axis labels).
const minPercent = Math.max(
0,
Math.min(
1,
(scale.getValueForPixel(centerPoint) - scale.min) / range || 0
)
);
kurkle marked this conversation as resolved.
Show resolved Hide resolved
const maxPercent = 1 - minPercent;

return {
Expand Down