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