Skip to content

Commit cf1966d

Browse files
0b10011kurkle
andauthored
Avoid zooming in when zooming out over certain areas of chart (#574)
* Avoid zooming in when zooming out over certain areas of chart Zooming out when hovering over y-axis labels or legend would cause `minPercent` to be negative or past 100%, causing the chart to zoom in instead. * Update src/scale.types.js Co-authored-by: Jukka Kurkela <jukka.kurkela@gmail.com>
1 parent 786c34f commit cf1966d

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/scale.types.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ function zoomDelta(scale, zoom, center) {
66
const newRange = range * (zoom - 1);
77

88
const centerPoint = scale.isHorizontal() ? center.x : center.y;
9-
const minPercent = (scale.getValueForPixel(centerPoint) - scale.min) / range || 0;
9+
// `scale.getValueForPixel()` can return a value less than the `scale.min` or
10+
// greater than `scale.max` when `centerPoint` is outside chartArea.
11+
const minPercent = Math.max(0, Math.min(1,
12+
(scale.getValueForPixel(centerPoint) - scale.min) / range || 0
13+
));
14+
1015
const maxPercent = 1 - minPercent;
1116

1217
return {

0 commit comments

Comments
 (0)