7
7
capitalize ,
8
8
connectLayoutToPlot ,
9
9
connectToContainer ,
10
+ getAllAxes ,
10
11
supplyLayoutPlotProps ,
11
12
striptags ,
12
13
} from 'lib' ;
@@ -196,7 +197,7 @@ export const LayoutNumericFractionInverse = connectLayoutToPlot(
196
197
197
198
export const AnnotationArrowRef = connectToContainer ( UnconnectedDropdown , {
198
199
modifyPlotProps : ( props , context , plotProps ) => {
199
- const { fullContainer : { xref, yref} , plotly , graphDiv } = context ;
200
+ const { fullContainer : { xref, yref} } = context ;
200
201
201
202
let currentAxisRef ;
202
203
if ( props . attr === 'axref' ) {
@@ -212,12 +213,19 @@ export const AnnotationArrowRef = connectToContainer(UnconnectedDropdown, {
212
213
213
214
if ( currentAxisRef === 'paper' ) {
214
215
// If currentAxesRef is paper provide all axes options to user.
215
- plotProps . options = [
216
- { label : 'in pixels' , value : 'pixel' } ,
217
- ...computeAxesRefOptions (
218
- plotly . Axes . list ( graphDiv , props . attr . charAt ( 1 ) )
219
- ) ,
220
- ] ;
216
+ if ( props . attr === 'axref' ) {
217
+ plotProps . options = [
218
+ { label : 'in pixels' , value : 'pixel' } ,
219
+ ...computeAxesRefOptions ( getAllAxes ( context . fullLayout ) , 'x' ) ,
220
+ ] ;
221
+ }
222
+
223
+ if ( props . attr === 'ayref' ) {
224
+ plotProps . options = [
225
+ { label : 'in pixels' , value : 'pixel' } ,
226
+ ...computeAxesRefOptions ( getAllAxes ( context . fullLayout ) , 'y' ) ,
227
+ ] ;
228
+ }
221
229
} else {
222
230
// If currentAxesRef is an actual axes then offer that value as the only
223
231
// axes option.
@@ -233,7 +241,7 @@ export const AnnotationArrowRef = connectToContainer(UnconnectedDropdown, {
233
241
234
242
export const AnnotationRef = connectToContainer ( UnconnectedDropdown , {
235
243
modifyPlotProps : ( props , context , plotProps ) => {
236
- const { fullContainer : { axref, ayref} , graphDiv , plotly } = context ;
244
+ const { fullContainer : { axref, ayref} } = context ;
237
245
238
246
let currentOffsetRef ;
239
247
if ( props . attr === 'xref' ) {
@@ -247,12 +255,19 @@ export const AnnotationRef = connectToContainer(UnconnectedDropdown, {
247
255
) ;
248
256
}
249
257
250
- plotProps . options = [
251
- { label : 'Canvas' , value : 'paper' } ,
252
- ...computeAxesRefOptions (
253
- plotly . Axes . list ( graphDiv , props . attr . charAt ( 0 ) )
254
- ) ,
255
- ] ;
258
+ if ( props . attr === 'xref' ) {
259
+ plotProps . options = [
260
+ { label : 'Canvas' , value : 'paper' } ,
261
+ ...computeAxesRefOptions ( getAllAxes ( context . fullLayout ) , 'x' ) ,
262
+ ] ;
263
+ }
264
+
265
+ if ( props . attr === 'yref' ) {
266
+ plotProps . options = [
267
+ { label : 'Canvas' , value : 'paper' } ,
268
+ ...computeAxesRefOptions ( getAllAxes ( context . fullLayout ) , 'y' ) ,
269
+ ] ;
270
+ }
256
271
257
272
if ( currentOffsetRef !== 'pixel' ) {
258
273
plotProps . updatePlot = v => {
@@ -280,15 +295,19 @@ export const AnnotationRef = connectToContainer(UnconnectedDropdown, {
280
295
281
296
export const PositioningRef = connectToContainer ( UnconnectedDropdown , {
282
297
modifyPlotProps : ( props , context , plotProps ) => {
283
- const { graphDiv, plotly} = context ;
284
-
285
- plotProps . options = [
286
- { label : 'Canvas' , value : 'paper' } ,
287
- ...computeAxesRefOptions (
288
- plotly . Axes . list ( graphDiv , props . attr . charAt ( 0 ) )
289
- ) ,
290
- ] ;
298
+ if ( props . attr === 'xref' ) {
299
+ plotProps . options = [
300
+ { label : 'Canvas' , value : 'paper' } ,
301
+ ...computeAxesRefOptions ( getAllAxes ( context . fullLayout ) , 'x' ) ,
302
+ ] ;
303
+ }
291
304
305
+ if ( props . attr === 'yref' ) {
306
+ plotProps . options = [
307
+ { label : 'Canvas' , value : 'paper' } ,
308
+ ...computeAxesRefOptions ( getAllAxes ( context . fullLayout ) , 'y' ) ,
309
+ ] ;
310
+ }
292
311
plotProps . clearable = false ;
293
312
} ,
294
313
} ) ;
@@ -321,14 +340,15 @@ export const PositioningNumeric = connectToContainer(UnconnectedNumeric, {
321
340
} ,
322
341
} ) ;
323
342
324
- function computeAxesRefOptions ( axes ) {
343
+ function computeAxesRefOptions ( axes , refAxis ) {
325
344
const options = [ ] ;
326
345
for ( let i = 0 ; i < axes . length ; i ++ ) {
327
346
const ax = axes [ i ] ;
328
-
329
- // checking user data for title avoids default "Click to enter axis title"
330
- const label = striptags ( ax . _input . title || ax . _id ) ;
331
- options [ i ] = { label, value : ax . _id } ;
347
+ if ( ax . _id . charAt ( 0 ) === refAxis ) {
348
+ // checking user data for title avoids default "Click to enter axis title"
349
+ const label = striptags ( ax . _input . title || ax . _id ) ;
350
+ options . push ( { label, value : ax . _id } ) ;
351
+ }
332
352
}
333
353
334
354
return options ;
0 commit comments