Skip to content

Commit 08844c2

Browse files
authored
fix: trigger onZoom from zoomScale (#889)
1 parent b2aeae6 commit 08844c2

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/core.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,13 @@ export function zoomRect(chart, p0, p1, transition = 'none') {
108108
}
109109

110110
export function zoomScale(chart, scaleId, range, transition = 'none') {
111-
storeOriginalScaleLimits(chart, getState(chart));
111+
const state = getState(chart);
112+
storeOriginalScaleLimits(chart, state);
112113
const scale = chart.scales[scaleId];
113114
updateRange(scale, range, undefined, true);
114115
chart.update(transition);
116+
117+
call(state.options.zoom?.onZoom, [{chart}]);
115118
}
116119

117120
export function resetZoom(chart, transition = 'default') {
@@ -130,6 +133,7 @@ export function resetZoom(chart, transition = 'default') {
130133
delete state.updatedScaleLimits[scale.id];
131134
});
132135
chart.update(transition);
136+
133137
call(state.options.zoom.onZoomComplete, [{chart}]);
134138
}
135139

test/specs/api.spec.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,35 @@ describe('api', function() {
240240
});
241241
});
242242

243+
describe('zoomScale', function() {
244+
it('should call onZoom', function() {
245+
const zoomSpy = jasmine.createSpy('start');
246+
const chart = window.acquireChart({
247+
type: 'scatter',
248+
data: {
249+
datasets: [
250+
{
251+
data: [{x: 1, y: 1}, {x: 10, y: 10}],
252+
},
253+
],
254+
},
255+
options: {
256+
plugins: {
257+
zoom: {
258+
zoom: {
259+
onZoom: zoomSpy,
260+
}
261+
}
262+
}
263+
}
264+
});
265+
266+
chart.zoomScale('x', {min: 2, max: 10}, 'default');
267+
268+
expect(zoomSpy).toHaveBeenCalledWith({chart});
269+
});
270+
});
271+
243272
describe('getInitialScaleBounds', function() {
244273
it('should provide the correct initial scale bounds regardless of the zoom level', function() {
245274
const chart = window.acquireChart({

0 commit comments

Comments
 (0)