@@ -98,12 +98,8 @@ module.exports = function draw(gd) {
98
98
var gs = fullLayout . _size ;
99
99
var bw = opts . borderwidth ;
100
100
101
- var lx = gs . l + gs . w * opts . x ;
102
- if ( Lib . isRightAnchor ( opts ) ) {
103
- lx -= opts . _width ;
104
- } else if ( Lib . isCenterAnchor ( opts ) ) {
105
- lx -= opts . _width / 2 ;
106
- }
101
+ var lx = gs . l + gs . w * opts . x - FROM_TL [ getXanchor ( opts ) ] * opts . _width ;
102
+ var ly = gs . t + gs . h * ( 1 - opts . y ) - FROM_TL [ getYanchor ( opts ) ] * opts . _effHeight ;
107
103
108
104
109
105
// Make sure the legend left and right sides are visible
@@ -119,12 +115,6 @@ module.exports = function draw(gd) {
119
115
legendWidth = Math . min ( fullLayout . width - lx , opts . _width ) ;
120
116
}
121
117
122
- var ly = gs . t + gs . h * ( 1 - opts . y ) ;
123
- if ( Lib . isBottomAnchor ( opts ) ) {
124
- ly -= opts . _height ;
125
- } else if ( Lib . isMiddleAnchor ( opts ) ) {
126
- ly -= opts . _height / 2 ;
127
- }
128
118
129
119
// Make sure the legend top and bottom are visible
130
120
// (legends with a scroll bar are not allowed to stretch beyond the extended
@@ -628,20 +618,9 @@ function computeLegendDimensions(gd, groups, traces) {
628
618
function expandMargin ( gd ) {
629
619
var fullLayout = gd . _fullLayout ;
630
620
var opts = fullLayout . legend ;
621
+ var xanchor = getXanchor ( opts ) ;
622
+ var yanchor = getYanchor ( opts ) ;
631
623
632
- var xanchor = 'left' ;
633
- if ( Lib . isRightAnchor ( opts ) ) {
634
- xanchor = 'right' ;
635
- } else if ( Lib . isCenterAnchor ( opts ) ) {
636
- xanchor = 'center' ;
637
- }
638
-
639
- var yanchor = 'top' ;
640
- if ( Lib . isBottomAnchor ( opts ) ) {
641
- yanchor = 'bottom' ;
642
- } else if ( Lib . isMiddleAnchor ( opts ) ) {
643
- yanchor = 'middle' ;
644
- }
645
624
646
625
Plots . autoMargin ( gd , 'legend' , {
647
626
x : opts . x ,
@@ -652,3 +631,15 @@ function expandMargin(gd) {
652
631
t : opts . _height * ( FROM_TL [ yanchor ] )
653
632
} ) ;
654
633
}
634
+
635
+ function getXanchor ( opts ) {
636
+ return Lib . isRightAnchor ( opts ) ? 'right' :
637
+ Lib . isCenterAnchor ( opts ) ? 'center' :
638
+ 'left' ;
639
+ }
640
+
641
+ function getYanchor ( opts ) {
642
+ return Lib . isBottomAnchor ( opts ) ? 'bottom' :
643
+ Lib . isMiddleAnchor ( opts ) ? 'middle' :
644
+ 'top' ;
645
+ }
0 commit comments