Skip to content

Commit 0a6a533

Browse files
committed
Correct axis selector axis names and display
1 parent 37961be commit 0a6a533

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

src/components/fields/AxesSelector.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,29 @@ export default class AxesSelector extends Component {
1717

1818
render() {
1919
const {axesTargetHandler, axesOptions, axesTarget} = this.context;
20+
const hasSecondaryAxis =
21+
axesOptions &&
22+
axesOptions.some(option => {
23+
return (
24+
option.axisGroup &&
25+
this.context.fullLayout._subplots[option.axisGroup].length > 1
26+
);
27+
});
2028

2129
return (
2230
<Field {...this.props} center>
23-
{axesOptions.length > 4 ? ( // eslint-disable-line no-magic-numbers
31+
{hasSecondaryAxis ? (
2432
<Dropdown
25-
options={axesOptions}
33+
options={axesOptions.map(option => {
34+
if (option.value !== 'allaxes') {
35+
return {
36+
label: option.title,
37+
value: option.value,
38+
};
39+
}
40+
41+
return option;
42+
})}
2643
value={axesTarget}
2744
onChange={axesTargetHandler}
2845
clearable={false}
@@ -43,4 +60,5 @@ AxesSelector.contextTypes = {
4360
axesTargetHandler: PropTypes.func,
4461
axesOptions: PropTypes.array,
4562
axesTarget: PropTypes.string,
63+
fullLayout: PropTypes.object,
4664
};

src/lib/connectAxesToLayout.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import React, {Component} from 'react';
22
import PropTypes from 'prop-types';
33
import nestedProperty from 'plotly.js/src/lib/nested_property';
44
import {deepCopyPublic, setMultiValuedContainer} from './multiValues';
5-
import {capitalize, getAllAxes, getDisplayName, localize} from '../lib';
5+
import {
6+
capitalize,
7+
getAllAxes,
8+
getDisplayName,
9+
localize,
10+
striptags,
11+
} from '../lib';
612

713
function computeAxesOptions(axes, _) {
814
const options = [{label: _('All'), value: 'allaxes'}];
@@ -15,7 +21,15 @@ function computeAxesOptions(axes, _) {
1521
? ax.subplot + '.' + ax._name
1622
: ax.subplot
1723
).trim();
18-
options[i + 1] = {label, value};
24+
const axisTitle = !ax.title.startsWith('Click') ? ax.title : null;
25+
options[i + 1] = {
26+
label,
27+
value,
28+
axisGroup: ax.axisGroup,
29+
title: striptags(
30+
axisTitle ? `${label} Axis: ${axisTitle}` : capitalize(ax._id)
31+
),
32+
};
1933
}
2034

2135
return options;

src/lib/getAllAxes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ export default function getAllAxes(fullLayout) {
1919
: subplot + 'axis';
2020

2121
fullLayout[subplot].subplot = subplot;
22+
fullLayout[subplot].axisGroup = type;
2223
axes.push(fullLayout[subplot]);
2324
} else {
2425
Object.keys(fullLayout[subplot])
2526
.filter(key => key.includes('axis'))
2627
.forEach(axis => {
2728
fullLayout[subplot][axis].subplot = subplot;
29+
fullLayout[subplot][axis].axisGroup = type;
2830

2931
// it should be in plotly.js, but it's not there for geo axes..
3032
if (!fullLayout[subplot][axis]._name) {

0 commit comments

Comments
 (0)