diff --git a/AUTHORS.txt b/AUTHORS.txt index 7848e2da2..e35a80df7 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -23,3 +23,4 @@ Chong Jaemyung Rex Alexandre Araujo Jinwoo Oh +Nirmal Guna diff --git a/spec/interactions/zoom-spec.js b/spec/interactions/zoom-spec.js index 1c2c1bf1b..7307ecfb3 100644 --- a/spec/interactions/zoom-spec.js +++ b/spec/interactions/zoom-spec.js @@ -70,9 +70,10 @@ describe("ZOOM", function() { }); describe("zoom event", () => { + let zoomDomain; const spyOnZoomStart = sinon.spy(); - const spyOnZoom = sinon.spy(); - const spyOnZoomEnd = sinon.spy(); + const spyOnZoom = sinon.spy(domain => (zoomDomain = domain)); + const spyOnZoomEnd = sinon.spy(domain => (zoomDomain = domain)); before(() => { args = { @@ -202,6 +203,29 @@ describe("ZOOM", function() { // check if chart react on resize expect(+domain.attr("d").match(rx)[1]).to.be.above(pathValue); }); + + it("check for updated domain on zoomScale after zoom in", () => { + const zoomValue = [1, 3]; + + chart.zoom(zoomValue); // zoom in + expect(chart.internal.zoomScale.domain()).to.be.deep.equal(zoomValue); // zoomScale value is updated on zoom in + + chart.unzoom(); // zoom set to initial + expect(chart.internal.zoomScale).to.be.null; // zoomScale null on zoom out to initial + + }); + + it("check for subX domain values after zoom", () => { + const zoomValue = [1, 3]; + const subX = chart.internal.subX; + + chart.zoom(zoomValue); // zoom in + expect(subX.domain()).to.not.deep.equal(zoomValue); // subX value not updated on zoom in + + chart.unzoom(); // zoom set to initial + expect(subX.domain()).to.be.deep.equal(chart.internal.x.orgDomain()); // subX value not updated on zoom in + }); + }); describe("zoom type drag", () => { diff --git a/src/api/api.zoom.js b/src/api/api.zoom.js index b836ee47f..7a6239e28 100644 --- a/src/api/api.zoom.js +++ b/src/api/api.zoom.js @@ -55,7 +55,7 @@ const zoom = function(domainValue) { }); $$.setZoomResetButton(); - callFn($$.config.zoom_onzoom, this, $$.x.orgDomain()); + callFn($$.config.zoom_onzoom, resultDomain); } else { resultDomain = $$.zoomScale ? $$.zoomScale.domain() : $$.x.orgDomain(); diff --git a/src/interactions/zoom.js b/src/interactions/zoom.js index c64652de1..a566cc411 100644 --- a/src/interactions/zoom.js +++ b/src/interactions/zoom.js @@ -160,7 +160,7 @@ extend(ChartInternal.prototype, { }); $$.cancelClick = isMousemove; - callFn(config.zoom_onzoom, $$.api, $$.subX.domain()); + callFn(config.zoom_onzoom, $$.api, $$.zoomScale.domain()); }, /** @@ -181,7 +181,7 @@ extend(ChartInternal.prototype, { $$.redrawEventRect(); $$.updateZoom(); - callFn($$.config.zoom_onzoomend, $$.api, $$.subX.domain()); + callFn($$.config.zoom_onzoomend, $$.api, $$[$$.zoomScale ? "zoomScale" : "subX"].domain()); }, /**