@@ -95,30 +95,16 @@ module.exports = function draw(gd) {
95
95
function ( ) { return computeLegendDimensions ( gd , groups , traces ) ; } ,
96
96
function ( ) { return expandMargin ( gd ) ; } ,
97
97
function ( ) {
98
- // Position and size the legend
99
- var lxMin = 0 ;
100
- var lxMax = fullLayout . width ;
101
- var lyMin = 0 ;
102
- var lyMax = fullLayout . height ;
103
-
104
- // Scroll section must be executed after repositionLegend.
105
- // It requires the legend width, height, x and y to position the scrollbox
106
- // and these values are mutated in repositionLegend.
107
98
var gs = fullLayout . _size ;
108
- var lx = gs . l + gs . w * opts . x ;
109
- var ly = gs . t + gs . h * ( 1 - opts . y ) ;
99
+ var bw = opts . borderwidth ;
110
100
101
+ var lx = gs . l + gs . w * opts . x ;
111
102
if ( Lib . isRightAnchor ( opts ) ) {
112
103
lx -= opts . _width ;
113
104
} else if ( Lib . isCenterAnchor ( opts ) ) {
114
105
lx -= opts . _width / 2 ;
115
106
}
116
107
117
- if ( Lib . isBottomAnchor ( opts ) ) {
118
- ly -= opts . _height ;
119
- } else if ( Lib . isMiddleAnchor ( opts ) ) {
120
- ly -= opts . _height / 2 ;
121
- }
122
108
123
109
// Make sure the legend left and right sides are visible
124
110
var legendWidth = opts . _width ;
@@ -128,9 +114,16 @@ module.exports = function draw(gd) {
128
114
lx = gs . l ;
129
115
legendWidth = legendWidthMax ;
130
116
} else {
131
- if ( lx + legendWidth > lxMax ) lx = lxMax - legendWidth ;
132
- if ( lx < lxMin ) lx = lxMin ;
133
- legendWidth = Math . min ( lxMax - lx , opts . _width ) ;
117
+ if ( lx + legendWidth > fullLayout . width ) lx = fullLayout . width - legendWidth ;
118
+ if ( lx < 0 ) lx = 0 ;
119
+ legendWidth = Math . min ( fullLayout . width - lx , opts . _width ) ;
120
+ }
121
+
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 ;
134
127
}
135
128
136
129
// Make sure the legend top and bottom are visible
@@ -143,9 +136,9 @@ module.exports = function draw(gd) {
143
136
ly = gs . t ;
144
137
legendHeight = legendHeightMax ;
145
138
} else {
146
- if ( ly + legendHeight > lyMax ) ly = lyMax - legendHeight ;
147
- if ( ly < lyMin ) ly = lyMin ;
148
- legendHeight = Math . min ( lyMax - ly , opts . _height ) ;
139
+ if ( ly + legendHeight > fullLayout . height ) ly = fullLayout . height - legendHeight ;
140
+ if ( ly < 0 ) ly = 0 ;
141
+ legendHeight = Math . min ( fullLayout . height - ly , opts . _height ) ;
149
142
}
150
143
151
144
// Set size and position of all the elements that make up a legend:
@@ -159,19 +152,19 @@ module.exports = function draw(gd) {
159
152
if ( opts . _height <= legendHeight || gd . _context . staticPlot ) {
160
153
// if scrollbar should not be shown.
161
154
bg . attr ( {
162
- width : legendWidth - opts . borderwidth ,
163
- height : legendHeight - opts . borderwidth ,
164
- x : opts . borderwidth / 2 ,
165
- y : opts . borderwidth / 2
155
+ width : legendWidth - bw ,
156
+ height : legendHeight - bw ,
157
+ x : bw / 2 ,
158
+ y : bw / 2
166
159
} ) ;
167
160
168
161
Drawing . setTranslate ( scrollBox , 0 , 0 ) ;
169
162
170
163
clipPath . select ( 'rect' ) . attr ( {
171
- width : legendWidth - 2 * opts . borderwidth ,
172
- height : legendHeight - 2 * opts . borderwidth ,
173
- x : opts . borderwidth ,
174
- y : opts . borderwidth
164
+ width : legendWidth - 2 * bw ,
165
+ height : legendHeight - 2 * bw ,
166
+ x : bw ,
167
+ y : bw
175
168
} ) ;
176
169
177
170
Drawing . setClipUrl ( scrollBox , clipId , gd ) ;
@@ -193,22 +186,22 @@ module.exports = function draw(gd) {
193
186
// by the scrollbar width and margin
194
187
bg . attr ( {
195
188
width : legendWidth -
196
- 2 * opts . borderwidth +
189
+ 2 * bw +
197
190
constants . scrollBarWidth +
198
191
constants . scrollBarMargin ,
199
- height : legendHeight - opts . borderwidth ,
200
- x : opts . borderwidth / 2 ,
201
- y : opts . borderwidth / 2
192
+ height : legendHeight - bw ,
193
+ x : bw / 2 ,
194
+ y : bw / 2
202
195
} ) ;
203
196
204
197
clipPath . select ( 'rect' ) . attr ( {
205
198
width : legendWidth -
206
- 2 * opts . borderwidth +
199
+ 2 * bw +
207
200
constants . scrollBarWidth +
208
201
constants . scrollBarMargin ,
209
- height : legendHeight - 2 * opts . borderwidth ,
210
- x : opts . borderwidth ,
211
- y : opts . borderwidth + scrollBoxY
202
+ height : legendHeight - 2 * bw ,
203
+ x : bw ,
204
+ y : bw + scrollBoxY
212
205
} ) ;
213
206
214
207
Drawing . setClipUrl ( scrollBox , clipId , gd ) ;
@@ -246,7 +239,6 @@ module.exports = function draw(gd) {
246
239
scrollBar . call ( drag ) ;
247
240
}
248
241
249
-
250
242
function scrollHandler ( scrollBoxY , scrollBarHeight , scrollRatio ) {
251
243
opts . _scrollY = gd . _fullLayout . legend . _scrollY = scrollBoxY ;
252
244
Drawing . setTranslate ( scrollBox , 0 , - scrollBoxY ) ;
@@ -271,7 +263,6 @@ module.exports = function draw(gd) {
271
263
gd : gd ,
272
264
prepFn : function ( ) {
273
265
var transform = Drawing . getTranslate ( legend ) ;
274
-
275
266
x0 = transform . x ;
276
267
y0 = transform . y ;
277
268
} ,
@@ -634,7 +625,6 @@ function computeLegendDimensions(gd, groups, traces) {
634
625
opts . _height += endPad ;
635
626
}
636
627
637
- // make sure we're only getting full pixels
638
628
opts . _width = Math . ceil ( opts . _width ) ;
639
629
opts . _height = Math . ceil ( opts . _height ) ;
640
630
@@ -672,7 +662,6 @@ function expandMargin(gd) {
672
662
yanchor = 'middle' ;
673
663
}
674
664
675
- // lastly check if the margin auto-expand has changed
676
665
Plots . autoMargin ( gd , 'legend' , {
677
666
x : opts . x ,
678
667
y : opts . y ,
0 commit comments