Skip to content

Commit

Permalink
fix(labels): Fix index argument for nullish value
Browse files Browse the repository at this point in the history
Index argument passed to data.labels.format
should be couning nullish value

Fix naver#3547
  • Loading branch information
netil authored Oct 12, 2023
1 parent f9b65ac commit 13d1077
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ChartInternal/internals/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export default {
}

value = $$.isTreemapType(d) ? $$.treemapDataLabelFormat(d)(node) :
$$.dataLabelFormat(d.id)(value, d.id, i, texts);
$$.dataLabelFormat(d.id)(value, d.id, d.index, texts);

if (isNumber(value)) {
this.textContent = value;
Expand Down
25 changes: 25 additions & 0 deletions test/internals/text-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,8 @@ describe("TEXT", () => {
});

describe("as function", () => {
const temp: any = [];

before(() => {
args = {
data: {
Expand Down Expand Up @@ -593,6 +595,29 @@ describe("TEXT", () => {
expect(d3Select(this).text()).to.equal("");
});
});

it("set options", () => {
args = {
data: {
columns: [
["data1", 10, 100, null, 150, 200]
],
labels: {
format: (value, seriesName, columnIndex) => {
if (seriesName) {
temp.push(columnIndex);
}

return value;
}
}
}
}
});

it("index argument should count nullish value", () => {
expect(temp).to.be.deep.equal([0, 1, 3, 4]);
});
});
});

Expand Down

0 comments on commit 13d1077

Please sign in to comment.