Skip to content

Commit ffec8c3

Browse files
authored
Fix initial call to isZoomedOrPanned (#630)
isZoomedOrPanned incorrectly returns true if it's called before any zoom or pan operations are done. I believe that the `!== undefined` check should be valid; storeOriginalScaleLimits always sets the min/max value to chart.scales[scaleId]'s min/max, which TypeScript says are always defined. However, I could be missing something. Fixes #629
1 parent 12f38a9 commit ffec8c3

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/core.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,11 @@ export function isZoomedOrPanned(chart) {
218218
for (const scaleId of Object.keys(chart.scales)) {
219219
const {min: originalMin, max: originalMax} = scaleBounds[scaleId];
220220

221-
if (chart.scales[scaleId].min !== originalMin) {
221+
if (originalMin !== undefined && chart.scales[scaleId].min !== originalMin) {
222222
return true;
223223
}
224224

225-
if (chart.scales[scaleId].max !== originalMax) {
225+
if (originalMax !== undefined && chart.scales[scaleId].max !== originalMax) {
226226
return true;
227227
}
228228
}

test/specs/api.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ describe('api', function() {
142142
}
143143
});
144144

145+
expect(chart.isZoomedOrPanned()).toBe(false);
146+
145147
chart.zoom(1);
146148
expect(chart.isZoomedOrPanned()).toBe(false);
147149

@@ -172,6 +174,8 @@ describe('api', function() {
172174
}
173175
});
174176

177+
expect(chart.isZoomedOrPanned()).toBe(false);
178+
175179
chart.pan({x: 0, y: 0});
176180
expect(chart.isZoomedOrPanned()).toBe(false);
177181

0 commit comments

Comments
 (0)