File size: 1,146 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
import {
    AnnotationSpec,
    CircleAnnotationSpec,
    DotAnnotationSpec,
    Note,
    NoteCanvas,
    NoteSvg,
    RectAnnotationSpec,
} from './types'
import { isValidElement } from 'react'

export const isSvgNote = <Datum>(note: Note<Datum>): note is NoteSvg<Datum> => {
    const noteType = typeof note

    return (
        isValidElement(note) ||
        noteType === 'string' ||
        noteType === 'function' ||
        noteType === 'object'
    )
}

export const isCanvasNote = <Datum>(note: Note<Datum>): note is NoteCanvas<Datum> => {
    const noteType = typeof note

    return noteType === 'string' || noteType === 'function'
}

export const isCircleAnnotation = <Datum>(
    annotationSpec: AnnotationSpec<Datum>
): annotationSpec is CircleAnnotationSpec<Datum> => annotationSpec.type === 'circle'

export const isDotAnnotation = <Datum>(
    annotationSpec: AnnotationSpec<Datum>
): annotationSpec is DotAnnotationSpec<Datum> => annotationSpec.type === 'dot'

export const isRectAnnotation = <Datum>(
    annotationSpec: AnnotationSpec<Datum>
): annotationSpec is RectAnnotationSpec<Datum> => annotationSpec.type === 'rect'