@@ -175,16 +175,12 @@ function plot(gd, cdModule) {
175
175
176
176
transform = transformOutsideText ( textBB , pt ) ;
177
177
}
178
-
179
- if ( transform . pxtxt ) {
180
- // copy text position if not at the middle
181
- pt . pxtxt = transform . pxtxt ;
182
- }
183
178
}
184
179
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 ) ;
188
184
computeTransform ( transform , textBB ) ;
189
185
190
186
// save some stuff to use later ensure no labels overlap
@@ -572,6 +568,7 @@ function transformInsideText(textBB, pt, cd0) {
572
568
var isAuto = orientation === 'auto' ;
573
569
var isCircle = ( ring === 1 ) && ( Math . abs ( pt . startangle - pt . stopangle ) === Math . PI * 2 ) ;
574
570
var allTransforms = [ ] ;
571
+ var newT ;
575
572
576
573
if ( ! isAuto ) {
577
574
// max size if text is placed (horizontally) at the top or bottom of the arc
@@ -583,13 +580,12 @@ function transformInsideText(textBB, pt, cd0) {
583
580
584
581
var closestEdge = dStart < dStop ? dStart : dStop ;
585
582
586
- var newT ;
587
583
if ( key === 'tan' ) {
588
584
newT = calcTanTransform ( textBB , r , ring , closestEdge , 0 ) ;
589
585
} else { // case of 'rad'
590
586
newT = calcRadTransform ( textBB , r , ring , closestEdge , Math . PI / 2 ) ;
591
587
}
592
- newT . pxtxt = getCoords ( r , angle ) ;
588
+ newT . textPosAngle = angle ;
593
589
594
590
allTransforms . push ( newT ) ;
595
591
}
@@ -616,25 +612,30 @@ function transformInsideText(textBB, pt, cd0) {
616
612
// this inscribes the text rectangle in a circle, which is then inscribed
617
613
// in the slice, so it will be an underestimate, which some day we may want
618
614
// to improve so this case can get more use
619
- var transform = {
615
+ newT = {
620
616
scale : rInscribed * r * 2 / textDiameter ,
621
617
622
618
// and the center position and rotation in this case
623
619
rCenter : 1 - rInscribed ,
624
620
rotate : 0
625
621
} ;
626
622
627
- if ( transform . scale >= 1 ) return transform ;
623
+ newT . textPosAngle = ( pt . startangle + pt . stopangle ) / 2 ;
624
+ if ( newT . scale >= 1 ) return newT ;
628
625
629
- allTransforms . push ( transform ) ;
626
+ allTransforms . push ( newT ) ;
630
627
}
631
628
632
629
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 ) ;
634
633
}
635
634
636
635
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 ) ;
638
639
}
639
640
640
641
var id = 0 ;
0 commit comments