@@ -182,7 +182,7 @@ module.exports = function draw(gd) {
182182
183183 // Set size and position of all the elements that make up a legend:
184184 // legend, background and border, scroll box and scroll bar
185- legend . attr ( 'transform' , 'translate(' + lx + ',' + ly + ')' ) ;
185+ Lib . setTranslate ( legend , lx , ly ) ;
186186
187187 bg . attr ( {
188188 width : opts . width - opts . borderwidth ,
@@ -193,7 +193,7 @@ module.exports = function draw(gd) {
193193
194194 var scrollPosition = scrollBox . attr ( 'data-scroll' ) || 0 ;
195195
196- scrollBox . attr ( 'transform' , 'translate( 0, ' + scrollPosition + ')' ) ;
196+ Lib . setTranslate ( scrollBox , 0 , scrollPosition ) ;
197197
198198 clipPath . select ( 'rect' ) . attr ( {
199199 width : opts . width - 2 * opts . borderwidth ,
@@ -268,8 +268,10 @@ module.exports = function draw(gd) {
268268
269269
270270 function scrollHandler ( scrollBarY , scrollBoxY ) {
271- scrollBox . attr ( 'data-scroll' , scrollBoxY ) ;
272- scrollBox . attr ( 'transform' , 'translate(0, ' + scrollBoxY + ')' ) ;
271+ scrollBox
272+ . attr ( 'data-scroll' , scrollBoxY )
273+ . call ( Lib . setTranslate , 0 , scrollBoxY ) ;
274+
273275 scrollBar . call (
274276 Drawing . setRect ,
275277 opts . width ,
@@ -299,8 +301,7 @@ module.exports = function draw(gd) {
299301 var newX = x0 + dx ,
300302 newY = y0 + dy ;
301303
302- var transform = 'translate(' + newX + ', ' + newY + ')' ;
303- legend . attr ( 'transform' , transform ) ;
304+ Lib . setTranslate ( legend , newX , newY ) ;
304305
305306 xf = dragElement . align ( newX , 0 , gs . l , gs . l + gs . w , opts . xanchor ) ;
306307 yf = dragElement . align ( newY , 0 , gs . t + gs . h , gs . t , opts . yanchor ) ;
@@ -424,7 +425,7 @@ function computeTextDimensions(g, gd, legendItem) {
424425 height = mathjaxBB . height ;
425426 width = mathjaxBB . width ;
426427
427- mathjaxGroup . attr ( 'transform' , 'translate(0,' + ( height / 4 ) + ')' ) ;
428+ Lib . setTranslate ( mathjaxGroup , 0 , ( height / 4 ) ) ;
428429 }
429430 else {
430431 var text = g . selectAll ( '.legendtext' ) ,
@@ -456,8 +457,8 @@ function computeLegendDimensions(gd, groups, traces) {
456457
457458 if ( helpers . isVertical ( opts ) ) {
458459 if ( helpers . isGrouped ( opts ) ) {
459- groups . attr ( 'transform' , function ( d , i ) {
460- return 'translate(0,' + i * opts . tracegroupgap + ')' ;
460+ groups . each ( function ( d , i ) {
461+ Lib . setTranslate ( this , 0 , i * opts . tracegroupgap ) ;
461462 } ) ;
462463 }
463464
@@ -469,11 +470,9 @@ function computeLegendDimensions(gd, groups, traces) {
469470 textHeight = legendItem . height ,
470471 textWidth = legendItem . width ;
471472
472- d3 . select ( this ) . attr ( 'transform' ,
473- 'translate(' + borderwidth + ',' +
474- ( 5 + borderwidth + opts . height + textHeight / 2 ) +
475- ')'
476- ) ;
473+ Lib . setTranslate ( this ,
474+ borderwidth ,
475+ ( 5 + borderwidth + opts . height + textHeight / 2 ) ) ;
477476
478477 opts . height += textHeight ;
479478 opts . width = Math . max ( opts . width , textWidth ) ;
@@ -509,8 +508,8 @@ function computeLegendDimensions(gd, groups, traces) {
509508 groupXOffsets . push ( opts . width ) ;
510509 } ) ;
511510
512- groups . attr ( 'transform' , function ( d , i ) {
513- return 'translate(' + groupXOffsets [ i ] + ',0)' ;
511+ groups . each ( function ( d , i ) {
512+ Lib . setTranslate ( this , groupXOffsets [ i ] , 0 ) ;
514513 } ) ;
515514
516515 groups . each ( function ( ) {
@@ -522,11 +521,9 @@ function computeLegendDimensions(gd, groups, traces) {
522521 var legendItem = d [ 0 ] ,
523522 textHeight = legendItem . height ;
524523
525- d3 . select ( this ) . attr ( 'transform' ,
526- 'translate(0,' +
527- ( 5 + borderwidth + groupHeight + textHeight / 2 ) +
528- ')'
529- ) ;
524+ Lib . setTranslate ( this ,
525+ 0 ,
526+ ( 5 + borderwidth + groupHeight + textHeight / 2 ) ) ;
530527
531528 groupHeight += textHeight ;
532529 } ) ;
@@ -553,13 +550,9 @@ function computeLegendDimensions(gd, groups, traces) {
553550 traceWidth = 40 + legendItem . width ,
554551 traceGap = opts . tracegroupgap || 5 ;
555552
556- d3 . select ( this ) . attr ( 'transform' ,
557- 'translate(' +
558- ( borderwidth + opts . width ) +
559- ',' +
560- ( 5 + borderwidth + legendItem . height / 2 ) +
561- ')'
562- ) ;
553+ Lib . setTranslate ( this ,
554+ ( borderwidth + opts . width ) ,
555+ ( 5 + borderwidth + legendItem . height / 2 ) ) ;
563556
564557 opts . width += traceGap + traceWidth ;
565558 opts . height = Math . max ( opts . height , legendItem . height ) ;
0 commit comments