Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(zoom): Correct zoom in rendering on 0 coordinates. #170

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions spec/api.zoom-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ describe("API zoom", function() {
expect(Math.round(domain[0])).to.be.equal(target[0]);
expect(Math.round(domain[1])).to.be.equal(target[1]);
});

it("should be zoomed and showing focus grid properly when target contained minus value", () => {
const target = [-2, 3]; // zoom in cotaining minus value

chart.zoom(target);

const zoomScale = chart.internal.zoomScale;

// If target contained minus value should not be null
expect(zoomScale).to.not.be.null;

const domain = chart.internal.zoomScale.domain();

// domain value must be above than target
expect(Math.round(domain[0])).to.be.above(target[0]);
expect(Math.round(domain[1])).to.be.above(target[1]);
});
});

describe("zoom line chart #2", () => {
Expand Down
14 changes: 10 additions & 4 deletions src/interactions/zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,20 @@ extend(ChartInternal.prototype, {
// .on("dblclick.zoom", null);

if ($$.zoomScale) {
const range1 = $$.zoomScale.domain()[0];
const range2 = $$.x.domain()[0];
const zoomLeftDomain = $$.zoomScale.domain()[0];
const leftDomain = $$.x.domain()[0];
const zoomRightDomain = $$.zoomScale.domain()[1];
const rightDomain = $$.x.domain()[1];
const delta = 0.015;

// check the zoomed chart is shown between leftDomain(x) and rightDomain(x).
const initLeft = zoomLeftDomain <= leftDomain || (zoomLeftDomain - delta) <= leftDomain;
const initRight = rightDomain <= zoomRightDomain || rightDomain <= (zoomRightDomain - delta);

// reset scale when zoom is out as initial
if (range1 <= range2 || (range1 - delta) <= range2) {
$$.zoomScale = null;
if (initLeft && initRight) {
$$.xAxis.scale($$.x);
$$.zoomScale = null;
}
}

Expand Down