Skip to content

Commit 8162f72

Browse files
committed
Correct annotation axesref
1 parent 21ad5b0 commit 8162f72

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';
@@ -195,7 +196,7 @@ export const LayoutNumericFraction = connectLayoutToPlot(
195196

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

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

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

233241
export const AnnotationRef = connectToContainer(UnconnectedDropdown, {
234242
modifyPlotProps: (props, context, plotProps) => {
235-
const {fullContainer: {axref, ayref}, graphDiv, plotly} = context;
243+
const {fullContainer: {axref, ayref}} = context;
236244

237245
let currentOffsetRef;
238246
if (props.attr === 'xref') {
@@ -246,12 +254,19 @@ export const AnnotationRef = connectToContainer(UnconnectedDropdown, {
246254
);
247255
}
248256

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

256271
if (currentOffsetRef !== 'pixel') {
257272
plotProps.updatePlot = v => {
@@ -279,27 +294,32 @@ export const AnnotationRef = connectToContainer(UnconnectedDropdown, {
279294

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

304+
if (props.attr === 'yref') {
305+
plotProps.options = [
306+
{label: 'Canvas', value: 'paper'},
307+
...computeAxesRefOptions(getAllAxes(context.fullLayout), 'y'),
308+
];
309+
}
291310
plotProps.clearable = false;
292311
},
293312
});
294313

295-
function computeAxesRefOptions(axes) {
314+
function computeAxesRefOptions(axes, refAxis) {
296315
const options = [];
297316
for (let i = 0; i < axes.length; i++) {
298317
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+
}
303323
}
304324

305325
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)