diff --git a/src/ChartInternal/internals/text.ts b/src/ChartInternal/internals/text.ts index 72782870a..3476de3f8 100644 --- a/src/ChartInternal/internals/text.ts +++ b/src/ChartInternal/internals/text.ts @@ -129,19 +129,19 @@ export default { const t: any = getRandom(); const opacityForText = forFlow ? 0 : $$.opacityForText.bind($$); - $$.$el.text.each(function() { + $$.$el.text.each(function(d, index: number) { const text = d3Select(this); // do not apply transition for newly added text elements (withTransition && text.attr("x") ? text.transition(t) : text) .call(selection => { - selection.each(function(d, i) { + selection.each(function(d) { d3Select(this) .style("fill", $$.updateTextColor.bind($$)) .style("fill-opacity", opacityForText); - const posX = x.bind(this)(d, i); - const posY = y.bind(this)(d, i); + const posX = x.bind(this)(d, index); + const posY = y.bind(this)(d, index); // when is multiline if (this.children.length) { diff --git a/test/shape/radar-spec.ts b/test/shape/radar-spec.ts index 8455f3251..862b35a4d 100644 --- a/test/shape/radar-spec.ts +++ b/test/shape/radar-spec.ts @@ -291,6 +291,45 @@ describe("SHAPE RADAR", () => { } }); }); + + it("set options", () => { + args = { + data: { + x: "x", + columns: [ + ["x", "Data A", "Data B", "Data C", "Data D", "Data E"], + ["data1", 330, 350, 200, 380, 150], + ["data2", 130, 100, 30, 200, 80], + ["data3", 230, 153, 85, 300, 250] + ], + type: "radar", // for ESM specify as: radar() + labels: true + }, + radar: { + axis: { + max: 400 + }, + level: { + depth: 4 + }, + direction: { + clockwise: true + } + } + } + }) + + it("check for data label text position", () => { + const pos = { + x: [218, 375.83020652047145, 273.73967547489525, 112.09461659769906, 150.35848291979795, 218, 263.0943447201347, 226.36095132123427, 162.26032452510478, 181.92452422389223, 218, 286.9943474218061, 241.68936207683046, 134.39048678765712, 105.26413819966326], + y: [55.5305, 160.71785724099158, 288.71908157657623, 357.76625499549493, 190.0219388175678, 150.3605, 197.34795921171187, 223.50786223648646, 288.71908157657623, 200.2783673693695, 102.94550000000001, 189.58237759391918, 244.6056096700449, 327.0786223648644, 175.36989802927968] + }; + + chart.$.text.texts.each(function() { + expect(+this.getAttribute("x")).to.be.equal(pos.x.shift()); + expect(+this.getAttribute("y")).to.be.equal(pos.y.shift()); + }); + }); }); describe("point.focus.only", () => {