@@ -568,25 +568,7 @@ function transformInsideText(textBB, pt, cd0) {
568568 var isCircle = ( ring === 1 ) && ( Math . abs ( pt . startangle - pt . stopangle ) === Math . PI * 2 ) ;
569569 var allTransforms = [ ] ;
570570
571- if ( isCircle || isAuto || isHorizontal ) {
572- // max size text can be inserted inside without rotating it
573- // this inscribes the text rectangle in a circle, which is then inscribed
574- // in the slice, so it will be an underestimate, which some day we may want
575- // to improve so this case can get more use
576- var transform = {
577- scale : rInscribed * r * 2 / textDiameter ,
578-
579- // and the center position and rotation in this case
580- rCenter : 1 - rInscribed ,
581- rotate : 0
582- } ;
583-
584- if ( transform . scale >= 1 ) return transform ;
585-
586- allTransforms . push ( transform ) ;
587- }
588-
589- if ( isHorizontal ) {
571+ if ( ! isAuto ) {
590572 // max size if text is placed (horizontally) at the top or bottom of the arc
591573
592574 var considerCrossing = function ( angle , key ) {
@@ -608,12 +590,40 @@ function transformInsideText(textBB, pt, cd0) {
608590 }
609591 } ;
610592
611- for ( var i = 3 ; i >= - 3 ; i -- ) { // to cover all cases with trace.rotation added
612- considerCrossing ( Math . PI * i , 'tan' ) ;
613- considerCrossing ( Math . PI * ( i + 0.5 ) , 'rad' ) ;
593+ // to cover all cases with trace.rotation added
594+ var i ;
595+ if ( isHorizontal || isTangential ) {
596+ // top
597+ for ( i = 4 ; i >= - 4 ; i -= 2 ) considerCrossing ( Math . PI * i , 'tan' ) ;
598+ // bottom
599+ for ( i = 4 ; i >= - 4 ; i -= 2 ) considerCrossing ( Math . PI * ( i + 1 ) , 'tan' ) ;
600+ }
601+ if ( isHorizontal || isRadial ) {
602+ // left
603+ for ( i = 4 ; i >= - 4 ; i -= 2 ) considerCrossing ( Math . PI * ( i + 1.5 ) , 'rad' ) ;
604+ // right
605+ for ( i = 4 ; i >= - 4 ; i -= 2 ) considerCrossing ( Math . PI * ( i + 0.5 ) , 'rad' ) ;
614606 }
615607 }
616608
609+ if ( isCircle || isAuto || isHorizontal ) {
610+ // max size text can be inserted inside without rotating it
611+ // this inscribes the text rectangle in a circle, which is then inscribed
612+ // in the slice, so it will be an underestimate, which some day we may want
613+ // to improve so this case can get more use
614+ var transform = {
615+ scale : rInscribed * r * 2 / textDiameter ,
616+
617+ // and the center position and rotation in this case
618+ rCenter : 1 - rInscribed ,
619+ rotate : 0
620+ } ;
621+
622+ if ( transform . scale >= 1 ) return transform ;
623+
624+ allTransforms . push ( transform ) ;
625+ }
626+
617627 if ( isAuto || isRadial ) {
618628 allTransforms . push ( calcRadTransform ( textBB , r , ring , halfAngle , midAngle ) ) ;
619629 }
@@ -622,16 +632,29 @@ function transformInsideText(textBB, pt, cd0) {
622632 allTransforms . push ( calcTanTransform ( textBB , r , ring , halfAngle , midAngle ) ) ;
623633 }
624634
625- var maxScaleTransform = allTransforms . sort ( function ( a , b ) {
626- return b . scale - a . scale ;
627- } ) [ 0 ] ;
635+ var id = 0 ;
636+ var maxScale = 0 ;
637+ for ( var k = 0 ; k < allTransforms . length ; k ++ ) {
638+ var s = allTransforms [ k ] . scale ;
639+ if ( maxScale < s ) {
640+ maxScale = s ;
641+ id = k ;
642+ }
643+
644+ if ( ! isAuto && maxScale >= 1 ) {
645+ // respect test order for non-auto options
646+ break ;
647+ }
648+ }
649+
650+ var selTransform = allTransforms [ id ] ;
628651
629- if ( maxScaleTransform . pxtxt ) {
652+ if ( selTransform . pxtxt ) {
630653 // copy text position if not at the middle
631- pt . pxtxt = maxScaleTransform . pxtxt ;
654+ pt . pxtxt = selTransform . pxtxt ;
632655 }
633656
634- return maxScaleTransform ;
657+ return selTransform ;
635658}
636659
637660function isCrossing ( pt , angle ) {
0 commit comments