Skip to content

Commit

Permalink
fix(subchart): fix duplicated node generation on data load
Browse files Browse the repository at this point in the history
Fix incorrect selection merge where causing node duplication

Ref naver#2003
  • Loading branch information
netil committed Mar 26, 2021
1 parent e507835 commit 1afaca4
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/ChartInternal/interactions/subchart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,21 +195,18 @@ export default {
} else {
const shapeUpdate = shapeChart
.selectAll(`.${CLASS[`chart${name}`]}`)
.data(targets.filter($$[`is${name}Type`].bind($$)))
.attr("class", chartClass);

shapeUpdate.exit().remove();
.attr("class", chartClass)
.data(targets.filter($$[`is${name}Type`].bind($$)));

const shapeEnter = shapeUpdate.enter()
.append("g")
.style("opacity", "0")
.attr("class", chartClass)
.merge(shapeUpdate);

// Bars for each data
shapeEnter.append("g")
.append("g")
.attr("class", shapeClass);

shapeUpdate.exit().remove();

// Area
v === "line" && $$.hasTypeOf("Area") &&
shapeEnter.append("g").attr("class", $$.getClass("areas", true));
Expand Down
52 changes: 52 additions & 0 deletions test/interactions/subchart-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,4 +476,56 @@ describe("SUBCHART", () => {
});
})
});


describe("dynamic data load via .load() API", () => {
before(() => {
args = {
data: {
columns: [
["data1", 30, 200, 100, 400, 150, 250]
]
},
subchart: {
show: true
}
};
});

it("shouldn't generate duplicated nodes #1", done => {
// when
chart.load({
columns: [
["data1", 30, 20, 50, 40, 60, 50],
["data2", 130, 120, 150, 140, 160, 150],
],
done: function() {
expect(
this.internal.$el.subchart.main.selectAll(`.${CLASS.line}-data1`).size()
).to.be.equal(1);
}
});
});

it("shouldn't generate duplicated nodes #2", done => {
// when
chart.load({
columns: [
["data2", 130, 120, 150, 140, 160, 150],
],
unload: ["data1"],
done: function() {
const {main} = this.internal.$el.subchart;

expect(
main.selectAll(`.${CLASS.line}-data1`).empty()
).to.be.true;

expect(
main.selectAll(`.${CLASS.line}-data2`).size()
).to.be.equal(1);
}
});
});
});
});

0 comments on commit 1afaca4

Please sign in to comment.