@@ -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,49 +221,57 @@ 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
} ) ;
227
229
228
230
clipPath . attr ( {
229
231
width : opts . width + constants . scrollBarWidth
230
232
} ) ;
233
+
234
+
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
+
244
+ legend . on ( 'wheel' , null ) ;
231
245
232
- legend . node ( ) . addEventListener ( 'wheel' , function ( e ) {
246
+ legend . on ( 'wheel' , function ( ) {
247
+ var e = d3 . event ;
233
248
e . preventDefault ( ) ;
234
- scrollHandler ( e . deltaY / 20 ) ;
235
- } ) ;
249
+ scrollHandler ( e . deltaY / 20 , scrollheight ) ;
250
+ } )
251
+
252
+ scrollBar . on ( 'mousedown' , null ) ;
236
253
237
- scrollBar . node ( ) . addEventListener ( 'mousedown' , function ( e ) {
254
+ scrollBar . on ( 'mousedown' , function ( ) {
255
+ var e = d3 . event ;
238
256
e . preventDefault ( ) ;
239
-
257
+
240
258
function mMove ( e ) {
241
259
if ( e . buttons === 1 ) {
242
- scrollHandler ( e . movementY ) ;
260
+ scrollHandler ( e . movementY , scrollheight ) ;
243
261
}
244
262
}
245
-
263
+
246
264
function mUp ( ) {
247
265
scrollBar . node ( ) . removeEventListener ( 'mousemove' , mMove ) ;
248
266
window . removeEventListener ( 'mouseup' , mUp ) ;
249
267
}
250
-
268
+
251
269
window . addEventListener ( 'mousemove' , mMove ) ;
252
270
window . addEventListener ( 'mouseup' , mUp ) ;
253
271
} ) ;
254
-
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
- ) ;
263
272
}
264
273
265
- function scrollHandler ( delta ) {
274
+ function scrollHandler ( delta , scrollheight ) {
266
275
267
276
var scrollBarTrack = scrollheight - constants . scrollBarHeight - 2 * constants . scrollBarMargin ,
268
277
translateY = scrollBox . attr ( 'data-scroll' ) ,
0 commit comments