@@ -678,18 +678,13 @@ function drawLabel(gd, index, options, shapeGroup) {
678
678
}
679
679
}
680
680
681
- // Do a fake render so we can get the text bounding box height
682
- var _labelText = labelGroup . append ( 'text' )
683
- . attr ( labelTextAttrs )
684
- . classed ( 'shape-label-text' , true )
685
- . text ( text ) ;
686
- _labelText . call ( function ( s ) {
681
+ // Do an initial render so we can get the text bounding box height
682
+ labelText . call ( function ( s ) {
687
683
s . call ( Drawing . font , font ) . attr ( { } ) ;
688
684
svgTextUtils . convertToTspans ( s , gd ) ;
689
685
return s ;
690
686
} ) ;
691
- var textBB = Drawing . bBox ( _labelText . node ( ) ) ;
692
- _labelText . remove ( ) ;
687
+ var textBB = Drawing . bBox ( labelText . node ( ) ) ;
693
688
694
689
// Calculate correct (x,y) for text
695
690
// We also determine true xanchor since xanchor depends on position when set to 'auto'
@@ -698,23 +693,17 @@ function drawLabel(gd, index, options, shapeGroup) {
698
693
var texty = textPos . texty ;
699
694
var xanchor = textPos . xanchor ;
700
695
701
- function textLayout ( s ) {
702
- s . call ( Drawing . font , font )
703
- . attr ( {
704
- 'text-anchor' : {
705
- left : 'start' ,
706
- center : 'middle' ,
707
- right : 'end'
708
- } [ xanchor ] ,
709
- 'y' : texty ,
710
- 'x' : textx ,
711
- 'transform' : 'rotate(' + textangle + ',' + textx + ',' + texty + ')'
712
- } ) ;
713
- svgTextUtils . convertToTspans ( s , gd ) ;
714
- return s ;
715
- }
716
-
717
- labelText . call ( textLayout ) ;
696
+ // Update (x,y) position, xanchor, and angle
697
+ labelText . attr ( {
698
+ 'text-anchor' : {
699
+ left : 'start' ,
700
+ center : 'middle' ,
701
+ right : 'end'
702
+ } [ xanchor ] ,
703
+ 'y' : texty ,
704
+ 'x' : textx ,
705
+ 'transform' : 'rotate(' + textangle + ',' + textx + ',' + texty + ')'
706
+ } ) . call ( svgTextUtils . positionText , textx , texty ) ;
718
707
}
719
708
720
709
function calcTextAngle ( shapex0 , shapey0 , shapex1 , shapey1 ) {
0 commit comments