@@ -513,16 +513,17 @@ function prerenderTitles(cdpie, gd) {
513513function transformInsideText ( textBB , pt , cd0 ) {
514514 var textDiameter = Math . sqrt ( textBB . width * textBB . width + textBB . height * textBB . height ) ;
515515 var textAspect = textBB . width / textBB . height ;
516- var halfAngle = Math . PI * Math . min ( pt . v / cd0 . vTotal , 0.5 ) ;
517- var ring = 1 - cd0 . trace . hole ;
518- var rInscribed = getInscribedRadiusFraction ( pt , cd0 ) ;
516+ var halfAngle = pt . halfangle ;
517+ var ring = pt . ring ;
518+ var rInscribed = pt . rInscribed ;
519+ var r = cd0 . r || pt . rpx1 ;
519520
520521 // max size text can be inserted inside without rotating it
521522 // this inscribes the text rectangle in a circle, which is then inscribed
522523 // in the slice, so it will be an underestimate, which some day we may want
523524 // to improve so this case can get more use
524525 var transform = {
525- scale : rInscribed * cd0 . r * 2 / textDiameter ,
526+ scale : rInscribed * r * 2 / textDiameter ,
526527
527528 // and the center position and rotation in this case
528529 rCenter : 1 - rInscribed ,
@@ -533,28 +534,28 @@ function transformInsideText(textBB, pt, cd0) {
533534
534535 // max size if text is rotated radially
535536 var Qr = textAspect + 1 / ( 2 * Math . tan ( halfAngle ) ) ;
536- var maxHalfHeightRotRadial = cd0 . r * Math . min (
537+ var maxHalfHeightRotRadial = r * Math . min (
537538 1 / ( Math . sqrt ( Qr * Qr + 0.5 ) + Qr ) ,
538539 ring / ( Math . sqrt ( textAspect * textAspect + ring / 2 ) + textAspect )
539540 ) ;
540541 var radialTransform = {
541542 scale : maxHalfHeightRotRadial * 2 / textBB . height ,
542- rCenter : Math . cos ( maxHalfHeightRotRadial / cd0 . r ) -
543- maxHalfHeightRotRadial * textAspect / cd0 . r ,
543+ rCenter : Math . cos ( maxHalfHeightRotRadial / r ) -
544+ maxHalfHeightRotRadial * textAspect / r ,
544545 rotate : ( 180 / Math . PI * pt . midangle + 720 ) % 180 - 90
545546 } ;
546547
547548 // max size if text is rotated tangentially
548549 var aspectInv = 1 / textAspect ;
549550 var Qt = aspectInv + 1 / ( 2 * Math . tan ( halfAngle ) ) ;
550- var maxHalfWidthTangential = cd0 . r * Math . min (
551+ var maxHalfWidthTangential = r * Math . min (
551552 1 / ( Math . sqrt ( Qt * Qt + 0.5 ) + Qt ) ,
552553 ring / ( Math . sqrt ( aspectInv * aspectInv + ring / 2 ) + aspectInv )
553554 ) ;
554555 var tangentialTransform = {
555556 scale : maxHalfWidthTangential * 2 / textBB . width ,
556- rCenter : Math . cos ( maxHalfWidthTangential / cd0 . r ) -
557- maxHalfWidthTangential / textAspect / cd0 . r ,
557+ rCenter : Math . cos ( maxHalfWidthTangential / r ) -
558+ maxHalfWidthTangential / textAspect / r ,
558559 rotate : ( 180 / Math . PI * pt . midangle + 810 ) % 180 - 90
559560 } ;
560561 // if we need a rotated transform, pick the biggest one
@@ -569,8 +570,7 @@ function transformInsideText(textBB, pt, cd0) {
569570function getInscribedRadiusFraction ( pt , cd0 ) {
570571 if ( pt . v === cd0 . vTotal && ! cd0 . trace . hole ) return 1 ; // special case of 100% with no hole
571572
572- var halfAngle = Math . PI * Math . min ( pt . v / cd0 . vTotal , 0.5 ) ;
573- return Math . min ( 1 / ( 1 + 1 / Math . sin ( halfAngle ) ) , ( 1 - cd0 . trace . hole ) / 2 ) ;
573+ return Math . min ( 1 / ( 1 + 1 / Math . sin ( pt . halfangle ) ) , pt . ring / 2 ) ;
574574}
575575
576576function transformOutsideText ( textBB , pt ) {
@@ -838,7 +838,6 @@ function scalePies(cdpie, plotSize) {
838838 }
839839 }
840840 }
841-
842841}
843842
844843function setCoords ( cd ) {
@@ -885,6 +884,10 @@ function setCoords(cd) {
885884 cdi [ lastPt ] = currentCoords ;
886885
887886 cdi . largeArc = ( cdi . v > cd0 . vTotal / 2 ) ? 1 : 0 ;
887+
888+ cdi . halfangle = Math . PI * Math . min ( cdi . v / cd0 . vTotal , 0.5 ) ;
889+ cdi . ring = 1 - trace . hole ;
890+ cdi . rInscribed = getInscribedRadiusFraction ( cdi , cd0 ) ;
888891 }
889892}
890893
0 commit comments