Skip to content

Commit

Permalink
feat(line): restore ability to animate line & line area
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Benitte committed Dec 12, 2017
1 parent da5c6fb commit d517c52
Show file tree
Hide file tree
Showing 25 changed files with 322 additions and 237 deletions.
27 changes: 0 additions & 27 deletions packages/nivo-line/src/Line.js

This file was deleted.

26 changes: 0 additions & 26 deletions packages/nivo-line/src/LineArea.js

This file was deleted.

77 changes: 0 additions & 77 deletions packages/nivo-line/src/_LineAreas.js

This file was deleted.

76 changes: 0 additions & 76 deletions packages/nivo-line/src/_LineLines.js

This file was deleted.

10 changes: 10 additions & 0 deletions packages/nivo-line/src/canvas/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* This file is part of the nivo project.
*
* Copyright 2016-present, Raphaël Benitte.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
export { default as LineCanvas } from './LineCanvas'
export { default as LineAreaCanvas } from './LineAreaCanvas'
11 changes: 2 additions & 9 deletions packages/nivo-line/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,9 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
export { default as ResponsiveLine } from './ResponsiveLine'
export * from './props'
export { default as Scales } from './Scales'
export { default as LinearScaleX } from './LinearScaleX'
export { default as LinearScaleY } from './LinearScaleY'
export { default as Lines } from './Lines'
export { default as Line } from './Line'
export { default as LineAreas } from './LineAreas'
export { default as LineArea } from './LineArea'

export { default as CanvasWrapper } from './canvas/CanvasWrapper'
export { default as LineCanvas } from './canvas/LineCanvas'
export { default as LineAreaCanvas } from './canvas/LineAreaCanvas'
export * from './svg'
export * from './canvas'
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
79 changes: 79 additions & 0 deletions packages/nivo-line/src/svg/LineAreaSvg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* This file is part of the nivo project.
*
* Copyright 2016-present, Raphaël Benitte.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import React from 'react'
import PropTypes from 'prop-types'
import pure from 'recompose/pure'
import {
SmartMotion,
motionPropTypes,
defaultAnimate,
defaultMotionDamping,
defaultMotionStiffness,
} from '@nivo/core'

const LineArea = ({
data,
generator,
xScale,
yScale,
animate,
motionDamping,
motionStiffness,
...props
}) => {
const pathDef = generator(
data.map(d => ({
x: d.x !== null ? xScale(d.x) : null,
y: d.y !== null ? yScale(d.y) : null,
}))
)

if (animate !== true) {
return <path d={pathDef} fill="rgba(0, 0, 0, 0.2)" {...props} />
}

const springConfig = {
stiffness: motionStiffness,
damping: motionDamping,
}

return (
<SmartMotion
style={spring => ({
d: spring(pathDef, springConfig),
})}
>
{style => <path d={style.d} fill="rgba(0, 0, 0, 0.2)" {...props} />}
</SmartMotion>
)
}

LineArea.propTypes = {
data: PropTypes.arrayOf(
PropTypes.shape({
x: PropTypes.number,
y: PropTypes.number,
})
),
generator: PropTypes.func.isRequired,
xScale: PropTypes.func.isRequired,
yScale: PropTypes.func.isRequired,

// motion
...motionPropTypes,
}

LineArea.defaultProps = {
// motion
animate: defaultAnimate,
motionDamping: defaultMotionDamping,
motionStiffness: defaultMotionStiffness,
}

export default pure(LineArea)
Loading

0 comments on commit d517c52

Please sign in to comment.