@@ -78,6 +78,10 @@ function handleAnnotationDefaults(annIn, fullLayout) {
78
78
// xref, yref
79
79
var axRef = Axes . coerceRef ( annIn , annOut , tdMock , axLetter ) ;
80
80
81
+ //todo: should be refactored in conjunction with Axes
82
+ // axref, ayref
83
+ var aaxRef = Axes . coerceARef ( annIn , annOut , tdMock , axLetter ) ;
84
+
81
85
// x, y
82
86
var defaultPosition = 0.5 ;
83
87
if ( axRef !== 'paper' ) {
@@ -92,7 +96,7 @@ function handleAnnotationDefaults(annIn, fullLayout) {
92
96
newval = Lib . dateTime2ms ( annIn [ axLetter ] ) ;
93
97
if ( newval !== false ) annIn [ axLetter ] = newval ;
94
98
95
- if ( annIn [ 'a' + axLetter + 'ref' ] === axRef ) {
99
+ if ( aaxRef === axRef ) {
96
100
var newvalB = Lib . dateTime2ms ( annIn [ 'a' + axLetter ] ) ;
97
101
if ( newvalB !== false ) annIn [ 'a' + axLetter ] = newvalB ;
98
102
}
@@ -487,15 +491,17 @@ annotations.draw = function(gd, index, opt, value) {
487
491
// make sure the arrowhead (if there is one)
488
492
// and the annotation center are visible
489
493
if ( options . showarrow ) {
490
- if ( options . axref === options . xref )
494
+ if ( options . axref === options . xref ) {
491
495
arrowX = Lib . constrain ( annPosPx . x , 1 , fullLayout . width - 1 ) ;
492
- else
496
+ } else {
493
497
arrowX = Lib . constrain ( annPosPx . x - options . ax , 1 , fullLayout . width - 1 ) ;
498
+ }
494
499
495
- if ( options . ayref === options . yref )
500
+ if ( options . ayref === options . yref ) {
496
501
arrowY = Lib . constrain ( annPosPx . y , 1 , fullLayout . height - 1 ) ;
497
- else
502
+ } else {
498
503
arrowY = Lib . constrain ( annPosPx . y - options . ay , 1 , fullLayout . height - 1 ) ;
504
+ }
499
505
}
500
506
annPosPx . x = Lib . constrain ( annPosPx . x , 1 , fullLayout . width - 1 ) ;
501
507
annPosPx . y = Lib . constrain ( annPosPx . y , 1 , fullLayout . height - 1 ) ;
@@ -515,15 +521,17 @@ annotations.draw = function(gd, index, opt, value) {
515
521
outerwidth - borderwidth , outerheight - borderwidth ) ;
516
522
517
523
var annX = 0 , annY = 0 ;
518
- if ( options . axref === options . xref )
524
+ if ( options . axref === options . xref ) {
519
525
annX = Math . round ( annPosPx . aax - outerwidth / 2 ) ;
520
- else
526
+ } else {
521
527
annX = Math . round ( annPosPx . x - outerwidth / 2 ) ;
528
+ }
522
529
523
- if ( options . ayref === options . yref )
530
+ if ( options . ayref === options . yref ) {
524
531
annY = Math . round ( annPosPx . aay - outerheight / 2 ) ;
525
- else
532
+ } else {
526
533
annY = Math . round ( annPosPx . y - outerheight / 2 ) ;
534
+ }
527
535
528
536
ann . call ( Lib . setTranslate , annX , annY ) ;
529
537
@@ -544,15 +552,17 @@ annotations.draw = function(gd, index, opt, value) {
544
552
// how-to-get-the-width-of-an-svg-tspan-element
545
553
var arrowX0 , arrowY0 ;
546
554
547
- if ( options . axref === options . xref )
555
+ if ( options . axref === options . xref ) {
548
556
arrowX0 = annPosPx . aax + dx ;
549
- else
557
+ } else {
550
558
arrowX0 = annPosPx . x + dx ;
559
+ }
551
560
552
- if ( options . ayref === options . yref )
561
+ if ( options . ayref === options . yref ) {
553
562
arrowY0 = annPosPx . aay + dy ;
554
- else
563
+ } else {
555
564
arrowY0 = annPosPx . y + dy ;
565
+ }
556
566
557
567
// create transform matrix and related functions
558
568
var transform =
@@ -654,15 +664,17 @@ annotations.draw = function(gd, index, opt, value) {
654
664
( options . y + dy / ya . _m ) :
655
665
( 1 - ( ( arrowY + dy - gs . t ) / gs . h ) ) ;
656
666
657
- if ( options . axref === options . xref )
667
+ if ( options . axref === options . xref ) {
658
668
update [ annbase + '.ax' ] = xa ?
659
669
( options . ax + dx / xa . _m ) :
660
670
( ( arrowX + dx - gs . l ) / gs . w ) ;
671
+ }
661
672
662
- if ( options . ayref === options . yref )
673
+ if ( options . ayref === options . yref ) {
663
674
update [ annbase + '.ay' ] = ya ?
664
675
( options . ay + dy / ya . _m ) :
665
676
( 1 - ( ( arrowY + dy - gs . t ) / gs . h ) ) ;
677
+ }
666
678
667
679
anng . attr ( {
668
680
transform : 'rotate(' + textangle + ',' +
@@ -706,15 +718,17 @@ annotations.draw = function(gd, index, opt, value) {
706
718
ann . call ( Lib . setTranslate , x0 + dx , y0 + dy ) ;
707
719
var csr = 'pointer' ;
708
720
if ( options . showarrow ) {
709
- if ( options . axref === options . xref )
721
+ if ( options . axref === options . xref ) {
710
722
update [ annbase + '.ax' ] = xa . p2l ( xa . l2p ( options . ax ) + dx ) ;
711
- else
723
+ } else {
712
724
update [ annbase + '.ax' ] = options . ax + dx ;
725
+ }
713
726
714
- if ( options . ayref === options . yref )
727
+ if ( options . ayref === options . yref ) {
715
728
update [ annbase + '.ay' ] = ya . p2l ( ya . l2p ( options . ay ) + dy ) ;
716
- else
729
+ } else {
717
730
update [ annbase + '.ay' ] = options . ay + dy ;
731
+ }
718
732
719
733
drawArrow ( dx , dy ) ;
720
734
}
0 commit comments