@@ -734,6 +734,8 @@ function calcTextPosition(shapex0, shapey0, shapex1, shapey1, shapeOptions, actu
734
734
var textPadding = shapeOptions . label . padding ;
735
735
var shapeType = shapeOptions . type ;
736
736
var textAngleRad = Math . PI / 180 * actualTextAngle ;
737
+ var sinA = Math . sin ( textAngleRad ) ;
738
+ var cosA = Math . cos ( textAngleRad ) ;
737
739
var xanchor = shapeOptions . label . xanchor ;
738
740
var yanchor = shapeOptions . label . yanchor ;
739
741
@@ -788,8 +790,8 @@ function calcTextPosition(shapex0, shapey0, shapex1, shapey1, shapeOptions, actu
788
790
if ( textAngle === 'auto' ) {
789
791
// Set direction to apply padding (based on `yanchor` only)
790
792
var paddingDirection = paddingConstantsY [ yanchor ] ;
791
- paddingX = - textPadding * Math . sin ( textAngleRad ) * paddingDirection ;
792
- paddingY = textPadding * Math . cos ( textAngleRad ) * paddingDirection ;
793
+ paddingX = - textPadding * sinA * paddingDirection ;
794
+ paddingY = textPadding * cosA * paddingDirection ;
793
795
} else {
794
796
// Set direction to apply padding (based on `xanchor` and `yanchor`)
795
797
var paddingDirectionX = paddingConstantsX [ xanchor ] ;
@@ -837,8 +839,8 @@ function calcTextPosition(shapex0, shapey0, shapex1, shapey1, shapeOptions, actu
837
839
// Adjust so that text is anchored at top of first line rather than at baseline of first line
838
840
var baselineAdjust = shapeOptions . label . font . size ;
839
841
var textHeight = textBB . height ;
840
- var xshift = ( textHeight * shiftFraction - baselineAdjust ) * Math . sin ( textAngleRad ) ;
841
- var yshift = - ( textHeight * shiftFraction - baselineAdjust ) * Math . cos ( textAngleRad ) ;
842
+ var xshift = ( textHeight * shiftFraction - baselineAdjust ) * sinA ;
843
+ var yshift = - ( textHeight * shiftFraction - baselineAdjust ) * cosA ;
842
844
843
845
return { textx : textx + xshift , texty : texty + yshift , xanchor : xanchor } ;
844
846
}
0 commit comments