@@ -43,16 +43,18 @@ module.exports = function draw(gd) {
43
43
if ( typeof gd . firstRender === 'undefined' ) gd . firstRender = true ;
44
44
else if ( gd . firstRender ) gd . firstRender = false ;
45
45
46
- var legendsvg = fullLayout . _infolayer . selectAll ( 'svg .legend' )
46
+ var legend = fullLayout . _infolayer . selectAll ( 'g .legend' )
47
47
. data ( [ 0 ] ) ;
48
- legendsvg . enter ( ) . append ( 'svg' )
48
+
49
+ legend . enter ( ) . append ( 'g' )
49
50
. attr ( {
50
51
'class' : 'legend' ,
51
52
'pointer-events' : 'all'
52
53
} ) ;
53
54
54
- var bg = legendsvg . selectAll ( 'rect.bg' )
55
+ var bg = legend . selectAll ( 'rect.bg' )
55
56
. data ( [ 0 ] ) ;
57
+
56
58
bg . enter ( ) . append ( 'rect' )
57
59
. attr ( {
58
60
'class' : 'bg' ,
@@ -62,14 +64,16 @@ module.exports = function draw(gd) {
62
64
. call ( Color . fill , opts . bgcolor )
63
65
. style ( 'stroke-width' , opts . borderwidth + 'px' ) ;
64
66
65
- var scrollBox = legendsvg . selectAll ( 'g.scrollbox' )
67
+ var scrollBox = legend . selectAll ( 'g.scrollbox' )
66
68
. data ( [ 0 ] ) ;
69
+
67
70
scrollBox . enter ( ) . append ( 'g' )
68
71
. attr ( 'class' , 'scrollbox' ) ;
69
72
scrollBox . exit ( ) . remove ( ) ;
70
73
71
- var scrollBar = legendsvg . selectAll ( 'rect.scrollbar' )
74
+ var scrollBar = legend . selectAll ( 'rect.scrollbar' )
72
75
. data ( [ 0 ] ) ;
76
+
73
77
scrollBar . enter ( ) . append ( 'rect' )
74
78
. attr ( {
75
79
'class' : 'scrollbar' ,
@@ -191,14 +195,14 @@ module.exports = function draw(gd) {
191
195
y : opts . borderwidth
192
196
} ) ;
193
197
194
- legendsvg . call ( Drawing . setRect , lx , ly , opts . width , scrollheight ) ;
198
+ legend . attr ( 'transform' , 'translate(' + lx + ',' + ly + ')' ) ;
195
199
196
200
// If scrollbar should be shown.
197
201
if ( gd . firstRender && opts . height - scrollheight > 0 && ! gd . _context . staticPlot ) {
198
202
199
203
bg . attr ( { width : opts . width - 2 * opts . borderwidth + constants . scrollBarWidth } ) ;
200
204
201
- legendsvg . node ( ) . addEventListener ( 'wheel' , function ( e ) {
205
+ legend . node ( ) . addEventListener ( 'wheel' , function ( e ) {
202
206
e . preventDefault ( ) ;
203
207
scrollHandler ( e . deltaY / 20 ) ;
204
208
} ) ;
@@ -258,18 +262,18 @@ module.exports = function draw(gd) {
258
262
lh ;
259
263
260
264
Fx . dragElement ( {
261
- element : legendsvg . node ( ) ,
265
+ element : legend . node ( ) ,
262
266
prepFn : function ( ) {
263
- x0 = Number ( legendsvg . attr ( 'x' ) ) ;
264
- y0 = Number ( legendsvg . attr ( 'y' ) ) ;
265
- lw = Number ( legendsvg . attr ( 'width' ) ) ;
266
- lh = Number ( legendsvg . attr ( 'height' ) ) ;
267
- Fx . setCursor ( legendsvg ) ;
267
+ x0 = Number ( legend . attr ( 'x' ) ) ;
268
+ y0 = Number ( legend . attr ( 'y' ) ) ;
269
+ lw = Number ( legend . attr ( 'width' ) ) ;
270
+ lh = Number ( legend . attr ( 'height' ) ) ;
271
+ Fx . setCursor ( legend ) ;
268
272
} ,
269
273
moveFn : function ( dx , dy ) {
270
274
var gs = gd . _fullLayout . _size ;
271
275
272
- legendsvg . call ( Drawing . setPosition , x0 + dx , y0 + dy ) ;
276
+ legend . call ( Drawing . setPosition , x0 + dx , y0 + dy ) ;
273
277
274
278
xf = Fx . dragAlign ( x0 + dx , lw , gs . l , gs . l + gs . w ,
275
279
opts . xanchor ) ;
@@ -278,10 +282,10 @@ module.exports = function draw(gd) {
278
282
279
283
var csr = Fx . dragCursors ( xf , yf ,
280
284
opts . xanchor , opts . yanchor ) ;
281
- Fx . setCursor ( legendsvg , csr ) ;
285
+ Fx . setCursor ( legend , csr ) ;
282
286
} ,
283
287
doneFn : function ( dragged ) {
284
- Fx . setCursor ( legendsvg ) ;
288
+ Fx . setCursor ( legend ) ;
285
289
if ( dragged && xf !== undefined && yf !== undefined ) {
286
290
Plotly . relayout ( gd , { 'legend.x' : xf , 'legend.y' : yf } ) ;
287
291
}
0 commit comments