Skip to content

Commit 0e444b6

Browse files
authored
Merge pull request #4580 from plotly/fix4569-sunburst-hide-zero-value
Ensure text fits inside sunburst sectors with zero values
2 parents 4d24c36 + 6b86bfb commit 0e444b6

File tree

3 files changed

+68
-5
lines changed

3 files changed

+68
-5
lines changed

src/traces/pie/plot.js

+20-5
Original file line numberDiff line numberDiff line change
@@ -559,18 +559,31 @@ function prerenderTitles(cdModule, gd) {
559559
}
560560

561561
function transformInsideText(textBB, pt, cd0) {
562-
var textDiameter = Math.sqrt(textBB.width * textBB.width + textBB.height * textBB.height);
562+
var r = cd0.r || pt.rpx1;
563+
var rInscribed = pt.rInscribed;
564+
565+
var isEmpty = pt.startangle === pt.stopangle;
566+
if(isEmpty) {
567+
return {
568+
rCenter: 1 - rInscribed,
569+
scale: 0,
570+
rotate: 0,
571+
textPosAngle: 0
572+
};
573+
}
574+
575+
var ring = pt.ring;
576+
var isCircle = (ring === 1) && (Math.abs(pt.startangle - pt.stopangle) === Math.PI * 2);
577+
563578
var halfAngle = pt.halfangle;
564579
var midAngle = pt.midangle;
565-
var ring = pt.ring;
566-
var rInscribed = pt.rInscribed;
567-
var r = cd0.r || pt.rpx1;
580+
568581
var orientation = cd0.trace.insidetextorientation;
569582
var isHorizontal = orientation === 'horizontal';
570583
var isTangential = orientation === 'tangential';
571584
var isRadial = orientation === 'radial';
572585
var isAuto = orientation === 'auto';
573-
var isCircle = (ring === 1) && (Math.abs(pt.startangle - pt.stopangle) === Math.PI * 2);
586+
574587
var allTransforms = [];
575588
var newT;
576589

@@ -616,6 +629,8 @@ function transformInsideText(textBB, pt, cd0) {
616629
// this inscribes the text rectangle in a circle, which is then inscribed
617630
// in the slice, so it will be an underestimate, which some day we may want
618631
// to improve so this case can get more use
632+
var textDiameter = Math.sqrt(textBB.width * textBB.width + textBB.height * textBB.height);
633+
619634
newT = {
620635
scale: rInscribed * r * 2 / textDiameter,
621636

Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"data": [
3+
{
4+
"ids": [
5+
"A/a1",
6+
"A/a0",
7+
"B/b1",
8+
"B/b0",
9+
"A",
10+
"B"
11+
],
12+
"labels": [
13+
"a",
14+
"!a?",
15+
"b",
16+
"!b?",
17+
"A",
18+
"B"
19+
],
20+
"parents": [
21+
"A",
22+
"A",
23+
"B",
24+
"B",
25+
"",
26+
""
27+
],
28+
"type": "sunburst",
29+
"insidetextorientation": "horizontal",
30+
"branchvalues": "total",
31+
"values": [
32+
2,
33+
0,
34+
1,
35+
0,
36+
2,
37+
1
38+
]
39+
}
40+
],
41+
"layout": {
42+
"width": 400,
43+
"height": 400,
44+
"font": {
45+
"size": 20
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)