Skip to content

Commit

Permalink
feat(line): add support for gridXValues and gridYValues (#391)
Browse files Browse the repository at this point in the history
* Add number support to gridXValues and gridYValues
* Add Date instance acceptance to line grid values
* Add prop types of Date for array in generic Grid component
  • Loading branch information
jasonwells authored and Raphaël Benitte committed Jan 24, 2019
1 parent 95dd060 commit fd49e83
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
14 changes: 12 additions & 2 deletions packages/core/src/components/axes/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,18 @@ Grid.propTypes = {

xScale: PropTypes.func,
yScale: PropTypes.func,
xValues: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string])),
yValues: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string])),
xValues: PropTypes.oneOfType([
PropTypes.number,
PropTypes.arrayOf(
PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.instanceOf(Date)])
),
]),
yValues: PropTypes.oneOfType([
PropTypes.number,
PropTypes.arrayOf(
PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.instanceOf(Date)])
),
]),

theme: PropTypes.object.isRequired,

Expand Down
13 changes: 6 additions & 7 deletions packages/core/src/lib/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,12 @@ export const computeAxisTicks = ({
*
* @return {Array.<Object>}
*/
export const computeGridLines = ({
width,
height,
scale,
axis,
values = getScaleValues(scale),
}) => {
export const computeGridLines = ({ width, height, scale, axis, values: _values }) => {
const gridValues = isArray(_values) ? _values : undefined
const gridCount = isNumber(_values) ? _values : undefined

const values = gridValues || getScaleValues(scale, gridCount)

const position = scale.bandwidth ? centerScale(scale) : scale

let lines
Expand Down
14 changes: 12 additions & 2 deletions packages/line/src/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,18 @@ export const LinePropTypes = {

enableGridX: PropTypes.bool.isRequired,
enableGridY: PropTypes.bool.isRequired,
gridXValues: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string])),
gridYValues: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string])),
gridXValues: PropTypes.oneOfType([
PropTypes.number,
PropTypes.arrayOf(
PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.instanceOf(Date)])
),
]),
gridYValues: PropTypes.oneOfType([
PropTypes.number,
PropTypes.arrayOf(
PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.instanceOf(Date)])
),
]),

enableDots: PropTypes.bool.isRequired,
dotSymbol: PropTypes.func,
Expand Down

0 comments on commit fd49e83

Please sign in to comment.