@@ -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
@@ -357,20 +356,21 @@ function drawOne(gd, index, opt, value) {
357
356
// outside the visible plot (as long as the axis
358
357
// isn't autoranged - then we need to draw it
359
358
// anyway to get its bounding box)
360
- if ( ! ax . autorange && ( ( options [ axLetter ] - ax . range [ 0 ] ) *
361
- ( options [ axLetter ] - ax . range [ 1 ] ) > 0 ) ) {
359
+ var posFraction = ax . r2fraction ( options [ axLetter ] ) ;
360
+ if ( ! ax . autorange && ( posFraction < 0 || posFraction > 1 ) ) {
362
361
if ( options [ 'a' + axLetter + 'ref' ] === axRef ) {
363
- if ( ( options [ 'a' + axLetter ] - ax . range [ 0 ] ) *
364
- ( options [ 'a' + axLetter ] - ax . range [ 1 ] ) > 0 ) {
362
+ posFraction = ax . r2fraction ( options [ 'a' + axLetter ] ) ;
363
+ if ( posFraction < 0 || posFraction > 1 ) {
365
364
annotationIsOffscreen = true ;
366
365
}
367
- } else {
366
+ }
367
+ else {
368
368
annotationIsOffscreen = true ;
369
369
}
370
370
371
371
if ( annotationIsOffscreen ) return ;
372
372
}
373
- annPosPx [ axLetter ] = ax . _offset + ax . l2p ( options [ axLetter ] ) ;
373
+ annPosPx [ axLetter ] = ax . _offset + ax . r2p ( options [ axLetter ] ) ;
374
374
alignPosition = 0.5 ;
375
375
}
376
376
else {
@@ -383,7 +383,7 @@ function drawOne(gd, index, opt, value) {
383
383
384
384
var alignShift = 0 ;
385
385
if ( options [ 'a' + axLetter + 'ref' ] === axRef ) {
386
- annPosPx [ 'aa' + axLetter ] = ax . _offset + ax . l2p ( options [ 'a' + axLetter ] ) ;
386
+ annPosPx [ 'aa' + axLetter ] = ax . _offset + ax . r2p ( options [ 'a' + axLetter ] ) ;
387
387
} else {
388
388
if ( options . showarrow ) {
389
389
alignShift = options [ 'a' + axLetter ] ;
@@ -583,22 +583,22 @@ function drawOne(gd, index, opt, value) {
583
583
ann . call ( Lib . setTranslate , xcenter , ycenter ) ;
584
584
585
585
update [ annbase + '.x' ] = xa ?
586
- ( options . x + dx / xa . _m ) :
586
+ xa . p2r ( xa . r2p ( options . x ) + dx ) :
587
587
( ( arrowX + dx - gs . l ) / gs . w ) ;
588
588
update [ annbase + '.y' ] = ya ?
589
- ( options . y + dy / ya . _m ) :
589
+ ya . p2r ( ya . r2p ( options . y ) + dy ) :
590
590
( 1 - ( ( arrowY + dy - gs . t ) / gs . h ) ) ;
591
591
592
592
if ( options . axref === options . xref ) {
593
593
update [ annbase + '.ax' ] = xa ?
594
- ( options . ax + dx / xa . _m ) :
595
- ( ( arrowX + dx - gs . l ) / gs . w ) ;
594
+ xa . p2r ( xa . r2p ( options . ax ) + dx ) :
595
+ ( ( arrowX + dx - gs . l ) / gs . w ) ;
596
596
}
597
597
598
598
if ( options . ayref === options . yref ) {
599
599
update [ annbase + '.ay' ] = ya ?
600
- ( options . ay + dy / ya . _m ) :
601
- ( 1 - ( ( arrowY + dy - gs . t ) / gs . h ) ) ;
600
+ ya . p2r ( ya . r2p ( options . ay ) + dy ) :
601
+ ( 1 - ( ( arrowY + dy - gs . t ) / gs . h ) ) ;
602
602
}
603
603
604
604
anng . attr ( {
@@ -644,13 +644,13 @@ function drawOne(gd, index, opt, value) {
644
644
var csr = 'pointer' ;
645
645
if ( options . showarrow ) {
646
646
if ( options . axref === options . xref ) {
647
- update [ annbase + '.ax' ] = xa . p2l ( xa . l2p ( options . ax ) + dx ) ;
647
+ update [ annbase + '.ax' ] = xa . p2r ( xa . r2p ( options . ax ) + dx ) ;
648
648
} else {
649
649
update [ annbase + '.ax' ] = options . ax + dx ;
650
650
}
651
651
652
652
if ( options . ayref === options . yref ) {
653
- update [ annbase + '.ay' ] = ya . p2l ( ya . l2p ( options . ay ) + dy ) ;
653
+ update [ annbase + '.ay' ] = ya . p2r ( ya . r2p ( options . ay ) + dy ) ;
654
654
} else {
655
655
update [ annbase + '.ay' ] = options . ay + dy ;
656
656
}
0 commit comments