@@ -43,16 +43,18 @@ module.exports = function draw(gd) {
4343 if ( typeof gd . firstRender === 'undefined' ) gd . firstRender = true ;
4444 else if ( gd . firstRender ) gd . firstRender = false ;
4545
46- var legendsvg = fullLayout . _infolayer . selectAll ( 'svg .legend' )
46+ var legend = fullLayout . _infolayer . selectAll ( 'g .legend' )
4747 . data ( [ 0 ] ) ;
48- legendsvg . enter ( ) . append ( 'svg' )
48+
49+ legend . enter ( ) . append ( 'g' )
4950 . attr ( {
5051 'class' : 'legend' ,
5152 'pointer-events' : 'all'
5253 } ) ;
5354
54- var bg = legendsvg . selectAll ( 'rect.bg' )
55+ var bg = legend . selectAll ( 'rect.bg' )
5556 . data ( [ 0 ] ) ;
57+
5658 bg . enter ( ) . append ( 'rect' )
5759 . attr ( {
5860 'class' : 'bg' ,
@@ -62,14 +64,16 @@ module.exports = function draw(gd) {
6264 . call ( Color . fill , opts . bgcolor )
6365 . style ( 'stroke-width' , opts . borderwidth + 'px' ) ;
6466
65- var scrollBox = legendsvg . selectAll ( 'g.scrollbox' )
67+ var scrollBox = legend . selectAll ( 'g.scrollbox' )
6668 . data ( [ 0 ] ) ;
69+
6770 scrollBox . enter ( ) . append ( 'g' )
6871 . attr ( 'class' , 'scrollbox' ) ;
6972 scrollBox . exit ( ) . remove ( ) ;
7073
71- var scrollBar = legendsvg . selectAll ( 'rect.scrollbar' )
74+ var scrollBar = legend . selectAll ( 'rect.scrollbar' )
7275 . data ( [ 0 ] ) ;
76+
7377 scrollBar . enter ( ) . append ( 'rect' )
7478 . attr ( {
7579 'class' : 'scrollbar' ,
@@ -191,14 +195,14 @@ module.exports = function draw(gd) {
191195 y : opts . borderwidth
192196 } ) ;
193197
194- legendsvg . call ( Drawing . setRect , lx , ly , opts . width , scrollheight ) ;
198+ legend . attr ( 'transform' , 'translate(' + lx + ',' + ly + ')' ) ;
195199
196200 // If scrollbar should be shown.
197201 if ( gd . firstRender && opts . height - scrollheight > 0 && ! gd . _context . staticPlot ) {
198202
199203 bg . attr ( { width : opts . width - 2 * opts . borderwidth + constants . scrollBarWidth } ) ;
200204
201- legendsvg . node ( ) . addEventListener ( 'wheel' , function ( e ) {
205+ legend . node ( ) . addEventListener ( 'wheel' , function ( e ) {
202206 e . preventDefault ( ) ;
203207 scrollHandler ( e . deltaY / 20 ) ;
204208 } ) ;
@@ -258,18 +262,18 @@ module.exports = function draw(gd) {
258262 lh ;
259263
260264 Fx . dragElement ( {
261- element : legendsvg . node ( ) ,
265+ element : legend . node ( ) ,
262266 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 ) ;
268272 } ,
269273 moveFn : function ( dx , dy ) {
270274 var gs = gd . _fullLayout . _size ;
271275
272- legendsvg . call ( Drawing . setPosition , x0 + dx , y0 + dy ) ;
276+ legend . call ( Drawing . setPosition , x0 + dx , y0 + dy ) ;
273277
274278 xf = Fx . dragAlign ( x0 + dx , lw , gs . l , gs . l + gs . w ,
275279 opts . xanchor ) ;
@@ -278,10 +282,10 @@ module.exports = function draw(gd) {
278282
279283 var csr = Fx . dragCursors ( xf , yf ,
280284 opts . xanchor , opts . yanchor ) ;
281- Fx . setCursor ( legendsvg , csr ) ;
285+ Fx . setCursor ( legend , csr ) ;
282286 } ,
283287 doneFn : function ( dragged ) {
284- Fx . setCursor ( legendsvg ) ;
288+ Fx . setCursor ( legend ) ;
285289 if ( dragged && xf !== undefined && yf !== undefined ) {
286290 Plotly . relayout ( gd , { 'legend.x' : xf , 'legend.y' : yf } ) ;
287291 }
0 commit comments