Skip to content

Commit

Permalink
fix(zoom): Fix on zoom.rescale option (#566)
Browse files Browse the repository at this point in the history
Update x axis domain with the zoomScale domain value

Fix #470
Close #566
  • Loading branch information
netil committed Aug 28, 2018
1 parent 937427d commit 851ec3e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
24 changes: 23 additions & 1 deletion spec/interactions/zoom-spec.js
Expand Up @@ -210,7 +210,7 @@ describe("ZOOM", function() {
expect(resetBtn.style("display")).to.be.equal("none");
});

it("set options zoom.resetButton.text='test", () => {
it("set options zoom.resetButton.text='test'", () => {
args.zoom.resetButton = {
text: "test"
};
Expand All @@ -225,6 +225,28 @@ describe("ZOOM", function() {
expect(resetBtn.empty()).to.be.false;
expect(resetBtn.text()).to.be.equal("test");
});

it("set options zoom.rescale=true", () => {
args.zoom.rescale = true;
});

it("check for the y axis rescale", () => {
const axisY = chart.$.main.select(`.${CLASS.axisY}`);

// when
chart.zoom([0, 2]);

let tick = axisY.selectAll(".tick").nodes().pop();

expect(+tick.textContent).to.be.equal(200);

// when
chart.zoom([2,4]);

tick = axisY.selectAll(".tick").nodes().pop();

expect(+tick.textContent).to.be.equal(6000);
});
});

describe("zoom on regions", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/api/api.zoom.js
Expand Up @@ -42,7 +42,7 @@ const zoom = function(domainValue) {
$$.brush.getSelection().call($$.brush.move, [xScale(domain[0]), xScale(domain[1])]);
resultDomain = domain;
} else {
const orgDomain = $$.x.orgDomain();
const orgDomain = $$.subX.domain();
const k = (orgDomain[1] - orgDomain[0]) / (domain[1] - domain[0]);
const gap = $$.isCategorized() ? $$.xAxis.tickOffset() : 0;
const tx = isTimeSeries ?
Expand Down
5 changes: 4 additions & 1 deletion src/interactions/zoom.js
Expand Up @@ -90,13 +90,16 @@ extend(ChartInternal.prototype, {
*/
zoom.updateTransformScale = transform => {
// rescale from the original scale
const newScale = transform.rescaleX($$.x.orgScale());
const newScale = transform.rescaleX($$.subX.orgScale());
const domain = $$.trimXDomain(newScale.domain());
const rescale = config.zoom_rescale;

newScale.domain(domain, $$.orgXDomain);

$$.zoomScale = $$.getCustomizedScale(newScale);
$$.xAxis.scale($$.zoomScale);

rescale && $$.x.domain($$.zoomScale.orgDomain());
};

$$.zoom = zoom;
Expand Down
2 changes: 1 addition & 1 deletion src/internals/ChartInternal.js
Expand Up @@ -807,7 +807,7 @@ export default class ChartInternal {
// callback function after redraw ends
const afterRedraw = flow || config.onrendered ? () => {
flow && flow();
config.onrendered && config.onrendered.call($$);
callFn(config.onrendered, $$);
} : null;

if (afterRedraw) {
Expand Down

0 comments on commit 851ec3e

Please sign in to comment.