@@ -56,8 +56,9 @@ module.exports = function draw(gd) {
56
56
} ) ;
57
57
58
58
var clipPath = fullLayout . _topdefs . selectAll ( '#' + clipId )
59
- . data ( [ 0 ] )
60
- . enter ( ) . append ( 'clipPath' )
59
+ . data ( [ 0 ] ) ;
60
+
61
+ clipPath . enter ( ) . append ( 'clipPath' )
61
62
. attr ( 'id' , clipId )
62
63
. append ( 'rect' ) ;
63
64
@@ -210,7 +211,7 @@ module.exports = function draw(gd) {
210
211
211
212
legend . attr ( 'transform' , 'translate(' + lx + ',' + ly + ')' ) ;
212
213
213
- clipPath . attr ( {
214
+ clipPath . select ( 'rect' ) . attr ( {
214
215
width : opts . width ,
215
216
height : scrollheight ,
216
217
x : 0 ,
@@ -220,7 +221,8 @@ module.exports = function draw(gd) {
220
221
legend . call ( Drawing . setClipUrl , clipId ) ;
221
222
222
223
// If scrollbar should be shown.
223
- if ( gd . firstRender && opts . height - scrollheight > 0 && ! gd . _context . staticPlot ) {
224
+ if ( opts . height - scrollheight > 0 && ! gd . _context . staticPlot ) {
225
+
224
226
bg . attr ( {
225
227
width : opts . width - 2 * opts . borderwidth + constants . scrollBarWidth
226
228
} ) ;
@@ -229,44 +231,46 @@ module.exports = function draw(gd) {
229
231
width : opts . width + constants . scrollBarWidth
230
232
} ) ;
231
233
232
- legend . node ( ) . addEventListener ( 'wheel' , function ( e ) {
233
- e . preventDefault ( ) ;
234
- scrollHandler ( e . deltaY / 20 ) ;
235
- } ) ;
236
-
237
- scrollBar . node ( ) . addEventListener ( 'mousedown' , function ( e ) {
238
- e . preventDefault ( ) ;
234
+ if ( gd . firstRender ) {
235
+ // Move scrollbar to starting position
236
+ scrollBar . call (
237
+ Drawing . setRect ,
238
+ opts . width - ( constants . scrollBarWidth + constants . scrollBarMargin ) ,
239
+ constants . scrollBarMargin ,
240
+ constants . scrollBarWidth ,
241
+ constants . scrollBarHeight
242
+ ) ;
243
+ scrollBox . attr ( 'data-scroll' , 0 ) ;
244
+ }
239
245
240
- function mMove ( e ) {
241
- if ( e . buttons === 1 ) {
242
- scrollHandler ( e . movementY ) ;
243
- }
244
- }
246
+ scrollHandler ( 0 , scrollheight ) ;
245
247
246
- function mUp ( ) {
247
- scrollBar . node ( ) . removeEventListener ( 'mousemove' , mMove ) ;
248
- window . removeEventListener ( 'mouseup' , mUp ) ;
249
- }
248
+ legend . on ( 'wheel' , null ) ;
250
249
251
- window . addEventListener ( 'mousemove' , mMove ) ;
252
- window . addEventListener ( 'mouseup' , mUp ) ;
250
+ legend . on ( 'wheel' , function ( ) {
251
+ var e = d3 . event ;
252
+ e . preventDefault ( ) ;
253
+ scrollHandler ( e . deltaY / 20 , scrollheight ) ;
253
254
} ) ;
254
255
255
- // Move scrollbar to starting position on the first render
256
- scrollBar . call (
257
- Drawing . setRect ,
258
- opts . width - ( constants . scrollBarWidth + constants . scrollBarMargin ) ,
259
- constants . scrollBarMargin ,
260
- constants . scrollBarWidth ,
261
- constants . scrollBarHeight
262
- ) ;
256
+ scrollBar . on ( '.drag' , null ) ;
257
+ scrollBox . on ( '.drag' , null ) ;
258
+ var drag = d3 . behavior . drag ( )
259
+ . on ( 'drag' , function ( ) {
260
+ scrollHandler ( d3 . event . dy , scrollheight ) ;
261
+ } ) ;
262
+
263
+ scrollBar . call ( drag ) ;
264
+ scrollBox . call ( drag ) ;
265
+
263
266
}
264
267
265
- function scrollHandler ( delta ) {
268
+
269
+ function scrollHandler ( delta , scrollheight ) {
266
270
267
271
var scrollBarTrack = scrollheight - constants . scrollBarHeight - 2 * constants . scrollBarMargin ,
268
272
translateY = scrollBox . attr ( 'data-scroll' ) ,
269
- scrollBoxY = Lib . constrain ( translateY - delta , Math . min ( scrollheight - opts . height , 0 ) , 0 ) ,
273
+ scrollBoxY = Lib . constrain ( translateY - delta , scrollheight - opts . height , 0 ) ,
270
274
scrollBarY = - scrollBoxY / ( opts . height - scrollheight ) * scrollBarTrack + constants . scrollBarMargin ;
271
275
272
276
scrollBox . attr ( 'data-scroll' , scrollBoxY ) ;
0 commit comments