Skip to content

Commit 27fb582

Browse files
committed
Correct annotation axesref
1 parent 7775095 commit 27fb582

File tree

2 files changed

+51
-29
lines changed

2 files changed

+51
-29
lines changed

src/components/fields/derived.js

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
capitalize,
88
connectLayoutToPlot,
99
connectToContainer,
10+
getAllAxes,
1011
supplyLayoutPlotProps,
1112
striptags,
1213
} from 'lib';
@@ -196,7 +197,7 @@ export const LayoutNumericFractionInverse = connectLayoutToPlot(
196197

197198
export const AnnotationArrowRef = connectToContainer(UnconnectedDropdown, {
198199
modifyPlotProps: (props, context, plotProps) => {
199-
const {fullContainer: {xref, yref}, plotly, graphDiv} = context;
200+
const {fullContainer: {xref, yref}} = context;
200201

201202
let currentAxisRef;
202203
if (props.attr === 'axref') {
@@ -212,12 +213,19 @@ export const AnnotationArrowRef = connectToContainer(UnconnectedDropdown, {
212213

213214
if (currentAxisRef === 'paper') {
214215
// 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+
}
221229
} else {
222230
// If currentAxesRef is an actual axes then offer that value as the only
223231
// axes option.
@@ -233,7 +241,7 @@ export const AnnotationArrowRef = connectToContainer(UnconnectedDropdown, {
233241

234242
export const AnnotationRef = connectToContainer(UnconnectedDropdown, {
235243
modifyPlotProps: (props, context, plotProps) => {
236-
const {fullContainer: {axref, ayref}, graphDiv, plotly} = context;
244+
const {fullContainer: {axref, ayref}} = context;
237245

238246
let currentOffsetRef;
239247
if (props.attr === 'xref') {
@@ -247,12 +255,19 @@ export const AnnotationRef = connectToContainer(UnconnectedDropdown, {
247255
);
248256
}
249257

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+
}
256271

257272
if (currentOffsetRef !== 'pixel') {
258273
plotProps.updatePlot = v => {
@@ -280,15 +295,19 @@ export const AnnotationRef = connectToContainer(UnconnectedDropdown, {
280295

281296
export const PositioningRef = connectToContainer(UnconnectedDropdown, {
282297
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+
}
291304

305+
if (props.attr === 'yref') {
306+
plotProps.options = [
307+
{label: 'Canvas', value: 'paper'},
308+
...computeAxesRefOptions(getAllAxes(context.fullLayout), 'y'),
309+
];
310+
}
292311
plotProps.clearable = false;
293312
},
294313
});
@@ -321,14 +340,15 @@ export const PositioningNumeric = connectToContainer(UnconnectedNumeric, {
321340
},
322341
});
323342

324-
function computeAxesRefOptions(axes) {
343+
function computeAxesRefOptions(axes, refAxis) {
325344
const options = [];
326345
for (let i = 0; i < axes.length; i++) {
327346
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+
}
332352
}
333353

334354
return options;

src/lib/connectAxesToLayout.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ function computeAxesOptions(axes, _) {
2121
? ax.subplot + '.' + ax._name
2222
: ax.subplot
2323
).trim();
24-
const axisTitle = !ax.title.startsWith('Click') ? ax.title : null;
24+
2525
options[i + 1] = {
2626
label,
2727
value,
2828
axisGroup: ax.axisGroup,
2929
title: striptags(
30-
axisTitle ? `${label} Axis: ${axisTitle}` : capitalize(ax._id)
30+
ax._input.title
31+
? `${label} Axis: ${ax._input.title}`
32+
: capitalize(ax._id)
3133
),
3234
};
3335
}

0 commit comments

Comments
 (0)