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