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