@@ -340,32 +340,32 @@ function appendBarText(gd, plotinfo, bar, calcTrace, i, x0, x1, y0, y1, opts) {
340
340
trace . constraintext === 'both' ||
341
341
trace . constraintext === 'outside' ;
342
342
343
- transform = getTransformToMoveOutsideBar ( x0 , x1 , y0 , y1 , textBB , {
343
+ transform = getTransform ( toMoveOutsideBar ( x0 , x1 , y0 , y1 , textBB , {
344
344
isHorizontal : isHorizontal ,
345
345
constrained : constrained ,
346
346
angle : trace . textangle
347
- } ) ;
347
+ } ) ) ;
348
348
} else {
349
349
constrained =
350
350
trace . constraintext === 'both' ||
351
351
trace . constraintext === 'inside' ;
352
352
353
- transform = getTransformToMoveInsideBar ( x0 , x1 , y0 , y1 , textBB , {
353
+ transform = getTransform ( toMoveInsideBar ( x0 , x1 , y0 , y1 , textBB , {
354
354
isHorizontal : isHorizontal ,
355
355
constrained : constrained ,
356
356
angle : trace . textangle ,
357
357
anchor : trace . insidetextanchor
358
- } ) ;
358
+ } ) ) ;
359
359
}
360
360
361
361
textSelection . attr ( 'transform' , transform ) ;
362
362
}
363
363
364
- function getRotationFromAngle ( angle ) {
364
+ function getRotateFromAngle ( angle ) {
365
365
return ( angle === 'auto' ) ? 0 : angle ;
366
366
}
367
367
368
- function getTransformToMoveInsideBar ( x0 , x1 , y0 , y1 , textBB , opts ) {
368
+ function toMoveInsideBar ( x0 , x1 , y0 , y1 , textBB , opts ) {
369
369
var isHorizontal = ! ! opts . isHorizontal ;
370
370
var constrained = ! ! opts . constrained ;
371
371
var angle = opts . angle || 0 ;
@@ -402,9 +402,9 @@ function getTransformToMoveInsideBar(x0, x1, y0, y1, textBB, opts) {
402
402
lx = tmp ;
403
403
}
404
404
405
- var rotation = getRotationFromAngle ( angle ) ;
406
- var absSin = Math . abs ( Math . sin ( Math . PI / 180 * rotation ) ) ;
407
- var absCos = Math . abs ( Math . cos ( Math . PI / 180 * rotation ) ) ;
405
+ var rotate = getRotateFromAngle ( angle ) ;
406
+ var absSin = Math . abs ( Math . sin ( Math . PI / 180 * rotate ) ) ;
407
+ var absCos = Math . abs ( Math . cos ( Math . PI / 180 * rotate ) ) ;
408
408
409
409
// compute and apply text padding
410
410
var dx = Math . max ( lx * absCos , ly * absSin ) ;
@@ -438,12 +438,19 @@ function getTransformToMoveInsideBar(x0, x1, y0, y1, textBB, opts) {
438
438
var textY = ( textBB . top + textBB . bottom ) / 2 ;
439
439
440
440
// lastly apply auto rotation
441
- if ( isAutoRotated ) rotation += 90 ;
442
-
443
- return getTransform ( textX , textY , targetX , targetY , scale , rotation ) ;
441
+ if ( isAutoRotated ) rotate += 90 ;
442
+
443
+ return {
444
+ textX : textX ,
445
+ textY : textY ,
446
+ targetX : targetX ,
447
+ targetY : targetY ,
448
+ scale : scale ,
449
+ rotate : rotate
450
+ } ;
444
451
}
445
452
446
- function getTransformToMoveOutsideBar ( x0 , x1 , y0 , y1 , textBB , opts ) {
453
+ function toMoveOutsideBar ( x0 , x1 , y0 , y1 , textBB , opts ) {
447
454
var isHorizontal = ! ! opts . isHorizontal ;
448
455
var constrained = ! ! opts . constrained ;
449
456
var angle = opts . angle || 0 ;
@@ -462,17 +469,17 @@ function getTransformToMoveOutsideBar(x0, x1, y0, y1, textBB, opts) {
462
469
textpad = ( lx > 2 * TEXTPAD ) ? TEXTPAD : 0 ;
463
470
}
464
471
465
- // compute rotation and scale
472
+ // compute rotate and scale
466
473
var scale = 1 ;
467
474
if ( constrained ) {
468
475
scale = ( isHorizontal ) ?
469
476
Math . min ( 1 , ly / textHeight ) :
470
477
Math . min ( 1 , lx / textWidth ) ;
471
478
}
472
479
473
- var rotation = getRotationFromAngle ( angle ) ;
474
- var absSin = Math . abs ( Math . sin ( Math . PI / 180 * rotation ) ) ;
475
- var absCos = Math . abs ( Math . cos ( Math . PI / 180 * rotation ) ) ;
480
+ var rotate = getRotateFromAngle ( angle ) ;
481
+ var absSin = Math . abs ( Math . sin ( Math . PI / 180 * rotate ) ) ;
482
+ var absCos = Math . abs ( Math . cos ( Math . PI / 180 * rotate ) ) ;
476
483
477
484
// compute text and target positions
478
485
var targetWidth = scale * ( isHorizontal ? textHeight : textWidth ) ;
@@ -491,10 +498,24 @@ function getTransformToMoveOutsideBar(x0, x1, y0, y1, textBB, opts) {
491
498
var textX = ( textBB . left + textBB . right ) / 2 ;
492
499
var textY = ( textBB . top + textBB . bottom ) / 2 ;
493
500
494
- return getTransform ( textX , textY , targetX , targetY , scale , rotation ) ;
501
+ return {
502
+ textX : textX ,
503
+ textY : textY ,
504
+ targetX : targetX ,
505
+ targetY : targetY ,
506
+ scale : scale ,
507
+ rotate : rotate
508
+ } ;
495
509
}
496
510
497
- function getTransform ( textX , textY , targetX , targetY , scale , rotation ) {
511
+ function getTransform ( opts ) {
512
+ var textX = opts . textX ;
513
+ var textY = opts . textY ;
514
+ var targetX = opts . targetX ;
515
+ var targetY = opts . targetY ;
516
+ var scale = opts . scale ;
517
+ var rotate = opts . rotate ;
518
+
498
519
var transformScale ;
499
520
var transformRotate ;
500
521
var transformTranslate ;
@@ -505,8 +526,8 @@ function getTransform(textX, textY, targetX, targetY, scale, rotation) {
505
526
transformScale = '' ;
506
527
}
507
528
508
- transformRotate = ( rotation ) ?
509
- 'rotate(' + rotation + ' ' + textX + ' ' + textY + ') ' : '' ;
529
+ transformRotate = ( rotate ) ?
530
+ 'rotate(' + rotate + ' ' + textX + ' ' + textY + ') ' : '' ;
510
531
511
532
// Note that scaling also affects the center of the text box
512
533
var translateX = ( targetX - scale * textX ) ;
@@ -610,6 +631,7 @@ function calcTextinfo(calcTrace, index, xa, ya) {
610
631
611
632
module . exports = {
612
633
plot : plot ,
613
- getTransformToMoveInsideBar : getTransformToMoveInsideBar ,
614
- getTransformToMoveOutsideBar : getTransformToMoveOutsideBar
634
+ getTransform : getTransform ,
635
+ toMoveInsideBar : toMoveInsideBar ,
636
+ toMoveOutsideBar : toMoveOutsideBar
615
637
} ;
0 commit comments