@@ -513,16 +513,17 @@ function prerenderTitles(cdpie, gd) {
513
513
function transformInsideText ( textBB , pt , cd0 ) {
514
514
var textDiameter = Math . sqrt ( textBB . width * textBB . width + textBB . height * textBB . height ) ;
515
515
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 ;
519
520
520
521
// max size text can be inserted inside without rotating it
521
522
// this inscribes the text rectangle in a circle, which is then inscribed
522
523
// in the slice, so it will be an underestimate, which some day we may want
523
524
// to improve so this case can get more use
524
525
var transform = {
525
- scale : rInscribed * cd0 . r * 2 / textDiameter ,
526
+ scale : rInscribed * r * 2 / textDiameter ,
526
527
527
528
// and the center position and rotation in this case
528
529
rCenter : 1 - rInscribed ,
@@ -533,28 +534,28 @@ function transformInsideText(textBB, pt, cd0) {
533
534
534
535
// max size if text is rotated radially
535
536
var Qr = textAspect + 1 / ( 2 * Math . tan ( halfAngle ) ) ;
536
- var maxHalfHeightRotRadial = cd0 . r * Math . min (
537
+ var maxHalfHeightRotRadial = r * Math . min (
537
538
1 / ( Math . sqrt ( Qr * Qr + 0.5 ) + Qr ) ,
538
539
ring / ( Math . sqrt ( textAspect * textAspect + ring / 2 ) + textAspect )
539
540
) ;
540
541
var radialTransform = {
541
542
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 ,
544
545
rotate : ( 180 / Math . PI * pt . midangle + 720 ) % 180 - 90
545
546
} ;
546
547
547
548
// max size if text is rotated tangentially
548
549
var aspectInv = 1 / textAspect ;
549
550
var Qt = aspectInv + 1 / ( 2 * Math . tan ( halfAngle ) ) ;
550
- var maxHalfWidthTangential = cd0 . r * Math . min (
551
+ var maxHalfWidthTangential = r * Math . min (
551
552
1 / ( Math . sqrt ( Qt * Qt + 0.5 ) + Qt ) ,
552
553
ring / ( Math . sqrt ( aspectInv * aspectInv + ring / 2 ) + aspectInv )
553
554
) ;
554
555
var tangentialTransform = {
555
556
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 ,
558
559
rotate : ( 180 / Math . PI * pt . midangle + 810 ) % 180 - 90
559
560
} ;
560
561
// if we need a rotated transform, pick the biggest one
@@ -569,8 +570,7 @@ function transformInsideText(textBB, pt, cd0) {
569
570
function getInscribedRadiusFraction ( pt , cd0 ) {
570
571
if ( pt . v === cd0 . vTotal && ! cd0 . trace . hole ) return 1 ; // special case of 100% with no hole
571
572
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 ) ;
574
574
}
575
575
576
576
function transformOutsideText ( textBB , pt ) {
@@ -838,7 +838,6 @@ function scalePies(cdpie, plotSize) {
838
838
}
839
839
}
840
840
}
841
-
842
841
}
843
842
844
843
function setCoords ( cd ) {
@@ -885,6 +884,10 @@ function setCoords(cd) {
885
884
cdi [ lastPt ] = currentCoords ;
886
885
887
886
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 ) ;
888
891
}
889
892
}
890
893
0 commit comments