@@ -56,8 +56,9 @@ module.exports = function draw(gd) {
5656 } ) ;
5757
5858 var clipPath = fullLayout . _topdefs . selectAll ( '#' + clipId )
59- . data ( [ 0 ] )
60- . enter ( ) . append ( 'clipPath' )
59+ . data ( [ 0 ] ) ;
60+
61+ clipPath . enter ( ) . append ( 'clipPath' )
6162 . attr ( 'id' , clipId )
6263 . append ( 'rect' ) ;
6364
@@ -210,7 +211,7 @@ module.exports = function draw(gd) {
210211
211212 legend . attr ( 'transform' , 'translate(' + lx + ',' + ly + ')' ) ;
212213
213- clipPath . attr ( {
214+ clipPath . select ( 'rect' ) . attr ( {
214215 width : opts . width ,
215216 height : scrollheight ,
216217 x : 0 ,
@@ -220,49 +221,57 @@ module.exports = function draw(gd) {
220221 legend . call ( Drawing . setClipUrl , clipId ) ;
221222
222223 // 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+
224226 bg . attr ( {
225227 width : opts . width - 2 * opts . borderwidth + constants . scrollBarWidth
226228 } ) ;
227229
228230 clipPath . attr ( {
229231 width : opts . width + constants . scrollBarWidth
230232 } ) ;
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 ) ;
231245
232- legend . node ( ) . addEventListener ( 'wheel' , function ( e ) {
246+ legend . on ( 'wheel' , function ( ) {
247+ var e = d3 . event ;
233248 e . preventDefault ( ) ;
234- scrollHandler ( e . deltaY / 20 ) ;
235- } ) ;
249+ scrollHandler ( e . deltaY / 20 , scrollheight ) ;
250+ } )
251+
252+ scrollBar . on ( 'mousedown' , null ) ;
236253
237- scrollBar . node ( ) . addEventListener ( 'mousedown' , function ( e ) {
254+ scrollBar . on ( 'mousedown' , function ( ) {
255+ var e = d3 . event ;
238256 e . preventDefault ( ) ;
239-
257+
240258 function mMove ( e ) {
241259 if ( e . buttons === 1 ) {
242- scrollHandler ( e . movementY ) ;
260+ scrollHandler ( e . movementY , scrollheight ) ;
243261 }
244262 }
245-
263+
246264 function mUp ( ) {
247265 scrollBar . node ( ) . removeEventListener ( 'mousemove' , mMove ) ;
248266 window . removeEventListener ( 'mouseup' , mUp ) ;
249267 }
250-
268+
251269 window . addEventListener ( 'mousemove' , mMove ) ;
252270 window . addEventListener ( 'mouseup' , mUp ) ;
253271 } ) ;
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- ) ;
263272 }
264273
265- function scrollHandler ( delta ) {
274+ function scrollHandler ( delta , scrollheight ) {
266275
267276 var scrollBarTrack = scrollheight - constants . scrollBarHeight - 2 * constants . scrollBarMargin ,
268277 translateY = scrollBox . attr ( 'data-scroll' ) ,
0 commit comments