Skip to content

Commit 8aa3312

Browse files
committed
Make y2 axis creation prettier // add label to axis dropdown
1 parent b865622 commit 8aa3312

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

src/components/fields/AxesSelector.js

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import PropTypes from 'prop-types';
33
import Dropdown from '../widgets/Dropdown';
44
import RadioBlocks from '../widgets/RadioBlocks';
55
import React, {Component} from 'react';
6+
import {localize} from 'lib';
67

7-
export default class AxesSelector extends Component {
8+
class AxesSelector extends Component {
89
constructor(props, context) {
910
super(props, context);
1011

@@ -17,6 +18,7 @@ export default class AxesSelector extends Component {
1718

1819
render() {
1920
const {axesTargetHandler, axesOptions, axesTarget} = this.context;
21+
const {localize: _} = this.props;
2022
const hasSecondaryAxis =
2123
axesOptions &&
2224
axesOptions.some(option => {
@@ -26,11 +28,10 @@ export default class AxesSelector extends Component {
2628
);
2729
});
2830

29-
return (
30-
<Field {...this.props} center>
31-
{hasSecondaryAxis ? (
31+
if (hasSecondaryAxis) {
32+
return (
33+
<Field {...this.props} label={_('Select axis')}>
3234
<Dropdown
33-
label={_('Select Axis')}
3435
options={axesOptions.map(option => {
3536
if (option.value !== 'allaxes') {
3637
return {
@@ -45,13 +46,17 @@ export default class AxesSelector extends Component {
4546
onChange={axesTargetHandler}
4647
clearable={false}
4748
/>
48-
) : (
49-
<RadioBlocks
50-
options={axesOptions}
51-
activeOption={axesTarget}
52-
onOptionChange={axesTargetHandler}
53-
/>
54-
)}
49+
</Field>
50+
);
51+
}
52+
53+
return (
54+
<Field {...this.props} center>
55+
<RadioBlocks
56+
options={axesOptions}
57+
activeOption={axesTarget}
58+
onOptionChange={axesTargetHandler}
59+
/>
5560
</Field>
5661
);
5762
}
@@ -63,3 +68,9 @@ AxesSelector.contextTypes = {
6368
axesTarget: PropTypes.string,
6469
fullLayout: PropTypes.object,
6570
};
71+
72+
AxesSelector.propTypes = {
73+
localize: PropTypes.func,
74+
};
75+
76+
export default localize(AxesSelector);

src/components/fields/AxisCreator.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Info from './Info';
44
import PropTypes from 'prop-types';
55
import React, {Component, Fragment} from 'react';
66
import {connectToContainer, localize, traceTypeToAxisType} from 'lib';
7+
import {EDITOR_ACTIONS} from 'lib/constants';
78
import {PlusIcon} from 'plotly-icons';
89

910
export class UnconnectedAxisCreator extends Component {
@@ -40,7 +41,17 @@ export class UnconnectedAxisCreator extends Component {
4041
label: _('Axis'),
4142
variant: 'secondary',
4243
icon: icon,
43-
onClick: () => props.updateContainer(update),
44+
onClick: () => {
45+
props.updateContainer(update);
46+
if (subplot.startsWith('yaxis')) {
47+
context.onUpdate({
48+
type: EDITOR_ACTIONS.UPDATE_LAYOUT,
49+
payload: {
50+
update: {[`${subplot}.side`]: 'right'},
51+
},
52+
});
53+
}
54+
},
4455
}}
4556
options={context.fullLayout._subplots[subplot].map(subplot => ({
4657
label: subplot,
@@ -125,6 +136,7 @@ UnconnectedAxisCreator.propTypes = {
125136
UnconnectedAxisCreator.contextTypes = {
126137
fullLayout: PropTypes.object,
127138
data: PropTypes.array,
139+
onUpdate: PropTypes.func,
128140
};
129141

130142
UnconnectedAxisCreator.plotly_editor_traits = {

0 commit comments

Comments
 (0)