Skip to content

Commit

Permalink
feat(bar): add ability to define grid values
Browse files Browse the repository at this point in the history
* added `xValues` and `yValues` props to `Grid`

* added `gridXValues` and `gridYValues` props to Bar component

* fmt fix
  • Loading branch information
Peter Göbel authored and Raphaël Benitte committed Jun 4, 2018
1 parent 8f22f89 commit afd1ee3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/nivo-bar/src/Bar.js
Expand Up @@ -72,6 +72,8 @@ const Bar = ({
axisLeft,
enableGridX,
enableGridY,
gridXValues,
gridYValues,

// customization
barComponent,
Expand Down Expand Up @@ -249,6 +251,8 @@ const Bar = ({
height={height}
xScale={enableGridX ? result.xScale : null}
yScale={enableGridY ? result.yScale : null}
xValues={gridXValues}
yValues={gridYValues}
{...motionProps}
/>
<Axes
Expand Down
2 changes: 2 additions & 0 deletions packages/nivo-bar/src/props.js
Expand Up @@ -35,6 +35,8 @@ export const BarPropTypes = {
axisLeft: PropTypes.object,
enableGridX: PropTypes.bool.isRequired,
enableGridY: PropTypes.bool.isRequired,
gridXValues: PropTypes.arrayOf(PropTypes.number),
gridYValues: PropTypes.arrayOf(PropTypes.number),

// customization
barComponent: PropTypes.func.isRequired,
Expand Down
6 changes: 6 additions & 0 deletions packages/nivo-core/src/components/axes/Grid.js
Expand Up @@ -19,6 +19,8 @@ const Grid = ({
height,
xScale,
yScale,
xValues,
yValues,
theme,
animate,
motionStiffness,
Expand All @@ -30,6 +32,7 @@ const Grid = ({
height,
scale: xScale,
axis: 'x',
values: xValues,
})
: false

Expand All @@ -39,6 +42,7 @@ const Grid = ({
height,
scale: yScale,
axis: 'y',
values: yValues,
})
: false

Expand Down Expand Up @@ -74,6 +78,8 @@ Grid.propTypes = {

xScale: PropTypes.func,
yScale: PropTypes.func,
xValues: PropTypes.arrayOf(PropTypes.number),
yValues: PropTypes.arrayOf(PropTypes.number),

theme: PropTypes.object.isRequired,

Expand Down
10 changes: 7 additions & 3 deletions packages/nivo-core/src/lib/cartesian/axes.js
Expand Up @@ -162,9 +162,13 @@ export const computeAxisTicks = ({
*
* @return {Array.<Object>}
*/
export const computeGridLines = ({ width, height, scale, axis }) => {
const values = getScaleValues(scale)

export const computeGridLines = ({
width,
height,
scale,
axis,
values = getScaleValues(scale),
}) => {
const position = scale.bandwidth ? centerScale(scale) : scale

let lines
Expand Down

0 comments on commit afd1ee3

Please sign in to comment.