Skip to content

Commit

Permalink
fix(zoom): Fix initial error empty data with zoom
Browse files Browse the repository at this point in the history
Fix zoom event binding error when initialized with empty data.

Fix #3470
  • Loading branch information
netil authored Oct 18, 2023
1 parent 83b0206 commit a94d09c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/ChartInternal/interactions/zoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,7 @@ export default {
// Applying the workaround: https://github.com/d3/d3-zoom/issues/231#issuecomment-802305692
$$.$el.svg.on("wheel", () => {});

eventRect
.call(behaviour)
eventRect?.call(behaviour)
.on("dblclick.zoom", null);
},

Expand Down
19 changes: 15 additions & 4 deletions test/interactions/zoom-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,37 @@ describe("ZOOM", function() {
expect(yDomain[0]).to.be.equal(expectedYDomain[0]);
expect(yDomain[1]).to.be.equal(expectedYDomain[1]);
});
});

describe("main chart domain", () => {
it("should have original y domain in subchart", () => {
const yDomain = chart.internal.scale.y.domain();
const subYDomain = chart.internal.scale.subY.domain();

expect(subYDomain[0]).to.be.equal(yDomain[0]);
expect(subYDomain[1]).to.be.equal(yDomain[1]);
});
});

describe("main chart domain", () => {
it("should have specified brush extent", () => {
const brushExtent = chart.internal.brush.extent()();
const expectedBrushExtent = [[1, 0], [2, 60]];

expect(brushExtent[0][1]).to.be.equal(expectedBrushExtent[0][1]);
expect(brushExtent[1][1]).to.be.equal(expectedBrushExtent[1][1]);
});

it("initialization with empty data", () => {
expect(
util.generate({
data: {
x: "x",
columns: [],
type: "line"
},
zoom: {
enabled: true
}
})
).to.not.throw;
});
});
});

Expand Down

0 comments on commit a94d09c

Please sign in to comment.