@@ -182,7 +182,7 @@ module.exports = function draw(gd) {
182
182
183
183
// Set size and position of all the elements that make up a legend:
184
184
// legend, background and border, scroll box and scroll bar
185
- legend . attr ( 'transform' , 'translate(' + lx + ',' + ly + ')' ) ;
185
+ Lib . setTranslate ( legend , lx , ly ) ;
186
186
187
187
bg . attr ( {
188
188
width : opts . width - opts . borderwidth ,
@@ -193,7 +193,7 @@ module.exports = function draw(gd) {
193
193
194
194
var scrollPosition = scrollBox . attr ( 'data-scroll' ) || 0 ;
195
195
196
- scrollBox . attr ( 'transform' , 'translate( 0, ' + scrollPosition + ')' ) ;
196
+ Lib . setTranslate ( scrollBox , 0 , scrollPosition ) ;
197
197
198
198
clipPath . select ( 'rect' ) . attr ( {
199
199
width : opts . width - 2 * opts . borderwidth ,
@@ -268,8 +268,10 @@ module.exports = function draw(gd) {
268
268
269
269
270
270
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
+
273
275
scrollBar . call (
274
276
Drawing . setRect ,
275
277
opts . width ,
@@ -299,8 +301,7 @@ module.exports = function draw(gd) {
299
301
var newX = x0 + dx ,
300
302
newY = y0 + dy ;
301
303
302
- var transform = 'translate(' + newX + ', ' + newY + ')' ;
303
- legend . attr ( 'transform' , transform ) ;
304
+ Lib . setTranslate ( legend , newX , newY ) ;
304
305
305
306
xf = dragElement . align ( newX , 0 , gs . l , gs . l + gs . w , opts . xanchor ) ;
306
307
yf = dragElement . align ( newY , 0 , gs . t + gs . h , gs . t , opts . yanchor ) ;
@@ -424,7 +425,7 @@ function computeTextDimensions(g, gd, legendItem) {
424
425
height = mathjaxBB . height ;
425
426
width = mathjaxBB . width ;
426
427
427
- mathjaxGroup . attr ( 'transform' , 'translate(0,' + ( height / 4 ) + ')' ) ;
428
+ Lib . setTranslate ( mathjaxGroup , 0 , ( height / 4 ) ) ;
428
429
}
429
430
else {
430
431
var text = g . selectAll ( '.legendtext' ) ,
@@ -456,8 +457,8 @@ function computeLegendDimensions(gd, groups, traces) {
456
457
457
458
if ( helpers . isVertical ( opts ) ) {
458
459
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 ) ;
461
462
} ) ;
462
463
}
463
464
@@ -469,11 +470,9 @@ function computeLegendDimensions(gd, groups, traces) {
469
470
textHeight = legendItem . height ,
470
471
textWidth = legendItem . width ;
471
472
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 ) ) ;
477
476
478
477
opts . height += textHeight ;
479
478
opts . width = Math . max ( opts . width , textWidth ) ;
@@ -509,8 +508,8 @@ function computeLegendDimensions(gd, groups, traces) {
509
508
groupXOffsets . push ( opts . width ) ;
510
509
} ) ;
511
510
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 ) ;
514
513
} ) ;
515
514
516
515
groups . each ( function ( ) {
@@ -522,11 +521,9 @@ function computeLegendDimensions(gd, groups, traces) {
522
521
var legendItem = d [ 0 ] ,
523
522
textHeight = legendItem . height ;
524
523
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 ) ) ;
530
527
531
528
groupHeight += textHeight ;
532
529
} ) ;
@@ -553,13 +550,9 @@ function computeLegendDimensions(gd, groups, traces) {
553
550
traceWidth = 40 + legendItem . width ,
554
551
traceGap = opts . tracegroupgap || 5 ;
555
552
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 ) ) ;
563
556
564
557
opts . width += traceGap + traceWidth ;
565
558
opts . height = Math . max ( opts . height , legendItem . height ) ;
0 commit comments