@@ -207,13 +207,6 @@ module.exports = function draw(gd) {
207
207
// legend, background and border, scroll box and scroll bar
208
208
Drawing . setTranslate ( legend , lx , ly ) ;
209
209
210
- var scrollBarYMax = legendHeight -
211
- constants . scrollBarHeight -
212
- 2 * constants . scrollBarMargin ,
213
- scrollBoxYMax = opts . _height - legendHeight ,
214
- scrollBarY ,
215
- scrollBoxY ;
216
-
217
210
if ( opts . _height <= legendHeight || gd . _context . staticPlot ) {
218
211
// if scrollbar should not be shown.
219
212
bg . attr ( {
@@ -235,8 +228,15 @@ module.exports = function draw(gd) {
235
228
scrollBox . call ( Drawing . setClipUrl , clipId ) ;
236
229
}
237
230
else {
238
- scrollBarY = constants . scrollBarMargin ,
239
- scrollBoxY = scrollBox . attr ( 'data-scroll' ) || 0 ;
231
+ var scrollBarHeight = Math . max ( constants . scrollBarMinHeight ,
232
+ legendHeight * legendHeight / opts . _height ) ;
233
+ var scrollBarYMax = legendHeight -
234
+ scrollBarHeight -
235
+ 2 * constants . scrollBarMargin ;
236
+ var scrollBoxYMax = opts . _height - legendHeight ;
237
+
238
+ var scrollBarY = constants . scrollBarMargin ;
239
+ var scrollBoxY = scrollBox . attr ( 'data-scroll' ) || 0 ;
240
240
241
241
// increase the background and clip-path width
242
242
// by the scrollbar width and margin
@@ -262,7 +262,7 @@ module.exports = function draw(gd) {
262
262
263
263
scrollBox . call ( Drawing . setClipUrl , clipId ) ;
264
264
265
- if ( firstRender ) scrollHandler ( scrollBarY , scrollBoxY ) ;
265
+ if ( firstRender ) scrollHandler ( scrollBarY , scrollBoxY , scrollBarHeight ) ;
266
266
267
267
legend . on ( 'wheel' , null ) ; // to be safe, remove previous listeners
268
268
legend . on ( 'wheel' , function ( ) {
@@ -272,7 +272,7 @@ module.exports = function draw(gd) {
272
272
- scrollBoxYMax , 0 ) ;
273
273
scrollBarY = constants . scrollBarMargin -
274
274
scrollBoxY / scrollBoxYMax * scrollBarYMax ;
275
- scrollHandler ( scrollBarY , scrollBoxY ) ;
275
+ scrollHandler ( scrollBarY , scrollBoxY , scrollBarHeight ) ;
276
276
if ( scrollBoxY !== 0 && scrollBoxY !== - scrollBoxYMax ) {
277
277
d3 . event . preventDefault ( ) ;
278
278
}
@@ -299,14 +299,14 @@ module.exports = function draw(gd) {
299
299
constants . scrollBarMargin + scrollBarYMax ) ;
300
300
scrollBoxY = - ( scrollBarY - constants . scrollBarMargin ) /
301
301
scrollBarYMax * scrollBoxYMax ;
302
- scrollHandler ( scrollBarY , scrollBoxY ) ;
302
+ scrollHandler ( scrollBarY , scrollBoxY , scrollBarHeight ) ;
303
303
} ) ;
304
304
305
305
scrollBar . call ( drag ) ;
306
306
}
307
307
308
308
309
- function scrollHandler ( scrollBarY , scrollBoxY ) {
309
+ function scrollHandler ( scrollBarY , scrollBoxY , scrollBarHeight ) {
310
310
scrollBox
311
311
. attr ( 'data-scroll' , scrollBoxY )
312
312
. call ( Drawing . setTranslate , 0 , scrollBoxY ) ;
@@ -316,7 +316,7 @@ module.exports = function draw(gd) {
316
316
legendWidth ,
317
317
scrollBarY ,
318
318
constants . scrollBarWidth ,
319
- constants . scrollBarHeight
319
+ scrollBarHeight
320
320
) ;
321
321
clipPath . select ( 'rect' ) . attr ( {
322
322
y : opts . borderwidth - scrollBoxY
0 commit comments