Skip to content

Commit

Permalink
feat(axis): improve axis formatting support
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Benitte committed Sep 5, 2017
1 parent 98c0199 commit 69269a6
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/components/axes/Axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
*/
import React from 'react'
import PropTypes from 'prop-types'
import { isFunction } from 'lodash'
import { format as d3Format } from 'd3-format'
import compose from 'recompose/compose'
import withPropsOnChange from 'recompose/withPropsOnChange'
import pure from 'recompose/pure'
import { TransitionMotion, spring } from 'react-motion'
import { withMotion } from '../../hocs'
Expand Down Expand Up @@ -214,7 +217,7 @@ Axis.propTypes = {
tickSize: PropTypes.number.isRequired,
tickPadding: PropTypes.number.isRequired,
tickRotation: PropTypes.number.isRequired,
format: PropTypes.func,
format: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),

// legend
legend: PropTypes.string,
Expand All @@ -236,6 +239,13 @@ Axis.defaultProps = {
legendOffset: 0,
}

const enhance = compose(withMotion(), pure)
const enhance = compose(
withMotion(),
withPropsOnChange(['format'], ({ format }) => {
if (!format || isFunction(format)) return { format }
return { format: d3Format(format) }
}),
pure
)

export default enhance(Axis)

0 comments on commit 69269a6

Please sign in to comment.