@@ -172,12 +172,19 @@ function drawOne(gd, index, opt, value) {
172172 continue ;
173173 }
174174
175- var axOld = Axes . getFromId ( gd , Axes . coerceRef ( oldRef , { } , gd , axLetter ) ) ,
176- axNew = Axes . getFromId ( gd , Axes . coerceRef ( optionsIn , { } , gd , axLetter ) ) ,
175+ var axOld = Axes . getFromId ( gd , Axes . coerceRef ( oldRef , { } , gd , axLetter , '' , 'paper' ) ) ,
176+ axNew = Axes . getFromId ( gd , Axes . coerceRef ( optionsIn , { } , gd , axLetter , '' , 'paper' ) ) ,
177177 position = optionsIn [ axLetter ] ,
178178 axTypeOld = oldPrivate [ '_' + axLetter + 'type' ] ;
179179
180180 if ( optionsEdit [ axLetter + 'ref' ] !== undefined ) {
181+
182+ // TODO: include ax / ay / axref / ayref here if not 'pixel'
183+ // or even better, move all of this machinery out of here and into
184+ // streambed as extra attributes to a regular relayout call
185+ // we should do this after v2.0 when it can work equivalently for
186+ // annotations, shapes, and images.
187+
181188 var autoAnchor = optionsIn [ axLetter + 'anchor' ] === 'auto' ,
182189 plotSize = ( axLetter === 'x' ? gs . w : gs . h ) ,
183190 halfSizeFrac = ( oldPrivate [ '_' + axLetter + 'size' ] || 0 ) /
@@ -186,18 +193,11 @@ function drawOne(gd, index, opt, value) {
186193 // go to the same fraction of the axis length
187194 // whether or not these axes share a domain
188195
189- // first convert to fraction of the axis
190- position = ( position - axOld . range [ 0 ] ) /
191- ( axOld . range [ 1 ] - axOld . range [ 0 ] ) ;
192-
193- // then convert to new data coordinates at the same fraction
194- position = axNew . range [ 0 ] +
195- position * ( axNew . range [ 1 ] - axNew . range [ 0 ] ) ;
196+ position = axNew . fraction2r ( axOld . r2fraction ( position ) ) ;
196197 }
197198 else if ( axOld ) { // data -> paper
198199 // first convert to fraction of the axis
199- position = ( position - axOld . range [ 0 ] ) /
200- ( axOld . range [ 1 ] - axOld . range [ 0 ] ) ;
200+ position = axOld . r2fraction ( position ) ;
201201
202202 // next scale the axis to the whole plot
203203 position = axOld . domain [ 0 ] +
@@ -225,8 +225,7 @@ function drawOne(gd, index, opt, value) {
225225 ( axNew . domain [ 1 ] - axNew . domain [ 0 ] ) ;
226226
227227 // finally convert to data coordinates
228- position = axNew . range [ 0 ] +
229- position * ( axNew . range [ 1 ] - axNew . range [ 0 ] ) ;
228+ position = axNew . fraction2r ( position ) ;
230229 }
231230 }
232231
@@ -358,20 +357,21 @@ function drawOne(gd, index, opt, value) {
358357 // outside the visible plot (as long as the axis
359358 // isn't autoranged - then we need to draw it
360359 // anyway to get its bounding box)
361- if ( ! ax . autorange && ( ( options [ axLetter ] - ax . range [ 0 ] ) *
362- ( options [ axLetter ] - ax . range [ 1 ] ) > 0 ) ) {
360+ var posFraction = ax . r2fraction ( options [ axLetter ] ) ;
361+ if ( ! ax . autorange && ( posFraction < 0 || posFraction > 1 ) ) {
363362 if ( options [ 'a' + axLetter + 'ref' ] === axRef ) {
364- if ( ( options [ 'a' + axLetter ] - ax . range [ 0 ] ) *
365- ( options [ 'a' + axLetter ] - ax . range [ 1 ] ) > 0 ) {
363+ posFraction = ax . r2fraction ( options [ 'a' + axLetter ] ) ;
364+ if ( posFraction < 0 || posFraction > 1 ) {
366365 annotationIsOffscreen = true ;
367366 }
368- } else {
367+ }
368+ else {
369369 annotationIsOffscreen = true ;
370370 }
371371
372372 if ( annotationIsOffscreen ) return ;
373373 }
374- annPosPx [ axLetter ] = ax . _offset + ax . l2p ( options [ axLetter ] ) ;
374+ annPosPx [ axLetter ] = ax . _offset + ax . r2p ( options [ axLetter ] ) ;
375375 alignPosition = 0.5 ;
376376 }
377377 else {
@@ -384,7 +384,7 @@ function drawOne(gd, index, opt, value) {
384384
385385 var alignShift = 0 ;
386386 if ( options [ 'a' + axLetter + 'ref' ] === axRef ) {
387- annPosPx [ 'aa' + axLetter ] = ax . _offset + ax . l2p ( options [ 'a' + axLetter ] ) ;
387+ annPosPx [ 'aa' + axLetter ] = ax . _offset + ax . r2p ( options [ 'a' + axLetter ] ) ;
388388 } else {
389389 if ( options . showarrow ) {
390390 alignShift = options [ 'a' + axLetter ] ;
@@ -584,22 +584,22 @@ function drawOne(gd, index, opt, value) {
584584 ann . call ( Lib . setTranslate , xcenter , ycenter ) ;
585585
586586 update [ annbase + '.x' ] = xa ?
587- ( options . x + dx / xa . _m ) :
587+ xa . p2r ( xa . r2p ( options . x ) + dx ) :
588588 ( ( arrowX + dx - gs . l ) / gs . w ) ;
589589 update [ annbase + '.y' ] = ya ?
590- ( options . y + dy / ya . _m ) :
590+ ya . p2r ( ya . r2p ( options . y ) + dy ) :
591591 ( 1 - ( ( arrowY + dy - gs . t ) / gs . h ) ) ;
592592
593593 if ( options . axref === options . xref ) {
594594 update [ annbase + '.ax' ] = xa ?
595- ( options . ax + dx / xa . _m ) :
596- ( ( arrowX + dx - gs . l ) / gs . w ) ;
595+ xa . p2r ( xa . r2p ( options . ax ) + dx ) :
596+ ( ( arrowX + dx - gs . l ) / gs . w ) ;
597597 }
598598
599599 if ( options . ayref === options . yref ) {
600600 update [ annbase + '.ay' ] = ya ?
601- ( options . ay + dy / ya . _m ) :
602- ( 1 - ( ( arrowY + dy - gs . t ) / gs . h ) ) ;
601+ ya . p2r ( ya . r2p ( options . ay ) + dy ) :
602+ ( 1 - ( ( arrowY + dy - gs . t ) / gs . h ) ) ;
603603 }
604604
605605 anng . attr ( {
@@ -645,13 +645,13 @@ function drawOne(gd, index, opt, value) {
645645 var csr = 'pointer' ;
646646 if ( options . showarrow ) {
647647 if ( options . axref === options . xref ) {
648- update [ annbase + '.ax' ] = xa . p2l ( xa . l2p ( options . ax ) + dx ) ;
648+ update [ annbase + '.ax' ] = xa . p2r ( xa . r2p ( options . ax ) + dx ) ;
649649 } else {
650650 update [ annbase + '.ax' ] = options . ax + dx ;
651651 }
652652
653653 if ( options . ayref === options . yref ) {
654- update [ annbase + '.ay' ] = ya . p2l ( ya . l2p ( options . ay ) + dy ) ;
654+ update [ annbase + '.ay' ] = ya . p2r ( ya . r2p ( options . ay ) + dy ) ;
655655 } else {
656656 update [ annbase + '.ay' ] = options . ay + dy ;
657657 }
0 commit comments