diff --git a/client/app/visualizations/chart/Editor/AxisSettings.jsx b/client/app/visualizations/chart/Editor/AxisSettings.jsx new file mode 100644 index 0000000000..45af149f64 --- /dev/null +++ b/client/app/visualizations/chart/Editor/AxisSettings.jsx @@ -0,0 +1,104 @@ +import { isString, isObject, isFinite, isNumber, merge } from 'lodash'; +import React from 'react'; +import PropTypes from 'prop-types'; +import Select from 'antd/lib/select'; +import Input from 'antd/lib/input'; +import InputNumber from 'antd/lib/input-number'; +import * as Grid from 'antd/lib/grid'; + +function toNumber(value) { + value = isNumber(value) ? value : parseFloat(value); + return isFinite(value) ? value : null; +} + +export default function AxisSettings({ id, options, features, onChange }) { + function optionsChanged(newOptions) { + onChange(merge({}, options, newOptions)); + } + + function handleNameChange(event) { + const text = event.target.value; + const title = isString(text) && (text !== '') ? { text } : null; + optionsChanged({ title }); + } + + return ( + +
+ + +
+ +
+ + +
+ + {features.range && ( + + + + optionsChanged({ rangeMin: toNumber(value) })} + /> + + + + optionsChanged({ rangeMax: toNumber(value) })} + /> + + + )} +
+ ); +} + +AxisSettings.propTypes = { + id: PropTypes.string.isRequired, + options: PropTypes.shape({ + type: PropTypes.string.isRequired, + title: PropTypes.shape({ + text: PropTypes.string, + }), + rangeMin: PropTypes.number, + rangeMax: PropTypes.number, + }).isRequired, + features: PropTypes.shape({ + autoDetectType: PropTypes.bool, + range: PropTypes.bool, + }), + onChange: PropTypes.func, +}; + +AxisSettings.defaultProps = { + features: {}, + onChange: () => {}, +}; diff --git a/client/app/visualizations/chart/Editor/XAxisSettings.jsx b/client/app/visualizations/chart/Editor/XAxisSettings.jsx index 010640c442..6ad2070705 100644 --- a/client/app/visualizations/chart/Editor/XAxisSettings.jsx +++ b/client/app/visualizations/chart/Editor/XAxisSettings.jsx @@ -1,48 +1,18 @@ -import { isString, isObject } from 'lodash'; import React from 'react'; import Switch from 'antd/lib/switch'; -import Input from 'antd/lib/input'; -import Select from 'antd/lib/select'; import { EditorPropTypes } from '@/visualizations'; -export default function XAxisSettings({ options, onOptionsChange }) { - function handleNameChange(event) { - const text = event.target.value; - if (isString(text) && (text !== '')) { - onOptionsChange({ xAxis: { title: { text } } }); - } else { - onOptionsChange({ xAxis: { title: null } }); - } - } +import AxisSettings from './AxisSettings'; +export default function XAxisSettings({ options, onOptionsChange }) { return ( -
- - -
- -
- - -
+ onOptionsChange({ xAxis })} + />