@@ -172,12 +172,19 @@ function drawOne(gd, index, opt, value) {
172
172
continue ;
173
173
}
174
174
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' ) ) ,
177
177
position = optionsIn [ axLetter ] ,
178
178
axTypeOld = oldPrivate [ '_' + axLetter + 'type' ] ;
179
179
180
180
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
+
181
188
var autoAnchor = optionsIn [ axLetter + 'anchor' ] === 'auto' ,
182
189
plotSize = ( axLetter === 'x' ? gs . w : gs . h ) ,
183
190
halfSizeFrac = ( oldPrivate [ '_' + axLetter + 'size' ] || 0 ) /
@@ -186,18 +193,11 @@ function drawOne(gd, index, opt, value) {
186
193
// go to the same fraction of the axis length
187
194
// whether or not these axes share a domain
188
195
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 ) ) ;
196
197
}
197
198
else if ( axOld ) { // data -> paper
198
199
// 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 ) ;
201
201
202
202
// next scale the axis to the whole plot
203
203
position = axOld . domain [ 0 ] +
@@ -225,8 +225,7 @@ function drawOne(gd, index, opt, value) {
225
225
( axNew . domain [ 1 ] - axNew . domain [ 0 ] ) ;
226
226
227
227
// finally convert to data coordinates
228
- position = axNew . range [ 0 ] +
229
- position * ( axNew . range [ 1 ] - axNew . range [ 0 ] ) ;
228
+ position = axNew . fraction2r ( position ) ;
230
229
}
231
230
}
232
231
@@ -358,20 +357,21 @@ function drawOne(gd, index, opt, value) {
358
357
// outside the visible plot (as long as the axis
359
358
// isn't autoranged - then we need to draw it
360
359
// 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 ) ) {
363
362
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 ) {
366
365
annotationIsOffscreen = true ;
367
366
}
368
- } else {
367
+ }
368
+ else {
369
369
annotationIsOffscreen = true ;
370
370
}
371
371
372
372
if ( annotationIsOffscreen ) return ;
373
373
}
374
- annPosPx [ axLetter ] = ax . _offset + ax . l2p ( options [ axLetter ] ) ;
374
+ annPosPx [ axLetter ] = ax . _offset + ax . r2p ( options [ axLetter ] ) ;
375
375
alignPosition = 0.5 ;
376
376
}
377
377
else {
@@ -384,7 +384,7 @@ function drawOne(gd, index, opt, value) {
384
384
385
385
var alignShift = 0 ;
386
386
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 ] ) ;
388
388
} else {
389
389
if ( options . showarrow ) {
390
390
alignShift = options [ 'a' + axLetter ] ;
@@ -584,22 +584,22 @@ function drawOne(gd, index, opt, value) {
584
584
ann . call ( Lib . setTranslate , xcenter , ycenter ) ;
585
585
586
586
update [ annbase + '.x' ] = xa ?
587
- ( options . x + dx / xa . _m ) :
587
+ xa . p2r ( xa . r2p ( options . x ) + dx ) :
588
588
( ( arrowX + dx - gs . l ) / gs . w ) ;
589
589
update [ annbase + '.y' ] = ya ?
590
- ( options . y + dy / ya . _m ) :
590
+ ya . p2r ( ya . r2p ( options . y ) + dy ) :
591
591
( 1 - ( ( arrowY + dy - gs . t ) / gs . h ) ) ;
592
592
593
593
if ( options . axref === options . xref ) {
594
594
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 ) ;
597
597
}
598
598
599
599
if ( options . ayref === options . yref ) {
600
600
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 ) ) ;
603
603
}
604
604
605
605
anng . attr ( {
@@ -645,13 +645,13 @@ function drawOne(gd, index, opt, value) {
645
645
var csr = 'pointer' ;
646
646
if ( options . showarrow ) {
647
647
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 ) ;
649
649
} else {
650
650
update [ annbase + '.ax' ] = options . ax + dx ;
651
651
}
652
652
653
653
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 ) ;
655
655
} else {
656
656
update [ annbase + '.ay' ] = options . ay + dy ;
657
657
}
0 commit comments