Skip to content

Commit

Permalink
skip: merge #1298
Browse files Browse the repository at this point in the history
  • Loading branch information
netil committed Apr 2, 2020
1 parent 808ca89 commit e9b1d7f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
48 changes: 48 additions & 0 deletions spec/shape/shape.arc-spec.ts
Expand Up @@ -225,6 +225,54 @@ describe("SHAPE ARC", () => {
});
});

it("check for Pie's threshold data label text", done => {
const chart = util.generate({
data: {
columns: [
["data1", 10],
["data2", 30],
["data3", 60]
],
type: "pie"
},
pie: {
label:{
threshold: 0.2
}
}
});

const checkText = () => {
chart.$.arc.selectAll("text").each(function(d, i) {
expect(this.textContent).to.be.equal(expectedText[i]);
});
};

let expectedText = ["", "30.0%", "60.0%"];

checkText();

new Promise((resolve, reject) => {
// when
chart.toggle("data3");
expectedText = ["25.0%", "75.0%", ""];

setTimeout(() => {
checkText();
resolve();
}, 200);
}).then(() => {
// when
chart.toggle("data3");
expectedText = ["", "30.0%", "60.0%"];

setTimeout(() => {
checkText();
done();
}, 200);
});
});

describe("show gauge", () => {
it("should have correct d for Pi radian gauge", done => {
const chart = util.generate({
Expand Down
9 changes: 5 additions & 4 deletions src/ChartInternal/shape/arc.ts
Expand Up @@ -275,25 +275,26 @@ export default {

textForArcLabel(selection: d3Selection): void {
const $$ = this;
const hasGauge = $$.hasType("gauge");

if ($$.shouldShowArcLabel()) {
selection.each(function(d) {
const node = d3Select(this);
const updated = $$.updateAngle(d);
const value = updated ? updated.value : d.value;
const ratio = $$.getRatio("arc", updated);
const id = d.data.id;
const hasGauge = $$.hasType("gauge");
const isUnderThreshold = !(
!hasGauge && !$$.meetsArcLabelThreshold(ratio)
);

if (isUnderThreshold) {
const {value} = updated || d;
const text = (
$$.getArcLabelFormat() || $$.defaultArcValueFormat
)(value, ratio, id).toString();
)(value, ratio, d.data.id).toString();

setTextValue(node, text, [-1, 1], hasGauge);
} else {
node.text("");
}
});
}
Expand Down

0 comments on commit e9b1d7f

Please sign in to comment.