[explore] adding y_axis_bounds to force Y axis bounds (#2878)

* [explore] adding y_axis_bounds to force Y axis

* Handling comments
This commit is contained in:
Maxime Beauchemin
2017-05-31 14:47:09 -07:00
committed by GitHub
parent c5f2eafc90
commit e300273e71
9 changed files with 209 additions and 42 deletions

View File

@@ -8,6 +8,7 @@ import SelectControl from './controls/SelectControl';
import TextAreaControl from './controls/TextAreaControl';
import TextControl from './controls/TextControl';
import VizTypeControl from './controls/VizTypeControl';
import BoundsControl from './controls/BoundsControl';
const controlMap = {
CheckboxControl,
@@ -17,6 +18,7 @@ const controlMap = {
TextAreaControl,
TextControl,
VizTypeControl,
BoundsControl,
};
const controlTypes = Object.keys(controlMap);

View File

@@ -19,7 +19,6 @@ const propTypes = {
controls: PropTypes.object.isRequired,
form_data: PropTypes.object.isRequired,
isDatasourceMetaLoading: PropTypes.bool.isRequired,
y_axis_zero: PropTypes.any,
};
class ControlPanelsContainer extends React.Component {
@@ -65,14 +64,15 @@ class ControlPanelsContainer extends React.Component {
<ControlRow
key={`controlsetrow-${i}`}
controls={controlSets.map(controlName => (
<Control
name={controlName}
key={`control-${controlName}`}
value={this.props.form_data[controlName]}
validationErrors={this.props.controls[controlName].validationErrors}
actions={this.props.actions}
{...this.getControlData(controlName)}
/>
controlName &&
<Control
name={controlName}
key={`control-${controlName}`}
value={this.props.form_data[controlName]}
validationErrors={this.props.controls[controlName].validationErrors}
actions={this.props.actions}
{...this.getControlData(controlName)}
/>
))}
/>
))}

View File

@@ -0,0 +1,95 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Col, Row, FormGroup, FormControl } from 'react-bootstrap';
import ControlHeader from '../ControlHeader';
const propTypes = {
name: PropTypes.string.isRequired,
label: PropTypes.string,
description: PropTypes.string,
onChange: PropTypes.func,
value: PropTypes.array,
};
const defaultProps = {
label: null,
description: null,
onChange: () => {},
value: [null, null],
};
export default class BoundsControl extends React.Component {
constructor(props) {
super(props);
this.state = {
minMax: [
props.value[0] === null ? '' : props.value[0],
props.value[1] === null ? '' : props.value[1],
],
};
this.onChange = this.onChange.bind(this);
this.onMinChange = this.onMinChange.bind(this);
this.onMaxChange = this.onMaxChange.bind(this);
}
onMinChange(event) {
this.setState({
minMax: [
event.target.value,
this.state.minMax[1],
],
}, this.onChange);
}
onMaxChange(event) {
this.setState({
minMax: [
this.state.minMax[0],
event.target.value,
],
}, this.onChange);
}
onChange() {
const mm = this.state.minMax;
const errors = [];
if (mm[0] && isNaN(mm[0])) {
errors.push('`Min` value should be numeric or empty');
}
if (mm[1] && isNaN(mm[1])) {
errors.push('`Max` value should be numeric or empty');
}
if (errors.length === 0) {
this.props.onChange([parseFloat(mm[0]), parseFloat(mm[1])], errors);
} else {
this.props.onChange([null, null], errors);
}
}
render() {
return (
<div>
<ControlHeader {...this.props} />
<FormGroup bsSize="small">
<Row>
<Col xs={6}>
<FormControl
type="text"
placeholder="Min"
onChange={this.onMinChange}
value={this.state.minMax[0]}
/>
</Col>
<Col xs={6}>
<FormControl
type="text"
placeholder="Max"
onChange={this.onMaxChange}
value={this.state.minMax[1]}
/>
</Col>
</Row>
</FormGroup>
</div>
);
}
}
BoundsControl.propTypes = propTypes;
BoundsControl.defaultProps = defaultProps;

View File

@@ -63,7 +63,7 @@ export default class VizTypeControl extends React.PureComponent {
const rows = [];
for (let i = 0; i <= filteredVizTypes.length; i += imgPerRow) {
rows.push(
<Row>
<Row key={`row-${i}`}>
{filteredVizTypes.slice(i, i + imgPerRow).map(vt => (
<Col md={3} key={`grid-col-${vt}`}>
{this.renderVizType(vt)}