@@ -168,12 +168,19 @@ function drawOne(gd, index, opt, value) {
168
168
continue ;
169
169
}
170
170
171
- var axOld = Axes . getFromId ( gd , Axes . coerceRef ( oldRef , { } , gd , axLetter ) ) ,
172
- axNew = Axes . getFromId ( gd , Axes . coerceRef ( optionsIn , { } , gd , axLetter ) ) ,
171
+ var axOld = Axes . getFromId ( gd , Axes . coerceRef ( oldRef , { } , gd , axLetter , '' , 'paper' ) ) ,
172
+ axNew = Axes . getFromId ( gd , Axes . coerceRef ( optionsIn , { } , gd , axLetter , '' , 'paper' ) ) ,
173
173
position = optionsIn [ axLetter ] ,
174
174
axTypeOld = oldPrivate [ '_' + axLetter + 'type' ] ;
175
175
176
176
if ( optionsEdit [ axLetter + 'ref' ] !== undefined ) {
177
+
178
+ // TODO: include ax / ay / axref / ayref here if not 'pixel'
179
+ // or even better, move all of this machinery out of here and into
180
+ // streambed as extra attributes to a regular relayout call
181
+ // we should do this after v2.0 when it can work equivalently for
182
+ // annotations, shapes, and images.
183
+
177
184
var autoAnchor = optionsIn [ axLetter + 'anchor' ] === 'auto' ,
178
185
plotSize = ( axLetter === 'x' ? gs . w : gs . h ) ,
179
186
halfSizeFrac = ( oldPrivate [ '_' + axLetter + 'size' ] || 0 ) /
@@ -182,18 +189,11 @@ function drawOne(gd, index, opt, value) {
182
189
// go to the same fraction of the axis length
183
190
// whether or not these axes share a domain
184
191
185
- // first convert to fraction of the axis
186
- position = ( position - axOld . range [ 0 ] ) /
187
- ( axOld . range [ 1 ] - axOld . range [ 0 ] ) ;
188
-
189
- // then convert to new data coordinates at the same fraction
190
- position = axNew . range [ 0 ] +
191
- position * ( axNew . range [ 1 ] - axNew . range [ 0 ] ) ;
192
+ position = axNew . fraction2r ( axOld . r2fraction ( position ) ) ;
192
193
}
193
194
else if ( axOld ) { // data -> paper
194
195
// first convert to fraction of the axis
195
- position = ( position - axOld . range [ 0 ] ) /
196
- ( axOld . range [ 1 ] - axOld . range [ 0 ] ) ;
196
+ position = axOld . r2fraction ( position ) ;
197
197
198
198
// next scale the axis to the whole plot
199
199
position = axOld . domain [ 0 ] +
@@ -221,8 +221,7 @@ function drawOne(gd, index, opt, value) {
221
221
( axNew . domain [ 1 ] - axNew . domain [ 0 ] ) ;
222
222
223
223
// finally convert to data coordinates
224
- position = axNew . range [ 0 ] +
225
- position * ( axNew . range [ 1 ] - axNew . range [ 0 ] ) ;
224
+ position = axNew . fraction2r ( position ) ;
226
225
}
227
226
}
228
227
@@ -353,20 +352,21 @@ function drawOne(gd, index, opt, value) {
353
352
// outside the visible plot (as long as the axis
354
353
// isn't autoranged - then we need to draw it
355
354
// anyway to get its bounding box)
356
- if ( ! ax . autorange && ( ( options [ axLetter ] - ax . range [ 0 ] ) *
357
- ( options [ axLetter ] - ax . range [ 1 ] ) > 0 ) ) {
355
+ var posFraction = ax . r2fraction ( options [ axLetter ] ) ;
356
+ if ( ! ax . autorange && ( posFraction < 0 || posFraction > 1 ) ) {
358
357
if ( options [ 'a' + axLetter + 'ref' ] === axRef ) {
359
- if ( ( options [ 'a' + axLetter ] - ax . range [ 0 ] ) *
360
- ( options [ 'a' + axLetter ] - ax . range [ 1 ] ) > 0 ) {
358
+ posFraction = ax . r2fraction ( options [ 'a' + axLetter ] ) ;
359
+ if ( posFraction < 0 || posFraction > 1 ) {
361
360
annotationIsOffscreen = true ;
362
361
}
363
- } else {
362
+ }
363
+ else {
364
364
annotationIsOffscreen = true ;
365
365
}
366
366
367
367
if ( annotationIsOffscreen ) return ;
368
368
}
369
- annPosPx [ axLetter ] = ax . _offset + ax . l2p ( options [ axLetter ] ) ;
369
+ annPosPx [ axLetter ] = ax . _offset + ax . l2p ( ax . r2l ( options [ axLetter ] ) ) ;
370
370
alignPosition = 0.5 ;
371
371
}
372
372
else {
@@ -379,7 +379,7 @@ function drawOne(gd, index, opt, value) {
379
379
380
380
var alignShift = 0 ;
381
381
if ( options [ 'a' + axLetter + 'ref' ] === axRef ) {
382
- annPosPx [ 'aa' + axLetter ] = ax . _offset + ax . l2p ( options [ 'a' + axLetter ] ) ;
382
+ annPosPx [ 'aa' + axLetter ] = ax . _offset + ax . l2p ( ax . r2l ( options [ 'a' + axLetter ] ) ) ;
383
383
} else {
384
384
if ( options . showarrow ) {
385
385
alignShift = options [ 'a' + axLetter ] ;
0 commit comments