Skip to content

Commit

Permalink
fix(annotations): switch to useAnimatedPath hook
Browse files Browse the repository at this point in the history
  • Loading branch information
wyze committed Oct 22, 2020
1 parent 6d2cd27 commit 6c8b767
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions packages/annotations/src/AnnotationLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,15 @@
*/
import React, { memo } from 'react'
import PropTypes from 'prop-types'
import { useSpring, animated } from 'react-spring'
import { useTheme, useMotionConfig } from '@nivo/core'
import { animated } from 'react-spring'
import { useAnimatedPath, useTheme } from '@nivo/core'

const AnnotationLink = memo(({ points, isOutline }) => {
const AnnotationLink = memo(({ isOutline, ...props }) => {
const theme = useTheme()
const [point, ...points] = props.points

let path = `M${points[0][0]},${points[0][1]}`
points.slice(1).forEach(point => {
path = `${path} L${point[0]},${point[1]}`
})

const { animate, config: springConfig } = useMotionConfig()
const animatedProps = useSpring({
path,
config: springConfig,
immediate: !animate,
})
const path = points.reduce((acc, [x, y]) => `${acc} L${x},${y}`, `M${point[0]},${point[1]}`)
const animatedPath = useAnimatedPath(path)

if (isOutline && theme.annotations.link.outlineWidth <= 0) {
return null
Expand All @@ -38,7 +30,7 @@ const AnnotationLink = memo(({ points, isOutline }) => {
style.stroke = theme.annotations.link.outlineColor
}

return <animated.path fill="none" d={animatedProps.path} style={style} />
return <animated.path fill="none" d={animatedPath} style={style} />
})

AnnotationLink.displayName = 'AnnotationLink'
Expand Down

0 comments on commit 6c8b767

Please sign in to comment.