react-code-dataset / nivo /packages /boxplot /src /BoxPlotAnnotations.tsx
Devendra174's picture
Upload folder using huggingface_hub
1e92f2d verified
raw
history blame
829 Bytes
import { Annotation, useAnnotations } from '@nivo/annotations'
import { BoxPlotAnnotationsProps, ComputedBoxPlotSummary } from './types'
const getPosition = (boxPlot: ComputedBoxPlotSummary) => ({
x: boxPlot.x + boxPlot.width / 2,
y: boxPlot.y + boxPlot.height / 2,
})
const getDimensions = ({ width, height }: { width: number; height: number }) => ({
width,
height,
size: Math.max(width, height),
})
export const BoxPlotAnnotations = ({ boxPlots, annotations }: BoxPlotAnnotationsProps) => {
const boundAnnotations = useAnnotations({
data: boxPlots,
annotations,
getPosition,
getDimensions,
})
return (
<>
{boundAnnotations.map((annotation, i) => (
<Annotation key={i} {...annotation} />
))}
</>
)
}