Skip to content

Commit

Permalink
feat(bump): pass original datum to each point
Browse files Browse the repository at this point in the history
  • Loading branch information
plouc committed Dec 13, 2019
1 parent b29fed2 commit b4c739d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/bump/src/bump/Point.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const Point = ({ x, y, size, color, borderColor, borderWidth }) => {
}

Point.propTypes = {
data: PropTypes.object.isRequired,
x: PropTypes.number.isRequired,
y: PropTypes.number.isRequired,
size: PropTypes.number.isRequired,
Expand Down
5 changes: 3 additions & 2 deletions packages/bump/src/bump/Points.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ import PropTypes from 'prop-types'
import { TransitionMotion, spring } from 'react-motion'
import { useMotionConfig } from '@nivo/core'

const pointStyle = { pointerEvents: 'none' }

const Points = ({ pointComponent, points }) => {
const { animate, springConfig } = useMotionConfig()

if (!animate) {
return points.map(point => {
return React.createElement(pointComponent, {
key: point.id,
data: point.data,
x: point.x,
y: point.y,
size: point.style.size,
Expand Down Expand Up @@ -48,6 +47,7 @@ const Points = ({ pointComponent, points }) => {
{interpolated.map(({ key, style, data: point }) => {
return React.createElement(pointComponent, {
key,
data: point.data,
x: style.x,
y: point.y,
size: Math.max(style.size, 0),
Expand All @@ -67,6 +67,7 @@ Points.propTypes = {
points: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.string.isRequired,
data: PropTypes.object.isRequired,
x: PropTypes.number.isRequired,
y: PropTypes.number.isRequired,
color: PropTypes.string.isRequired,
Expand Down
2 changes: 1 addition & 1 deletion packages/bump/src/bump/compute.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ export const computeSeries = ({ width, height, data, xPadding, xOuterPadding, yO

rawSerie.data.forEach((datum, i) => {
const point = {
...datum,
id: `${rawSerie.id}.${datum.x}`,
x: xScale(datum.x),
y: yScale(datum.y),
serie: rawSerie,
data: datum,
}
serie.points.push(point)

Expand Down
1 change: 1 addition & 0 deletions packages/bump/stories/bump.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const generateData = () => {
series[i].data.push({
x: year,
y: rank,
extra: Math.random(),
})
})
})
Expand Down

0 comments on commit b4c739d

Please sign in to comment.