@@ -175,16 +175,12 @@ function plot(gd, cdModule) {
175175
176176 transform = transformOutsideText ( textBB , pt ) ;
177177 }
178-
179- if ( transform . pxtxt ) {
180- // copy text position if not at the middle
181- pt . pxtxt = transform . pxtxt ;
182- }
183178 }
184179
185- var pxtxt = pt . pxtxt || pt . pxmid ;
186- transform . targetX = cx + pxtxt [ 0 ] * transform . rCenter + ( transform . x || 0 ) ;
187- transform . targetY = cy + pxtxt [ 1 ] * transform . rCenter + ( transform . y || 0 ) ;
180+ var textPosAngle = transform . textPosAngle ;
181+ var textXY = textPosAngle === undefined ? pt . pxmid : getCoords ( cd0 . r , textPosAngle ) ;
182+ transform . targetX = cx + textXY [ 0 ] * transform . rCenter + ( transform . x || 0 ) ;
183+ transform . targetY = cy + textXY [ 1 ] * transform . rCenter + ( transform . y || 0 ) ;
188184 computeTransform ( transform , textBB ) ;
189185
190186 // save some stuff to use later ensure no labels overlap
@@ -572,6 +568,7 @@ function transformInsideText(textBB, pt, cd0) {
572568 var isAuto = orientation === 'auto' ;
573569 var isCircle = ( ring === 1 ) && ( Math . abs ( pt . startangle - pt . stopangle ) === Math . PI * 2 ) ;
574570 var allTransforms = [ ] ;
571+ var newT ;
575572
576573 if ( ! isAuto ) {
577574 // max size if text is placed (horizontally) at the top or bottom of the arc
@@ -583,13 +580,12 @@ function transformInsideText(textBB, pt, cd0) {
583580
584581 var closestEdge = dStart < dStop ? dStart : dStop ;
585582
586- var newT ;
587583 if ( key === 'tan' ) {
588584 newT = calcTanTransform ( textBB , r , ring , closestEdge , 0 ) ;
589585 } else { // case of 'rad'
590586 newT = calcRadTransform ( textBB , r , ring , closestEdge , Math . PI / 2 ) ;
591587 }
592- newT . pxtxt = getCoords ( r , angle ) ;
588+ newT . textPosAngle = angle ;
593589
594590 allTransforms . push ( newT ) ;
595591 }
@@ -616,25 +612,30 @@ function transformInsideText(textBB, pt, cd0) {
616612 // this inscribes the text rectangle in a circle, which is then inscribed
617613 // in the slice, so it will be an underestimate, which some day we may want
618614 // to improve so this case can get more use
619- var transform = {
615+ newT = {
620616 scale : rInscribed * r * 2 / textDiameter ,
621617
622618 // and the center position and rotation in this case
623619 rCenter : 1 - rInscribed ,
624620 rotate : 0
625621 } ;
626622
627- if ( transform . scale >= 1 ) return transform ;
623+ newT . textPosAngle = ( pt . startangle + pt . stopangle ) / 2 ;
624+ if ( newT . scale >= 1 ) return newT ;
628625
629- allTransforms . push ( transform ) ;
626+ allTransforms . push ( newT ) ;
630627 }
631628
632629 if ( isAuto || isRadial ) {
633- allTransforms . push ( calcRadTransform ( textBB , r , ring , halfAngle , midAngle ) ) ;
630+ newT = calcRadTransform ( textBB , r , ring , halfAngle , midAngle ) ;
631+ newT . textPosAngle = ( pt . startangle + pt . stopangle ) / 2 ;
632+ allTransforms . push ( newT ) ;
634633 }
635634
636635 if ( isAuto || isTangential ) {
637- allTransforms . push ( calcTanTransform ( textBB , r , ring , halfAngle , midAngle ) ) ;
636+ newT = calcTanTransform ( textBB , r , ring , halfAngle , midAngle ) ;
637+ newT . textPosAngle = ( pt . startangle + pt . stopangle ) / 2 ;
638+ allTransforms . push ( newT ) ;
638639 }
639640
640641 var id = 0 ;
0 commit comments