@@ -27,6 +27,7 @@ var anchorUtils = require('./anchor_utils');
27
27
28
28
module . exports = function draw ( gd ) {
29
29
var fullLayout = gd . _fullLayout ;
30
+ var clipId = 'legend' + fullLayout . _uid ;
30
31
31
32
if ( ! fullLayout . _infolayer || ! gd . calcdata ) return ;
32
33
@@ -36,6 +37,8 @@ module.exports = function draw(gd) {
36
37
37
38
if ( ! fullLayout . showlegend || ! legendData . length ) {
38
39
fullLayout . _infolayer . selectAll ( '.legend' ) . remove ( ) ;
40
+ fullLayout . _topdefs . select ( '#' + clipId ) . remove ( ) ;
41
+
39
42
Plots . autoMargin ( gd , 'legend' ) ;
40
43
return ;
41
44
}
@@ -52,6 +55,12 @@ module.exports = function draw(gd) {
52
55
'pointer-events' : 'all'
53
56
} ) ;
54
57
58
+ var clipPath = fullLayout . _topdefs . selectAll ( '#' + clipId )
59
+ . data ( [ 0 ] )
60
+ . enter ( ) . append ( 'clipPath' )
61
+ . attr ( 'id' , clipId )
62
+ . append ( 'rect' ) ;
63
+
55
64
var bg = legend . selectAll ( 'rect.bg' )
56
65
. data ( [ 0 ] ) ;
57
66
@@ -201,16 +210,14 @@ module.exports = function draw(gd) {
201
210
202
211
legend . attr ( 'transform' , 'translate(' + lx + ',' + ly + ')' ) ;
203
212
204
- var clipPath = selectClipPath ( gd ) ;
205
-
206
213
clipPath . attr ( {
207
214
width : opts . width ,
208
215
height : scrollheight ,
209
216
x : 0 ,
210
217
y : 0
211
218
} ) ;
212
219
213
- legend . call ( Drawing . setClipUrl , constants . clipId ) ;
220
+ legend . call ( Drawing . setClipUrl , clipId ) ;
214
221
215
222
// If scrollbar should be shown.
216
223
if ( gd . firstRender && opts . height - scrollheight > 0 && ! gd . _context . staticPlot ) {
@@ -470,21 +477,3 @@ function repositionLegend(gd, traces) {
470
477
t : opts . height * ( { bottom : 1 , middle : 0.5 } [ yanchor ] || 0 )
471
478
} ) ;
472
479
}
473
-
474
- function selectClipPath ( gd ) {
475
- var container = gd . _fullLayout . _infolayer . node ( ) . parentNode ;
476
-
477
- var defs = d3 . select ( container ) . selectAll ( 'defs' )
478
- . data ( [ 0 ] ) ;
479
-
480
- defs . enter ( ) . append ( 'defs' ) ;
481
-
482
- var clipPath = defs . selectAll ( '#' + constants . clipId )
483
- . data ( [ 0 ] ) ;
484
-
485
- var path = clipPath . enter ( ) . append ( 'clipPath' )
486
- . attr ( 'id' , constants . clipId )
487
- . append ( 'rect' ) ;
488
-
489
- return path ;
490
- }
0 commit comments