Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/traces/pie/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,18 +559,31 @@ function prerenderTitles(cdModule, gd) {
}

function transformInsideText(textBB, pt, cd0) {
var textDiameter = Math.sqrt(textBB.width * textBB.width + textBB.height * textBB.height);
var r = cd0.r || pt.rpx1;
var rInscribed = pt.rInscribed;

var isEmpty = pt.startangle === pt.stopangle;
if(isEmpty) {
return {
rCenter: 1 - rInscribed,
scale: 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, by fitting inside text of zero-value sunburst sectors, you mean setting their scale transform to 0, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other option (not implemented here) may be not to draw sectors with zero values.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or set them with display: 'none', to keep the sector <--> node map 1:1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... but really, this is fine. It allows us to keep all the logic in transformInsideText.

rotate: 0,
textPosAngle: 0
};
}

var ring = pt.ring;
var isCircle = (ring === 1) && (Math.abs(pt.startangle - pt.stopangle) === Math.PI * 2);

var halfAngle = pt.halfangle;
var midAngle = pt.midangle;
var ring = pt.ring;
var rInscribed = pt.rInscribed;
var r = cd0.r || pt.rpx1;

var orientation = cd0.trace.insidetextorientation;
var isHorizontal = orientation === 'horizontal';
var isTangential = orientation === 'tangential';
var isRadial = orientation === 'radial';
var isAuto = orientation === 'auto';
var isCircle = (ring === 1) && (Math.abs(pt.startangle - pt.stopangle) === Math.PI * 2);

var allTransforms = [];
var newT;

Expand Down Expand Up @@ -616,6 +629,8 @@ function transformInsideText(textBB, pt, cd0) {
// this inscribes the text rectangle in a circle, which is then inscribed
// in the slice, so it will be an underestimate, which some day we may want
// to improve so this case can get more use
var textDiameter = Math.sqrt(textBB.width * textBB.width + textBB.height * textBB.height);

newT = {
scale: rInscribed * r * 2 / textDiameter,

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions test/image/mocks/sunburst_zero_values_textfit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"data": [
{
"ids": [
"A/a1",
"A/a0",
"B/b1",
"B/b0",
"A",
"B"
],
"labels": [
"a",
"!a?",
"b",
"!b?",
"A",
"B"
],
"parents": [
"A",
"A",
"B",
"B",
"",
""
],
"type": "sunburst",
"insidetextorientation": "horizontal",
"branchvalues": "total",
"values": [
2,
0,
1,
0,
2,
1
]
}
],
"layout": {
"width": 400,
"height": 400,
"font": {
"size": 20
}
}
}