Skip to content

Commit

Permalink
fix(radar): fix data label text position
Browse files Browse the repository at this point in the history
Fix incorrect text position coordinate value setting.

Fix #1871
  • Loading branch information
netil authored Jan 12, 2021
1 parent 673384e commit c69d674
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/ChartInternal/internals/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
39 changes: 39 additions & 0 deletions test/shape/radar-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down

0 comments on commit c69d674

Please sign in to comment.