Skip to content

Commit

Permalink
fix(event): fix referencing event element
Browse files Browse the repository at this point in the history
Make sure referencing event rect element when updating event rect's
dimension.

Fix #1752
  • Loading branch information
netil committed Nov 3, 2020
1 parent ce8210c commit 38568c1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/ChartInternal/interactions/eventrect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,23 +173,24 @@ export default {
const $$ = this;
const {state, $el} = $$;
const {eventReceiver, width, height, rendered, resizing} = state;
const rectElement = eventRect || $el.eventRect;

const updateClientRect = (): void => {
eventReceiver && (
eventReceiver.rect = (eventRect || $el.eventRect).node().getBoundingClientRect()
eventReceiver.rect = rectElement.node().getBoundingClientRect()
);
};

if (!rendered || resizing) {
const rect = eventRect
rectElement
.attr("x", 0)
.attr("y", 0)
.attr("width", width)
.attr("height", height);

// only for init
if (!rendered) {
rect.attr("class", CLASS.eventRect);
rectElement.attr("class", CLASS.eventRect);
}
}

Expand Down
9 changes: 9 additions & 0 deletions test/api/chart-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ describe("API chart", () => {

expect(+eventRect.attr("height")).to.be.above(height);
});

it("updating event rect during resize state", () => {
// force resizing state
chart.internal.state.resizing = true;

expect(
chart.internal.updateEventRect()
).to.not.throw;
});
});

describe("destroy()", () => {
Expand Down

0 comments on commit 38568c1

Please sign in to comment.