Skip to content

Commit

Permalink
feat(radar): add ability to define max value
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Benitte authored and Raphaël Benitte committed May 30, 2018
1 parent 1f9cf69 commit 880d729
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/nivo-radar/src/Radar.js
Expand Up @@ -176,6 +176,7 @@ Radar.propTypes = {
data: PropTypes.arrayOf(PropTypes.object).isRequired,
keys: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])).isRequired,
indexBy: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.func]).isRequired,
maxValue: PropTypes.oneOfType([PropTypes.number, PropTypes.oneOf(['auto'])]).isRequired,
getIndex: PropTypes.func.isRequired, // computed
indices: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number]))
.isRequired, // computed
Expand Down Expand Up @@ -217,6 +218,8 @@ Radar.propTypes = {
}

export const RadarDefaultProps = {
maxValue: 'auto',

curve: 'linearClosed',

// border
Expand Down Expand Up @@ -262,9 +265,12 @@ const enhance = compose(
}, {}),
})),
withPropsOnChange(
['keys', 'indexBy', 'data', 'width', 'height'],
({ data, keys, width, height }) => {
const maxValue = max(data.reduce((acc, d) => [...acc, ...keys.map(key => d[key])], []))
['keys', 'indexBy', 'data', 'maxValue', 'width', 'height'],
({ data, keys, maxValue: _maxValue, width, height }) => {
const maxValue =
_maxValue !== 'auto'
? _maxValue
: max(data.reduce((acc, d) => [...acc, ...keys.map(key => d[key])], []))

const radius = Math.min(width, height) / 2
const radiusScale = scaleLinear()
Expand Down
2 changes: 2 additions & 0 deletions website/src/components/charts/radar/Radar.js
Expand Up @@ -30,6 +30,8 @@ export default class Radar extends Component {

state = {
settings: {
maxValue: 'auto',

margin: {
top: 70,
right: 80,
Expand Down
16 changes: 16 additions & 0 deletions website/src/components/charts/radar/props.js
Expand Up @@ -66,6 +66,22 @@ export default [
required: false,
default: defaults.keys,
},
{
key: 'maxValue',
scopes: '*',
description: `Maximum value, if 'auto', will use max value from the provided data.`,
required: false,
default: defaults.maxValue,
type: '{number|string}',
controlType: 'switchableRange',
controlGroup: 'Base',
controlOptions: {
disabledValue: 'auto',
defaultValue: 200,
min: 0,
max: 1000,
},
},
{
key: 'width',
scopes: ['api'],
Expand Down

0 comments on commit 880d729

Please sign in to comment.