Skip to content

Commit e4c2049

Browse files
Add AxesRange component to handle special visibility
When autorange=true range components are not visible
1 parent 380cc35 commit e4c2049

File tree

8 files changed

+69
-2
lines changed

8 files changed

+69
-2
lines changed

src/DefaultEditor.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, {Component} from 'react';
22
import PropTypes from 'prop-types';
33
import {
44
AxesSelector,
5+
AxesRange,
56
ColorPicker,
67
DataSelector,
78
Dropdown,
@@ -194,9 +195,29 @@ class DefaultEditor extends Component {
194195
<Numeric label={_('Size')} step={1} attr="font.size" postfix="px" />
195196
<ColorPicker label={_('Color')} attr="font.color" />
196197
</AxesFold>
198+
197199
<AxesFold name={_('Range')}>
198200
<AxesSelector />
201+
<Section name={_('Selection')}>
202+
<Radio
203+
attr="autorange"
204+
options={[
205+
{label: _('Auto'), value: true},
206+
{label: _('Custom'), value: false},
207+
]}
208+
/>
209+
<AxesRange label={_('Min')} attr="range[0]" />
210+
<AxesRange label={_('Max')} attr="range[1]" />
211+
<Radio
212+
attr="type"
213+
options={[
214+
{label: _('Linear'), value: 'linear'},
215+
{label: _('log'), value: 'log'},
216+
]}
217+
/>
218+
</Section>
199219
</AxesFold>
220+
200221
<AxesFold name={_('Lines')}>
201222
<AxesSelector />
202223
</AxesFold>

src/components/containers/Section.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Section extends Component {
4646

4747
const isAttr = Boolean(child.props.attr);
4848
const plotProps = isAttr
49-
? unpackPlotProps(child.props, context, child.constructor)
49+
? unpackPlotProps(child.props, context, child.type)
5050
: {isVisible: true};
5151
const childProps = Object.assign({plotProps}, child.props);
5252
childProps.key = i;

src/components/fields/AxesRange.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Numeric from './Numeric';
2+
import React, {Component} from 'react';
3+
import {connectToContainer} from '../../lib';
4+
5+
class AxesRange extends Component {
6+
static modifyPlotProps(props, context, plotProps) {
7+
if (!plotProps.isVisible) {
8+
return;
9+
}
10+
const {fullContainer} = plotProps;
11+
if (fullContainer && fullContainer.autorange) {
12+
plotProps.isVisible = false;
13+
}
14+
}
15+
16+
render() {
17+
return <Numeric {...this.props} />;
18+
}
19+
}
20+
21+
AxesRange.propTypes = {
22+
...Numeric.propTypes,
23+
};
24+
25+
AxesRange.defaultProps = {
26+
showArrows: false,
27+
};
28+
29+
export default connectToContainer(AxesRange);

src/components/fields/Numeric.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Numeric extends Component {
1616
max={this.props.max}
1717
onChange={this.props.updatePlot}
1818
onUpdate={this.props.updatePlot}
19-
showArrows
19+
showArrows={this.props.showArrows}
2020
/>
2121
</Field>
2222
);
@@ -28,9 +28,14 @@ Numeric.propTypes = {
2828
fullValue: PropTypes.func,
2929
min: PropTypes.number,
3030
max: PropTypes.number,
31+
showArrows: PropTypes.number,
3132
step: PropTypes.number,
3233
updatePlot: PropTypes.func,
3334
...Field.propTypes,
3435
};
3536

37+
Numeric.defaultProps = {
38+
showArrows: true,
39+
};
40+
3641
export default connectToContainer(Numeric);

src/components/fields/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import AxesRange from './AxesRange';
12
import AxesSelector from './AxesSelector';
23
import ColorPicker from './Color';
34
import Dropdown from './Dropdown';
@@ -9,6 +10,7 @@ import Numeric from './Numeric';
910
import TraceSelector from './TraceSelector';
1011

1112
export {
13+
AxesRange,
1214
AxesSelector,
1315
ColorPicker,
1416
Dropdown,

src/components/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
AxesRange,
23
AxesSelector,
34
ColorPicker,
45
Dropdown,
@@ -15,6 +16,7 @@ import PanelMenuWrapper from './PanelMenuWrapper';
1516

1617
export {
1718
AxesSelector,
19+
AxesRange,
1820
SubPanel,
1921
ColorPicker,
2022
DataSelector,

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import {EDITOR_ACTIONS} from './constants';
1111

1212
import {
13+
AxesRange,
1314
AxesSelector,
1415
SubPanel,
1516
ColorPicker,
@@ -29,6 +30,7 @@ import {
2930
} from './components';
3031

3132
export {
33+
AxesRange,
3234
AxesSelector,
3335
SubPanel,
3436
ColorPicker,

src/lib/connectToContainer.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ import {getDisplayName} from '../lib';
55

66
export default function connectToContainer(WrappedComponent) {
77
class ContainerConnectedComponent extends Component {
8+
static modifyPlotProps(props, context, plotProps) {
9+
if (WrappedComponent.modifyPlotProps) {
10+
WrappedComponent.modifyPlotProps(props, context, plotProps);
11+
}
12+
}
13+
814
constructor(props, context) {
915
super(props, context);
1016

0 commit comments

Comments
 (0)