-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
types.ts
239 lines (203 loc) · 5.44 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
import { Box, BoxAlign, CompleteTheme, Dimensions, Theme, ValueFormat } from '@nivo/core'
import { LegendProps } from '@nivo/legends'
export type BBox = Record<'x' | 'y' | 'height' | 'width', number>
type Legend = Record<'x' | 'y' | 'rotation', number>
export type Month = {
path: string
bbox: BBox
date: Date
year: number
month: number
}
export type MonthLegend = Omit<Month, 'path'> & Legend
export type Year = {
year: number
bbox: BBox
}
export type YearLegend = Year & Legend
export type DateOrString = string | Date
export type CalendarDatum = {
day: string
value: number
}
export type CalendarData = {
from: DateOrString
to: DateOrString
data: CalendarDatum[]
}
export type CalendarDayData = {
date: Date
day: string
value?: number
color: string
size: number
x: number
y: number
}
export type CalendarLegendProps = LegendProps & {
itemCount: number
}
export interface ColorScale {
(value: number | { valueOf(): number }): string
ticks(count?: number): number[]
}
export type CalendarYearLegendsProps = {
legend: (year: number) => string | number
theme: CompleteTheme
years: YearLegend[]
}
export type CalendarMonthLegendsProps = {
legend: (year: number, month: number, date: Date) => string | number
months: MonthLegend[]
theme: CompleteTheme
}
export type CalendarTooltipProps = {
value: string
day: string
color: string
}
export type CalendarMonthPathProps = {
borderColor: string
borderWidth: number
path: string
}
export type Datum = {
data: {
date: Date
day: string
size: number
x: number
y: number
}
date: Date
day: string
value: number
color: string
size: number
x: number
y: number
}
export type CalendarDayProps = {
data: Omit<Datum, 'data' | 'value'> | Datum
x: number
y: number
size: number
color: string
borderWidth: number
borderColor: string
isInteractive: boolean
tooltip: React.FC<CalendarTooltipProps>
formatValue: (value: number) => string
} & Partial<InteractivityProps<Omit<Datum, 'data' | 'value'> | Datum, SVGRectElement>>
type InteractivityProps<DatumProp, ElementType> = Partial<
Record<
'onClick' | 'onMouseEnter' | 'onMouseLeave' | 'onMouseMove',
(datum: DatumProp, event: React.MouseEvent<ElementType>) => void
>
>
export type CommonCalendarProps = {
minValue: 'auto' | number
maxValue: 'auto' | number
direction: 'horizontal' | 'vertical'
colors: string[]
colorScale: ColorScale
margin: Box
align: BoxAlign
yearLegend: (year: number) => string | number
yearSpacing: number
yearLegendOffset: number
yearLegendPosition: 'before' | 'after'
monthSpacing: number
monthBorderWidth: number
monthBorderColor: string
monthLegend: (year: number, month: number, date: Date) => string | number
monthLegendOffset: number
monthLegendPosition: 'before' | 'after'
daySpacing: number
dayBorderWidth: number
dayBorderColor: string
emptyColor: string
valueFormat: ValueFormat<number>
legendFormat: ValueFormat<number>
theme: Theme
// interactivity
isInteractive: boolean
tooltip: React.FC<CalendarTooltipProps>
legends: CalendarLegendProps[]
renderWrapper: boolean
}
export type CalendarSvgProps = Dimensions &
CalendarData &
Partial<
CommonCalendarProps &
InteractivityProps<Omit<Datum, 'data' | 'value'> | Datum, SVGRectElement> & {
role: string
}
>
export type CalendarCanvasProps = Dimensions &
CalendarData &
Partial<
CommonCalendarProps &
InteractivityProps<Omit<Datum, 'data' | 'value'> | Datum, HTMLCanvasElement> & {
pixelRatio: number
}
>
export type TimeRangeDayData = (Omit<CalendarDatum, 'value'> | CalendarDatum) & {
coordinates: {
x: number
y: number
}
date: Date
firstWeek: number
month: number
year: number
color: string
width: number
height: number
}
export type TimeRangeTooltipProps = Omit<TimeRangeDayData, 'date' | 'value'> & {
value: string
}
export type Weekday =
| 'sunday'
| 'monday'
| 'tuesday'
| 'wednesday'
| 'thursday'
| 'friday'
| 'saturday'
export type TimeRangeSvgProps = Dimensions & { data: CalendarDatum[] } & Partial<
Omit<CalendarData, 'data'>
> &
Partial<
Omit<
CommonCalendarProps,
| 'yearLegend'
| 'yearSpacing'
| 'yearLegendOffset'
| 'yearLegendPosition'
| 'monthSpacing'
| 'monthBorderWidth'
| 'monthBorderColor'
> &
InteractivityProps<TimeRangeDayData, SVGRectElement> & {
dayRadius: number
square: boolean
role: string
weekdayLegendOffset: number
weekdayTicks: Array<0 | 1 | 2 | 3 | 4 | 5 | 6>
firstWeekday: Weekday
weekdays: string[]
}
>
export type TimeRangeDayProps = Record<
'x' | 'y' | 'borderWidth' | 'rx' | 'ry' | 'height' | 'width',
number
> & {
data: TimeRangeDayData
color: string
borderColor: string
isInteractive: boolean
tooltip: React.FC<TimeRangeTooltipProps>
formatValue: (value: number) => string
} & Partial<InteractivityProps<TimeRangeDayData, SVGRectElement>>