/
types.ts
147 lines (124 loc) · 3.78 KB
/
types.ts
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import { FunctionComponent, AriaAttributes } from 'react'
import { AnimatedProps } from '@react-spring/web'
import {
Box,
Theme,
CssMixBlendMode,
Dimensions,
ModernMotionProps,
PropertyAccessor,
ValueFormat,
ClosedCurveFactoryId,
DotsItemSymbolComponent,
SvgDefsAndFill,
} from '@nivo/core'
import { InheritedColorConfig, OrdinalColorScaleConfig } from '@nivo/colors'
import { LegendProps } from '@nivo/legends'
import { ScaleLinear } from 'd3-scale'
export interface RadarDataProps<D extends Record<string, unknown>> {
data: D[]
keys: string[]
indexBy: PropertyAccessor<D, string>
}
export interface GridLabelProps {
id: string
anchor: 'start' | 'middle' | 'end'
angle: number
x: number
y: number
animated: AnimatedProps<{
transform: string
}>
}
export type GridLabelComponent = FunctionComponent<GridLabelProps>
export type PointData = {
index: string
key: string
value: number
formattedValue: string
color: string
}
export interface PointProps {
key: string
label: string | number | undefined
data: PointData
style: {
fill: string
stroke: string
x: number
y: number
}
}
export interface RadarSliceTooltipDatum {
color: string
id: string
value: number
formattedValue: string
}
export interface RadarSliceTooltipProps {
index: string | number
data: RadarSliceTooltipDatum[]
}
export type RadarSliceTooltipComponent = FunctionComponent<RadarSliceTooltipProps>
export interface RadarCustomLayerProps<D extends Record<string, unknown>> {
data: D[]
keys: string[]
indices: string[] | number[]
colorByKey: RadarColorMapping
centerX: number
centerY: number
radiusScale: ScaleLinear<number, number>
angleStep: number
}
export type RadarCustomLayer<D extends Record<string, unknown>> = FunctionComponent<
RadarCustomLayerProps<D>
>
export type RadarLayerId = 'grid' | 'layers' | 'slices' | 'dots' | 'legends'
export type RadarColorMapping = Record<string, string>
export interface RadarCommonProps<D extends Record<string, unknown>> {
maxValue: number | 'auto'
// second argument passed to the formatter is the key
valueFormat: ValueFormat<number, string>
layers: (RadarLayerId | RadarCustomLayer<D>)[]
margin: Box
curve: ClosedCurveFactoryId
gridLevels: number
gridShape: 'circular' | 'linear'
gridLabel: GridLabelComponent
gridLabelOffset: number
enableDots: boolean
dotSymbol: DotsItemSymbolComponent
dotSize: number
dotColor: InheritedColorConfig<PointData>
dotBorderWidth: number
dotBorderColor: InheritedColorConfig<PointData>
enableDotLabel: boolean
dotLabel: PropertyAccessor<PointData, string | number>
dotLabelFormat: ValueFormat<number>
dotLabelYOffset: number
theme: Theme
colors: OrdinalColorScaleConfig<{ key: string; index: number }>
fillOpacity: number
blendMode: CssMixBlendMode
borderWidth: number
borderColor: InheritedColorConfig<{ key: string; color: string }>
isInteractive: boolean
sliceTooltip: RadarSliceTooltipComponent
renderWrapper: boolean
legends: LegendProps[]
role: string
ariaLabel: AriaAttributes['aria-label']
ariaLabelledBy: AriaAttributes['aria-labelledby']
ariaDescribedBy: AriaAttributes['aria-describedby']
}
export interface RadarSvgFillMatcherDatum<D extends Record<string, unknown>> {
color: string
data: RadarDataProps<D>['data']
key: string
}
export type RadarSvgProps<D extends Record<string, unknown>> = Partial<RadarCommonProps<D>> &
RadarDataProps<D> &
Dimensions &
ModernMotionProps &
SvgDefsAndFill<RadarSvgFillMatcherDatum<D>>
export type BoundLegendProps = Required<Pick<LegendProps, 'data'>> & Omit<LegendProps, 'data'>