diff --git a/src/traces/pie/plot.js b/src/traces/pie/plot.js index b8505618ef9..624d0825d59 100644 --- a/src/traces/pie/plot.js +++ b/src/traces/pie/plot.js @@ -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, + 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; @@ -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, diff --git a/test/image/baselines/sunburst_zero_values_textfit.png b/test/image/baselines/sunburst_zero_values_textfit.png new file mode 100644 index 00000000000..01f075a6967 Binary files /dev/null and b/test/image/baselines/sunburst_zero_values_textfit.png differ diff --git a/test/image/mocks/sunburst_zero_values_textfit.json b/test/image/mocks/sunburst_zero_values_textfit.json new file mode 100644 index 00000000000..187c12231ec --- /dev/null +++ b/test/image/mocks/sunburst_zero_values_textfit.json @@ -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 + } + } +}