Skip to content

Commit

Permalink
fix(Zoom): Updated domain values onzoom/onzoomend
Browse files Browse the repository at this point in the history
Updated the domain value passed to callFn on onzoom/onzoomend callback

Fix #770
Close #777
  • Loading branch information
gunaseelann authored and netil committed Feb 20, 2019
1 parent d9f4477 commit acf3239
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ Chong Jaemyung <[email protected]>
Rex <[email protected]>
Alexandre Araujo <https://github.com/oliveiraaraujo>
Jinwoo Oh <[email protected]>
Nirmal Guna <[email protected]>
28 changes: 26 additions & 2 deletions spec/interactions/zoom-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/api/api.zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/interactions/zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ extend(ChartInternal.prototype, {
});

$$.cancelClick = isMousemove;
callFn(config.zoom_onzoom, $$.api, $$.subX.domain());
callFn(config.zoom_onzoom, $$.api, $$.zoomScale.domain());
},

/**
Expand All @@ -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());
},

/**
Expand Down

0 comments on commit acf3239

Please sign in to comment.