File tree 2 files changed +38
-2
lines changed
2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -12,5 +12,7 @@ module.exports = {
12
12
scrollBarWidth : 4 ,
13
13
scrollBarHeight : 20 ,
14
14
scrollBarColor : '#808BA4' ,
15
- scrollBarMargin : 4
15
+ scrollBarMargin : 4 ,
16
+
17
+ clipId : 'legend'
16
18
} ;
Original file line number Diff line number Diff line change @@ -197,10 +197,26 @@ module.exports = function draw(gd) {
197
197
198
198
legend . attr ( 'transform' , 'translate(' + lx + ',' + ly + ')' ) ;
199
199
200
+ var clipPath = selectClipPath ( gd ) ;
201
+
202
+ clipPath . attr ( {
203
+ width : opts . width ,
204
+ height : scrollheight ,
205
+ x : 0 ,
206
+ y : 0
207
+ } ) ;
208
+
209
+ legend . call ( Drawing . setClipUrl , constants . clipId ) ;
210
+
200
211
// If scrollbar should be shown.
201
212
if ( gd . firstRender && opts . height - scrollheight > 0 && ! gd . _context . staticPlot ) {
213
+ bg . attr ( {
214
+ width : opts . width - 2 * opts . borderwidth + constants . scrollBarWidth
215
+ } ) ;
202
216
203
- bg . attr ( { width : opts . width - 2 * opts . borderwidth + constants . scrollBarWidth } ) ;
217
+ clipPath . attr ( {
218
+ width : opts . width + constants . scrollBarWidth
219
+ } ) ;
204
220
205
221
legend . node ( ) . addEventListener ( 'wheel' , function ( e ) {
206
222
e . preventDefault ( ) ;
@@ -450,3 +466,21 @@ function repositionLegend(gd, traces) {
450
466
t : opts . height * ( { bottom : 1 , middle : 0.5 } [ yanchor ] || 0 )
451
467
} ) ;
452
468
}
469
+
470
+ function selectClipPath ( gd ) {
471
+ var container = gd . _fullLayout . _infolayer . node ( ) . parentNode ;
472
+
473
+ var defs = d3 . select ( container ) . selectAll ( 'defs' )
474
+ . data ( [ 0 ] ) ;
475
+
476
+ defs . enter ( ) . append ( 'defs' ) ;
477
+
478
+ var clipPath = defs . selectAll ( '#' + constants . clipId )
479
+ . data ( [ 0 ] ) ;
480
+
481
+ var path = clipPath . enter ( ) . append ( 'clipPath' )
482
+ . attr ( 'id' , constants . clipId )
483
+ . append ( 'rect' ) ;
484
+
485
+ return path ;
486
+ }
You can’t perform that action at this time.
0 commit comments