File size: 1,627 Bytes
1e92f2d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | import { useComputedAnnotation } from './hooks'
import { AnnotationNote } from './AnnotationNote'
import { AnnotationLink } from './AnnotationLink'
import { CircleAnnotationOutline } from './CircleAnnotationOutline'
import { DotAnnotationOutline } from './DotAnnotationOutline'
import { RectAnnotationOutline } from './RectAnnotationOutline'
import { BoundAnnotation } from './types'
import { isCircleAnnotation, isDotAnnotation, isRectAnnotation, isSvgNote } from './utils'
export const Annotation = <Datum,>(annotation: BoundAnnotation<Datum>) => {
const { datum, x, y, note } = annotation
const computed = useComputedAnnotation(annotation)
if (!isSvgNote(note)) {
throw new Error('note should be a valid react element')
}
return (
<>
<AnnotationLink points={computed.points} isOutline={true} />
{isCircleAnnotation(annotation) && (
<CircleAnnotationOutline x={x} y={y} size={annotation.size} />
)}
{isDotAnnotation(annotation) && (
<DotAnnotationOutline x={x} y={y} size={annotation.size} />
)}
{isRectAnnotation(annotation) && (
<RectAnnotationOutline
x={x}
y={y}
width={annotation.width}
height={annotation.height}
borderRadius={annotation.borderRadius}
/>
)}
<AnnotationLink points={computed.points} />
<AnnotationNote datum={datum} x={computed.text[0]} y={computed.text[1]} note={note} />
</>
)
}
|