@@ -78,6 +78,10 @@ function handleAnnotationDefaults(annIn, fullLayout) {
7878 // xref, yref
7979 var axRef = Axes . coerceRef ( annIn , annOut , tdMock , axLetter ) ;
8080
81+ //todo: should be refactored in conjunction with Axes
82+ // axref, ayref
83+ var aaxRef = Axes . coerceARef ( annIn , annOut , tdMock , axLetter ) ;
84+
8185 // x, y
8286 var defaultPosition = 0.5 ;
8387 if ( axRef !== 'paper' ) {
@@ -92,7 +96,7 @@ function handleAnnotationDefaults(annIn, fullLayout) {
9296 newval = Lib . dateTime2ms ( annIn [ axLetter ] ) ;
9397 if ( newval !== false ) annIn [ axLetter ] = newval ;
9498
95- if ( annIn [ 'a' + axLetter + 'ref' ] === axRef ) {
99+ if ( aaxRef === axRef ) {
96100 var newvalB = Lib . dateTime2ms ( annIn [ 'a' + axLetter ] ) ;
97101 if ( newvalB !== false ) annIn [ 'a' + axLetter ] = newvalB ;
98102 }
@@ -487,15 +491,17 @@ annotations.draw = function(gd, index, opt, value) {
487491 // make sure the arrowhead (if there is one)
488492 // and the annotation center are visible
489493 if ( options . showarrow ) {
490- if ( options . axref === options . xref )
494+ if ( options . axref === options . xref ) {
491495 arrowX = Lib . constrain ( annPosPx . x , 1 , fullLayout . width - 1 ) ;
492- else
496+ } else {
493497 arrowX = Lib . constrain ( annPosPx . x - options . ax , 1 , fullLayout . width - 1 ) ;
498+ }
494499
495- if ( options . ayref === options . yref )
500+ if ( options . ayref === options . yref ) {
496501 arrowY = Lib . constrain ( annPosPx . y , 1 , fullLayout . height - 1 ) ;
497- else
502+ } else {
498503 arrowY = Lib . constrain ( annPosPx . y - options . ay , 1 , fullLayout . height - 1 ) ;
504+ }
499505 }
500506 annPosPx . x = Lib . constrain ( annPosPx . x , 1 , fullLayout . width - 1 ) ;
501507 annPosPx . y = Lib . constrain ( annPosPx . y , 1 , fullLayout . height - 1 ) ;
@@ -515,15 +521,17 @@ annotations.draw = function(gd, index, opt, value) {
515521 outerwidth - borderwidth , outerheight - borderwidth ) ;
516522
517523 var annX = 0 , annY = 0 ;
518- if ( options . axref === options . xref )
524+ if ( options . axref === options . xref ) {
519525 annX = Math . round ( annPosPx . aax - outerwidth / 2 ) ;
520- else
526+ } else {
521527 annX = Math . round ( annPosPx . x - outerwidth / 2 ) ;
528+ }
522529
523- if ( options . ayref === options . yref )
530+ if ( options . ayref === options . yref ) {
524531 annY = Math . round ( annPosPx . aay - outerheight / 2 ) ;
525- else
532+ } else {
526533 annY = Math . round ( annPosPx . y - outerheight / 2 ) ;
534+ }
527535
528536 ann . call ( Lib . setTranslate , annX , annY ) ;
529537
@@ -544,15 +552,17 @@ annotations.draw = function(gd, index, opt, value) {
544552 // how-to-get-the-width-of-an-svg-tspan-element
545553 var arrowX0 , arrowY0 ;
546554
547- if ( options . axref === options . xref )
555+ if ( options . axref === options . xref ) {
548556 arrowX0 = annPosPx . aax + dx ;
549- else
557+ } else {
550558 arrowX0 = annPosPx . x + dx ;
559+ }
551560
552- if ( options . ayref === options . yref )
561+ if ( options . ayref === options . yref ) {
553562 arrowY0 = annPosPx . aay + dy ;
554- else
563+ } else {
555564 arrowY0 = annPosPx . y + dy ;
565+ }
556566
557567 // create transform matrix and related functions
558568 var transform =
@@ -654,15 +664,17 @@ annotations.draw = function(gd, index, opt, value) {
654664 ( options . y + dy / ya . _m ) :
655665 ( 1 - ( ( arrowY + dy - gs . t ) / gs . h ) ) ;
656666
657- if ( options . axref === options . xref )
667+ if ( options . axref === options . xref ) {
658668 update [ annbase + '.ax' ] = xa ?
659669 ( options . ax + dx / xa . _m ) :
660670 ( ( arrowX + dx - gs . l ) / gs . w ) ;
671+ }
661672
662- if ( options . ayref === options . yref )
673+ if ( options . ayref === options . yref ) {
663674 update [ annbase + '.ay' ] = ya ?
664675 ( options . ay + dy / ya . _m ) :
665676 ( 1 - ( ( arrowY + dy - gs . t ) / gs . h ) ) ;
677+ }
666678
667679 anng . attr ( {
668680 transform : 'rotate(' + textangle + ',' +
@@ -706,15 +718,17 @@ annotations.draw = function(gd, index, opt, value) {
706718 ann . call ( Lib . setTranslate , x0 + dx , y0 + dy ) ;
707719 var csr = 'pointer' ;
708720 if ( options . showarrow ) {
709- if ( options . axref === options . xref )
721+ if ( options . axref === options . xref ) {
710722 update [ annbase + '.ax' ] = xa . p2l ( xa . l2p ( options . ax ) + dx ) ;
711- else
723+ } else {
712724 update [ annbase + '.ax' ] = options . ax + dx ;
725+ }
713726
714- if ( options . ayref === options . yref )
727+ if ( options . ayref === options . yref ) {
715728 update [ annbase + '.ay' ] = ya . p2l ( ya . l2p ( options . ay ) + dy ) ;
716- else
729+ } else {
717730 update [ annbase + '.ay' ] = options . ay + dy ;
731+ }
718732
719733 drawArrow ( dx , dy ) ;
720734 }
0 commit comments