Skip to content

Commit

Permalink
fix(api): fix tooltip work for .load() with xs key
Browse files Browse the repository at this point in the history
when data initializes with empty data, do not initialize eventRect
and initializes when data is loaded dynamically.

Fix #3194
  • Loading branch information
netil authored May 3, 2023
1 parent cf82289 commit 13b9da7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/ChartInternal/interactions/eventrect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export default {

if ($el.eventRect) {
$$.updateEventRect($el.eventRect, true);
} else {

// do not initialize eventRect when data is empty
} else if ($$.data.targets.length) {
const eventRects = $$.$el.main.select(`.${$EVENT.eventRects}`)
.style("cursor", config.zoom_enabled && config.zoom_type !== "drag" ? (
config.axis_rotated ? "ns-resize" : "ew-resize"
Expand Down Expand Up @@ -61,6 +63,9 @@ export default {
if ($$.state.inputType === "touch" && !$el.svg.on("touchstart.eventRect") && !$$.hasArcType()) {
$$.bindTouchOnEventRect(isMultipleX);
}

// when initilazed with empty data and data loaded later, need to update eventRect
state.rendered && $$.updateEventRect($el.eventRect, true);
}

if (!isMultipleX) {
Expand Down
39 changes: 39 additions & 0 deletions test/api/load-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,45 @@ describe("API load", function() {
}
});
});

it("set options: initialize with empty data", () => {
args = {
data: {
columns: [],
type: "area"
}
};
});

it("check for correct event binding", done => {
setTimeout(() => {
chart.load({
xs: {
data: 'dataX'
},
columns: [
["data", 300, 350, 300, 200, 50, 300],
["dataX", 1, 2, 3, 4, 5, 6],
],
done: function() {
this.tooltip.show({
data: {
x: 3,
id: "data",
value: 300
}
});

const {tooltip} = this.$;

expect(tooltip.select(".name").text()).to.be.equal("data");
expect(+tooltip.select(".value").text()).to.be.equal(300);

done();
}
});
}, 1000);
});
});

describe("different type loading", () => {
Expand Down

0 comments on commit 13b9da7

Please sign in to comment.