@@ -207,13 +207,6 @@ module.exports = function draw(gd) {
207207 // legend, background and border, scroll box and scroll bar
208208 Drawing . setTranslate ( legend , lx , ly ) ;
209209
210- var scrollBarYMax = legendHeight -
211- constants . scrollBarHeight -
212- 2 * constants . scrollBarMargin ,
213- scrollBoxYMax = opts . _height - legendHeight ,
214- scrollBarY ,
215- scrollBoxY ;
216-
217210 if ( opts . _height <= legendHeight || gd . _context . staticPlot ) {
218211 // if scrollbar should not be shown.
219212 bg . attr ( {
@@ -235,8 +228,15 @@ module.exports = function draw(gd) {
235228 scrollBox . call ( Drawing . setClipUrl , clipId ) ;
236229 }
237230 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 ;
240240
241241 // increase the background and clip-path width
242242 // by the scrollbar width and margin
@@ -262,7 +262,7 @@ module.exports = function draw(gd) {
262262
263263 scrollBox . call ( Drawing . setClipUrl , clipId ) ;
264264
265- if ( firstRender ) scrollHandler ( scrollBarY , scrollBoxY ) ;
265+ if ( firstRender ) scrollHandler ( scrollBarY , scrollBoxY , scrollBarHeight ) ;
266266
267267 legend . on ( 'wheel' , null ) ; // to be safe, remove previous listeners
268268 legend . on ( 'wheel' , function ( ) {
@@ -272,7 +272,7 @@ module.exports = function draw(gd) {
272272 - scrollBoxYMax , 0 ) ;
273273 scrollBarY = constants . scrollBarMargin -
274274 scrollBoxY / scrollBoxYMax * scrollBarYMax ;
275- scrollHandler ( scrollBarY , scrollBoxY ) ;
275+ scrollHandler ( scrollBarY , scrollBoxY , scrollBarHeight ) ;
276276 if ( scrollBoxY !== 0 && scrollBoxY !== - scrollBoxYMax ) {
277277 d3 . event . preventDefault ( ) ;
278278 }
@@ -299,14 +299,14 @@ module.exports = function draw(gd) {
299299 constants . scrollBarMargin + scrollBarYMax ) ;
300300 scrollBoxY = - ( scrollBarY - constants . scrollBarMargin ) /
301301 scrollBarYMax * scrollBoxYMax ;
302- scrollHandler ( scrollBarY , scrollBoxY ) ;
302+ scrollHandler ( scrollBarY , scrollBoxY , scrollBarHeight ) ;
303303 } ) ;
304304
305305 scrollBar . call ( drag ) ;
306306 }
307307
308308
309- function scrollHandler ( scrollBarY , scrollBoxY ) {
309+ function scrollHandler ( scrollBarY , scrollBoxY , scrollBarHeight ) {
310310 scrollBox
311311 . attr ( 'data-scroll' , scrollBoxY )
312312 . call ( Drawing . setTranslate , 0 , scrollBoxY ) ;
@@ -316,7 +316,7 @@ module.exports = function draw(gd) {
316316 legendWidth ,
317317 scrollBarY ,
318318 constants . scrollBarWidth ,
319- constants . scrollBarHeight
319+ scrollBarHeight
320320 ) ;
321321 clipPath . select ( 'rect' ) . attr ( {
322322 y : opts . borderwidth - scrollBoxY
0 commit comments