Skip to content

Commit

Permalink
fix(Domain): fix trimXDomain not trimming min
Browse files Browse the repository at this point in the history
fix order of domain assignment to not write domain[0] before it's used
to calculate domain[1]
  • Loading branch information
ebencollins committed Sep 11, 2023
1 parent ca96f85 commit 6716cf4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ChartInternal/internals/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ export default {
const [min, max] = zoomDomain;

if (isInverted ? domain[0] >= min : domain[0] <= min) {
domain[0] = min;
domain[1] = +domain[1] + (min - domain[0]);
domain[0] = min;
}

if (isInverted ? domain[1] <= max : domain[1] >= max) {
Expand Down
32 changes: 32 additions & 0 deletions test/internals/domain-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,4 +377,36 @@ describe("DOMAIN", function() {
expect(y2.domain()).to.be.deep.equal(domain);
});
});

describe("trimXDomain", () => {
before(() => {
args = {
data: {
columns: [
["sample", 30, 200, 100, 400, 150, 250, 150, 200, 170, 240, 350, 150, 100, 400, 150],
],
type: "line",
},
zoom: {
enabled: true,
},
}
});

it("test pan left gets trimmed", () => {
const domain = chart.internal.scale.x.domain();
const trimmed = chart.internal.trimXDomain(domain.map((x: number) => x - 10));

expect(trimmed[0]).to.approximately(domain[0], 0.1);
expect(trimmed[1]).to.approximately(domain[1], 0.1);
});

it("test pan right gets trimmed", () => {
const domain = chart.internal.scale.x.domain();
const trimmed = chart.internal.trimXDomain(domain.map((x: number) => x + 5));

expect(trimmed[0]).to.approximately(domain[0], 0.1);
expect(trimmed[1]).to.approximately(domain[1], 0.1);
});
});
});

0 comments on commit 6716cf4

Please sign in to comment.