Skip to content

Commit 1919f50

Browse files
authored
Merge pull request #601 from plotly/axis-names-fix
Axis names fix
2 parents 27ce988 + c093fcb commit 1919f50

File tree

7 files changed

+60
-40
lines changed

7 files changed

+60
-40
lines changed

src/components/fields/AxisCreator.js renamed to src/components/fields/AxesCreator.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
axisIdToAxisName,
1313
} from 'lib';
1414

15-
class UnconnectedNewAxisCreator extends Component {
15+
class UnconnectedAxisCreator extends Component {
1616
canAddAxis() {
1717
const currentAxisId = this.props.fullContainer[this.props.attr];
1818
const currentTraceIndex = this.props.fullContainer.index;
@@ -104,7 +104,7 @@ class UnconnectedNewAxisCreator extends Component {
104104
}
105105
}
106106

107-
UnconnectedNewAxisCreator.propTypes = {
107+
UnconnectedAxisCreator.propTypes = {
108108
attr: PropTypes.string,
109109
label: PropTypes.string,
110110
options: PropTypes.array,
@@ -114,16 +114,16 @@ UnconnectedNewAxisCreator.propTypes = {
114114
updateContainer: PropTypes.func,
115115
};
116116

117-
UnconnectedNewAxisCreator.contextTypes = {
117+
UnconnectedAxisCreator.contextTypes = {
118118
fullLayout: PropTypes.object,
119119
data: PropTypes.array,
120120
fullData: PropTypes.array,
121121
onUpdate: PropTypes.func,
122122
};
123123

124-
const ConnectedNewAxisCreator = connectToContainer(UnconnectedNewAxisCreator);
124+
const AxisCreator = connectToContainer(UnconnectedAxisCreator);
125125

126-
class AxisCreator extends Component {
126+
class UnconnectedAxesCreator extends Component {
127127
render() {
128128
const isFirstTraceOfType =
129129
this.context.data.filter(d => d.type === this.props.container.type)
@@ -148,7 +148,7 @@ class AxisCreator extends Component {
148148
if (axisType === 'cartesian') {
149149
['xaxis', 'yaxis'].forEach((type, index) => {
150150
controls.push(
151-
<ConnectedNewAxisCreator
151+
<AxisCreator
152152
key={index}
153153
attr={type}
154154
label={type.charAt(0).toUpperCase() + ' Axis'}
@@ -169,19 +169,19 @@ class AxisCreator extends Component {
169169
}
170170
}
171171

172-
AxisCreator.propTypes = {
172+
UnconnectedAxesCreator.propTypes = {
173173
container: PropTypes.object,
174174
fullContainer: PropTypes.object,
175175
};
176176

177-
AxisCreator.contextTypes = {
177+
UnconnectedAxesCreator.contextTypes = {
178178
data: PropTypes.array,
179179
fullData: PropTypes.array,
180180
fullLayout: PropTypes.object,
181181
localize: PropTypes.func,
182182
};
183183

184-
export default connectToContainer(AxisCreator, {
184+
export default connectToContainer(UnconnectedAxesCreator, {
185185
modifyPlotProps: (props, context, plotProps) => {
186186
const {data} = context;
187187
const {fullContainer} = plotProps;

src/components/fields/AxesSelector.js

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,51 @@ class AxesSelector extends Component {
1616
}
1717

1818
render() {
19-
const {axesTargetHandler, axesTarget, localize: _} = this.context;
19+
const {
20+
axesTargetHandler,
21+
axesTarget,
22+
fullLayout,
23+
localize: _,
24+
} = this.context;
2025
const {axesOptions} = this.props;
26+
const maxCharsThatFitInRadio = 27;
2127
const maxOptions = axesOptions.length > 4; // eslint-disable-line
2228

23-
if (maxOptions) {
24-
return (
25-
<Field {...this.props} label={_('Axis to Style')}>
26-
<Dropdown
27-
options={axesOptions.map(option => {
28-
if (option.value !== 'allaxes') {
29-
return {
29+
const multipleSublots =
30+
fullLayout &&
31+
fullLayout._subplots &&
32+
Object.values(fullLayout._subplots).some(s => s.length > 1);
33+
34+
const options = multipleSublots
35+
? axesOptions.map(
36+
option =>
37+
option.value === 'allaxes'
38+
? option
39+
: {
3040
label: option.title,
3141
value: option.value,
32-
};
33-
}
42+
}
43+
)
44+
: axesOptions;
3445

35-
return option;
36-
})}
37-
value={axesTarget}
38-
onChange={axesTargetHandler}
39-
clearable={false}
40-
/>
41-
</Field>
42-
);
43-
}
46+
const totalCharsInOptions =
47+
(options &&
48+
options.map(o => o.label).reduce((acc, o) => acc + o.length, 0)) ||
49+
0;
4450

45-
return (
51+
return maxOptions || totalCharsInOptions >= maxCharsThatFitInRadio ? (
52+
<Field {...this.props} label={_('Axis to Style')}>
53+
<Dropdown
54+
options={options}
55+
value={axesTarget}
56+
onChange={axesTargetHandler}
57+
clearable={false}
58+
/>
59+
</Field>
60+
) : (
4661
<Field {...this.props} center>
4762
<RadioBlocks
48-
options={axesOptions}
63+
options={options}
4964
activeOption={axesTarget}
5065
onOptionChange={axesTargetHandler}
5166
/>

src/components/fields/derived.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const AxisAnchorDropdown = connectToContainer(UnconnectedDropdown, {
4747

4848
export const AxisOverlayDropdown = connectToContainer(UnconnectedDropdown, {
4949
modifyPlotProps: (props, context, plotProps) => {
50+
const {localize: _} = context;
5051
let options = [];
5152
if (
5253
plotProps.fullContainer &&
@@ -72,13 +73,15 @@ export const AxisOverlayDropdown = connectToContainer(UnconnectedDropdown, {
7273
});
7374
}
7475

76+
options.unshift({label: _('None'), value: false});
77+
7578
// filter out the current axisID, can't overlay over itself
7679
plotProps.options = options.filter(
7780
option =>
7881
context.fullContainer && context.fullContainer._id !== option.value
7982
);
8083

81-
plotProps.clearable = true;
84+
plotProps.clearable = false;
8285
},
8386
});
8487

src/components/fields/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Text from './Text';
1616
import SymbolSelector from './SymbolSelector';
1717
import TraceSelector from './TraceSelector';
1818
import ErrorBars from './ErrorBars';
19-
import AxisCreator from './AxisCreator';
19+
import AxesCreator from './AxesCreator';
2020
import UpdateMenuButtons from './UpdateMenuButtons';
2121
import {FilterOperation, FilterValue} from './FilterOperation';
2222
import MarkerSize from './MarkerSize';
@@ -83,7 +83,7 @@ export {
8383
TextEditor,
8484
TraceOrientation,
8585
TraceSelector,
86-
AxisCreator,
86+
AxesCreator,
8787
AxisOverlayDropdown,
8888
AxisSide,
8989
UpdateMenuButtons,

src/components/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import {
3535
Text,
3636
Radio,
3737
RangesliderVisible,
38-
AxisCreator,
38+
AxesCreator,
3939
SymbolSelector,
4040
TextEditor,
4141
TraceOrientation,
@@ -130,7 +130,7 @@ export {
130130
PlotlySection,
131131
Section,
132132
SingleSidebarItem,
133-
AxisCreator,
133+
AxesCreator,
134134
SymbolSelector,
135135
TextEditor,
136136
TraceAccordion,

src/default_panels/GraphCreatePanel.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
Radio,
88
PlotlySection,
99
LayoutSection,
10-
AxisCreator,
10+
AxesCreator,
1111
TraceAccordion,
1212
TraceSelector,
1313
TextEditor,
@@ -107,7 +107,7 @@ const GraphCreatePanel = (props, {localize: _}) => {
107107
</TraceTypeSection>
108108

109109
<PlotlySection name={_('Axes to Use')}>
110-
<AxisCreator attr="fake_attr" />
110+
<AxesCreator attr="fake_attr" />
111111
</PlotlySection>
112112

113113
<PlotlySection name={_('Error Bars X')}>

src/lib/getAllAxes.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,16 @@ function getSubplotNumber(axis) {
7575
const splitSubplot = axis._subplot
7676
? axis._subplot.split(axis._axisGroup)
7777
: [];
78-
return splitSubplot[1] ? Number(splitSubplot[1]) : 0;
78+
return splitSubplot[1]
79+
? Number(splitSubplot[1])
80+
: axis._name.split('axis')[1];
7981
}
8082

8183
export function getAxisTitle(axis) {
8284
const axisType = capitalize(axis._name.split('axis')[0]);
83-
const subplotNb = getSubplotNumber(axis);
85+
const subplotNb = getSubplotNumber(axis) || 1;
8486

8587
return axis._input && axis._input.title
8688
? striptags(`${axisType}: ${axis._input.title}`)
87-
: striptags(`${axisType} ${subplotNb === 0 ? 1 : subplotNb}`);
89+
: striptags(`${axisType} ${subplotNb}`);
8890
}

0 commit comments

Comments
 (0)