@@ -271,36 +271,46 @@ module.exports = function draw(gd) {
271
271
scrollBox . attr ( 'data-scroll' , 0 ) ;
272
272
}
273
273
274
- scrollHandler ( 0 , legendHeight ) ;
274
+ var scrollBarYMax = legendHeight -
275
+ constants . scrollBarHeight -
276
+ 2 * constants . scrollBarMargin ,
277
+ scrollBoxYMax = opts . height - legendHeight ,
278
+ scrollBarY = constants . scrollBarMargin ,
279
+ scrollBoxY = 0 ;
275
280
276
- legend . on ( 'wheel' , null ) ;
281
+ scrollHandler ( scrollBarY , scrollBoxY ) ;
277
282
283
+ legend . on ( 'wheel' , null ) ;
278
284
legend . on ( 'wheel' , function ( ) {
279
- var e = d3 . event ;
280
- e . preventDefault ( ) ;
281
- scrollHandler ( e . deltaY / 20 , legendHeight ) ;
285
+ scrollBoxY = Lib . constrain (
286
+ scrollBox . attr ( 'data-scroll' ) -
287
+ d3 . event . deltaY / scrollBarYMax * scrollBoxYMax ,
288
+ - scrollBoxYMax , 0 ) ;
289
+ scrollBarY = constants . scrollBarMargin -
290
+ scrollBoxY / scrollBoxYMax * scrollBarYMax ;
291
+ scrollHandler ( scrollBarY , scrollBoxY ) ;
292
+ d3 . event . preventDefault ( ) ;
282
293
} ) ;
283
294
284
295
scrollBar . on ( '.drag' , null ) ;
285
296
scrollBox . on ( '.drag' , null ) ;
286
- var drag = d3 . behavior . drag ( )
287
- . on ( 'drag' , function ( ) {
288
- scrollHandler ( d3 . event . dy , legendHeight ) ;
289
- } ) ;
297
+ var drag = d3 . behavior . drag ( ) . on ( 'drag' , function ( ) {
298
+ scrollBarY = Lib . constrain (
299
+ d3 . event . y - constants . scrollBarHeight / 2 ,
300
+ constants . scrollBarMargin ,
301
+ constants . scrollBarMargin + scrollBarYMax ) ;
302
+ scrollBoxY = - ( scrollBarY - constants . scrollBarMargin ) /
303
+ scrollBarYMax * scrollBoxYMax ;
304
+ scrollHandler ( scrollBarY , scrollBoxY ) ;
305
+ } ) ;
290
306
291
307
scrollBar . call ( drag ) ;
292
308
scrollBox . call ( drag ) ;
293
309
294
310
}
295
311
296
312
297
- function scrollHandler ( delta , legendHeight ) {
298
-
299
- var scrollBarTrack = legendHeight - constants . scrollBarHeight - 2 * constants . scrollBarMargin ,
300
- translateY = scrollBox . attr ( 'data-scroll' ) ,
301
- scrollBoxY = Lib . constrain ( translateY - delta , legendHeight - opts . height , 0 ) ,
302
- scrollBarY = - scrollBoxY / ( opts . height - legendHeight ) * scrollBarTrack + constants . scrollBarMargin ;
303
-
313
+ function scrollHandler ( scrollBarY , scrollBoxY ) {
304
314
scrollBox . attr ( 'data-scroll' , scrollBoxY ) ;
305
315
scrollBox . attr ( 'transform' , 'translate(0, ' + scrollBoxY + ')' ) ;
306
316
scrollBar . call (
0 commit comments