Skip to content

Commit

Permalink
fix(point): fix usePoint defs id value
Browse files Browse the repository at this point in the history
Incorrect id value was set for custom data point.
Side-effect caused by 6ff9aec

Fix #1887
  • Loading branch information
netil committed Jan 20, 2021
1 parent 0421a50 commit 6df4653
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/ChartInternal/shape/point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@ export default {
return function(method, context, ...args) {
return function(d) {
const id: string = $$.getTargetSelectorSuffix(d.id || (d.data && d.data.id) || d);

const element = d3Select(this);

ids.indexOf(id) < 0 && ids.push(id);
Expand All @@ -457,7 +456,7 @@ export default {
if ($$.hasValidPointType(point)) {
point = $$[point];
} else if (!$$.hasValidPointDrawMethods(point)) {
const pointId = `${datetimeId}-point-${id}`;
const pointId = `${datetimeId}-point${id}`;
const pointFromDefs = $$.pointFromDefs(pointId);

if (pointFromDefs.size() < 1) {
Expand Down
15 changes: 10 additions & 5 deletions test/internals/legend-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,15 +461,20 @@ describe("LEGEND", () => {
});

it("should render custom points in legend", () => {
const nodes = chart.internal.$el.svg.selectAll(`.${CLASS.legendItem} .${CLASS.legendItemPoint}`);
const {$el} = chart.internal;
const nodes = $el.svg.selectAll(`.${CLASS.legendItem} .${CLASS.legendItemPoint}`);
const pointTagName = ["circle", "rect", "use", "circle"];

nodes.each((data, idx, selection) => {
nodes.each(function(data, idx, selection) {
const node = selection[idx];
const nodeName = node.nodeName.toLowerCase();
const expected = (idx === 0 || idx === 3) ?
"circle" : (idx === 1) ? "rect" : (idx === 2) ? "use" : "";

expect(nodeName).to.be.equal(expected);
// check if referenced defs node exists
if (pointTagName[idx] === "use") {
expect($el.defs.select(this.getAttribute("href")).size()).to.be.equal(1);
}

expect(nodeName).to.be.equal(pointTagName[idx]);
});

expect(nodes.size()).to.be.equal(chart.data().length);
Expand Down

0 comments on commit 6df4653

Please sign in to comment.