Devendra174's picture
Upload folder using huggingface_hub
1e92f2d verified
raw
history blame
1.58 kB
import { createElement } from 'react'
import omit from 'lodash/omit.js'
import { useSpring, animated } from '@react-spring/web'
import { useMotionConfig } from '@nivo/core'
import { useTheme } from '@nivo/theming'
import { NoteSvg } from './types'
export const AnnotationNote = <Datum,>({
datum,
x,
y,
note,
}: {
datum: Datum
x: number
y: number
note: NoteSvg<Datum>
}) => {
const theme = useTheme()
const { animate, config: springConfig } = useMotionConfig()
const animatedProps = useSpring({
x,
y,
config: springConfig,
immediate: !animate,
})
if (typeof note === 'function') {
return createElement(note, { x, y, datum })
}
return (
<>
{theme.annotations.text.outlineWidth > 0 && (
<animated.text
x={animatedProps.x}
y={animatedProps.y}
style={{
...theme.annotations.text,
strokeLinejoin: 'round',
strokeWidth: theme.annotations.text.outlineWidth * 2,
stroke: theme.annotations.text.outlineColor,
}}
>
{note}
</animated.text>
)}
<animated.text
x={animatedProps.x}
y={animatedProps.y}
style={omit(theme.annotations.text, ['outlineWidth', 'outlineColor'])}
>
{note}
</animated.text>
</>
)
}