/
index.d.ts
596 lines (538 loc) · 17.6 KB
/
index.d.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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
import * as React from 'react'
import { Interpolation, SpringConfig } from '@react-spring/web'
import { CurveFactory } from 'd3-shape'
import { ComponentType } from 'react'
declare module '@nivo/core' {
export type DatumValue = string | number | Date
export interface Dimensions {
height: number
width: number
}
export interface Point {
x: number
y: number
}
export interface AlignBox extends Dimensions, Point {}
export type Margin = {
bottom: number
left: number
right: number
top: number
}
export type Box = Partial<Margin>
export type BoxAlign =
| 'center'
| 'top-left'
| 'top'
| 'top-right'
| 'right'
| 'bottom-right'
| 'bottom'
| 'bottom-left'
| 'left'
export const boxAlignments: BoxAlign[]
export function alignBox(
box: AlignBox,
container: AlignBox,
alignment: BoxAlign
): [number, number]
export type GetColor<T> = (datum: T) => string
export type Colors = string[] | string
export interface ColorProps<T> {
colors?: Colors
colorBy?: string | GetColor<T>
}
export type CompleteTheme = {
crosshair: {
line: {
stroke: string
strokeWidth: number
strokeOpacity: number
strokeDasharray: string
}
}
background: string
fontFamily: string
fontSize: number
textColor: string
axis: {
domain: {
line: Partial<React.CSSProperties>
}
ticks: {
line: Partial<React.CSSProperties>
text: Partial<React.CSSProperties>
}
legend: {
text: Partial<React.CSSProperties>
}
}
grid: {
line: Partial<React.CSSProperties>
}
legends: {
hidden: {
symbol: Partial<{
fill: string
opacity: number
}>
text: Partial<React.CSSProperties>
}
title: {
text: Partial<React.CSSProperties>
}
text: Partial<React.CSSProperties>
ticks: {
line: Partial<React.CSSProperties>
text: Partial<React.CSSProperties>
}
}
labels: {
text: Partial<React.CSSProperties>
}
markers: {
lineColor: string
lineStrokeWidth: number
textColor: string
fontSize: string | 0
text: Partial<React.CSSProperties>
}
dots: {
text: Partial<React.CSSProperties>
}
tooltip: {
container: Partial<React.CSSProperties>
basic: Partial<React.CSSProperties>
chip: Partial<React.CSSProperties>
table: Partial<React.CSSProperties>
tableCell: Partial<React.CSSProperties>
tableCellValue: Partial<React.CSSProperties>
}
annotations: {
text: {
fill: string
outlineWidth: number
outlineColor: string
outlineOpacity: number
} & Partial<Omit<React.CSSProperties, 'fill'>>
link: {
stroke: string
strokeWidth: number
outlineWidth: number
outlineColor: string
outlineOpacity: number
} & Partial<Omit<React.CSSProperties, 'stroke' | 'strokeWidth'>>
outline: {
stroke: string
strokeWidth: number
outlineWidth: number
outlineColor: string
outlineOpacity: number
} & Partial<Omit<React.CSSProperties, 'stroke' | 'strokeWidth'>>
symbol: {
fill: string
outlineWidth: number
outlineColor: string
outlineOpacity: number
} & Partial<Omit<React.CSSProperties, 'fill'>>
}
}
export type Theme = Partial<
Pick<CompleteTheme, 'background' | 'fontFamily' | 'fontSize' | 'textColor'> & {
crosshair: Partial<{
line: Partial<CompleteTheme['crosshair']['line']>
}>
axis: Partial<{
domain: Partial<{
line: Partial<CompleteTheme['axis']['domain']['line']>
}>
ticks: Partial<{
line: Partial<CompleteTheme['axis']['ticks']['line']>
text: Partial<CompleteTheme['axis']['ticks']['text']>
}>
legend: Partial<{
text: Partial<CompleteTheme['axis']['legend']['text']>
}>
}>
grid: Partial<{
line: Partial<CompleteTheme['grid']['line']>
}>
legends: Partial<{
hidden: Partial<{
symbol: CompleteTheme['legends']['hidden']['symbol']
text: CompleteTheme['legends']['hidden']['text']
}>
title: Partial<{
text: Partial<CompleteTheme['legends']['title']['text']>
}>
text: Partial<CompleteTheme['legends']['text']>
ticks: Partial<{
line: Partial<CompleteTheme['legends']['ticks']['line']>
text: Partial<CompleteTheme['legends']['ticks']['text']>
}>
}>
labels: Partial<{
text: Partial<CompleteTheme['labels']['text']>
}>
markers: Partial<CompleteTheme['markers']>
dots: Partial<{
text: Partial<CompleteTheme['dots']['text']>
}>
tooltip: Partial<CompleteTheme['tooltip']>
annotations: Partial<{
text: Partial<CompleteTheme['annotations']['text']>
link: Partial<CompleteTheme['annotations']['link']>
outline: Partial<CompleteTheme['annotations']['outline']>
symbol: Partial<CompleteTheme['annotations']['symbol']>
}>
}
>
export function useTheme(): CompleteTheme
export function usePartialTheme(theme?: Theme): CompleteTheme
export type MotionProps = Partial<{
animate: boolean
motionDamping: number
motionStiffness: number
}>
export type ModernMotionProps = Partial<{
animate: boolean
motionConfig: string | SpringConfig
}>
export function useMotionConfig(): {
animate: boolean
config: SpringConfig
springConfig: {
stiffness: number
damping: number
}
}
export type SvgFillMatcher<T> = (datum: T) => boolean
export interface SvgDefsAndFill<T> {
defs?: {
id: string
[key: string]: any
}[]
fill?: { id: string; match: Record<string, unknown> | SvgFillMatcher<T> | '*' }[]
}
export type CssMixBlendMode =
| 'normal'
| 'multiply'
| 'screen'
| 'overlay'
| 'darken'
| 'lighten'
| 'color-dodge'
| 'color-burn'
| 'hard-light'
| 'soft-light'
| 'difference'
| 'exclusion'
| 'hue'
| 'saturation'
| 'color'
| 'luminosity'
export type StackOrder = 'ascending' | 'descending' | 'insideOut' | 'none' | 'reverse'
export type StackOffset = 'expand' | 'diverging' | 'none' | 'silhouette' | 'wiggle'
export type AreaCurve =
| 'basis'
| 'cardinal'
| 'catmullRom'
| 'linear'
| 'monotoneX'
| 'monotoneY'
| 'natural'
| 'step'
| 'stepAfter'
| 'stepBefore'
export function useAnimatedPath(path: string): Interpolation<string>
// ------------------------------------------------------------------------
// Patterns & Gradients
// ------------------------------------------------------------------------
export type GradientColor = {
offset: number
color: string
opacity?: number
}
export function linearGradientDef(
id: string,
colors: GradientColor[],
options?: React.SVGProps<SVGLinearGradientElement>
): {
id: string
type: 'linearGradient'
colors: GradientColor[]
} & React.SVGProps<SVGLinearGradientElement>
export type LinearGradientDef = {
id: string
type: 'linearGradient'
colors: {
offset: number
color: string
opacity?: number
}[]
gradientTransform?: string
}
export type PatternDotsDef = {
id: string
type: 'patternDots'
color?: string
background?: string
size?: number
padding?: number
stagger?: boolean
}
export function patternDotsDef(
id: string,
options?: Omit<PatternDotsDef, 'id' | 'type'>
): PatternDotsDef
export function PatternDots(props: Omit<PatternDotsDef, 'type'>): JSX.Element
export type PatternSquaresDef = Omit<PatternDotsDef, 'type'> & {
type: 'patternSquares'
}
export function patternSquaresDef(
id: string,
options?: Omit<PatternSquaresDef, 'id' | 'type'>
): PatternSquaresDef
export function PatternSquares(props: Omit<PatternSquaresDef, 'type'>): JSX.Element
export type PatternLinesDef = {
id: string
type: 'patternLines'
spacing?: number
rotation?: number
background?: string
color?: string
lineWidth?: number
}
export function patternLinesDef(
id: string,
options?: Omit<PatternLinesDef, 'id' | 'type'>
): PatternLinesDef
export function PatternLines(props: Omit<PatternLinesDef, 'type'>): JSX.Element
export type Def = LinearGradientDef | PatternDotsDef | PatternSquaresDef | PatternLinesDef
export type DefsProps = {
defs: Def[]
}
export function Defs(props: DefsProps): JSX.Element
// ------------------------------------------------------------------------
// Motion
// ------------------------------------------------------------------------
export const defaultAnimate = true
export const defaultMotionStiffness = 90
export const defaultMotionDamping = 15
type MotionDefaultProps = {
animate: true
stiffness: 90
damping: 15
config: 'default'
}
export const motionDefaultProps: MotionDefaultProps
type DefaultMargin = {
top: 0
right: 0
bottom: 0
left: 0
}
export const defaultMargin: DefaultMargin
export function degreesToRadians(degrees: number): number
export function radiansToDegrees(radians: number): number
export function absoluteAngleDegrees(degrees: number): number
export function normalizeAngle(degrees: number): number
export function clampArc(
startAngle: number,
endAngle: number,
length?: number
): [number, number]
type Accessor<T extends keyof U, U> = T extends string ? U[T] : never
export type DatumPropertyAccessor<RawDatum, T> = (datum: RawDatum) => T
export function useDimensions(
width: number,
height: number,
margin?: Box
): {
margin: Margin
innerWidth: number
innerHeight: number
outerWidth: number
outerHeight: number
}
export function useMeasure(): [
React.RefObject<HTMLDivElement>,
{ left: number; top: number; width: number; height: number }
]
type SvgWrapperType = (
props: React.PropsWithChildren<{
width: number
height: number
margin: Margin
defs?: any
role?: string
ariaLabel?: React.AriaAttributes['aria-label']
ariaLabelledBy?: React.AriaAttributes['aria-labelledby']
ariaDescribedBy?: React.AriaAttributes['aria-describedby']
isFocusable?: boolean
}>
) => JSX.Element
export const SvgWrapper: SvgWrapperType
interface ContainerProps {
theme?: Theme
renderWrapper?: boolean
isInteractive?: boolean
animate?: boolean
motionStiffness?: number
motionDamping?: number
motionConfig?: string | SpringConfig
}
type ContainerType = (props: React.PropsWithChildren<ContainerProps>) => JSX.Element
export const Container: ContainerType
type ResponsiveWrapperType = (props: {
children: (dimensions: { width: number; height: number }) => JSX.Element
}) => JSX.Element
export const ResponsiveWrapper: ResponsiveWrapperType
interface ThemeProviderProps {
theme?: Theme
}
type ThemeProviderType = (props: React.PropsWithChildren<ThemeProviderProps>) => JSX.Element
export const ThemeProvider: ThemeProviderType
export function getDistance(x1: number, y1: number, x2: number, y2: number): number
export function getAngle(x1: number, y1: number, x2: number, y2: number): number
export function positionFromAngle(
angle: number,
distance: number
): {
x: number
y: number
}
export type ValueFormat<Value, Context = void> =
| string // d3 formatter
// explicit formatting function
| (Context extends void
? (value: Value) => string
: (value: Value, context: Context) => string)
export function getValueFormatter<Value, Context = void>(
format?: ValueFormat<Value, Context>
): Context extends void ? (value: Value) => string : (value: Value, context: Context) => string
export function useValueFormatter<Value, Context = void>(
format?: ValueFormat<Value, Context>
): Context extends void ? (value: Value) => string : (value: Value, context: Context) => string
export type PropertyAccessor<Datum, Value> =
// path to use with `lodash.get()`
| string
// explicit accessor function
| ((datum: Datum) => Value)
export function getPropertyAccessor<Datum, Value>(
accessor: PropertyAccessor<Datum, Value>
): (datum: Datum) => Value
export function usePropertyAccessor<Datum, Value>(
accessor: PropertyAccessor<Datum, Value>
): (datum: Datum) => Value
export function getRelativeCursor(element: Element, event: React.MouseEvent): [number, number]
export function isCursorInRect(
x: number,
y: number,
width: number,
height: number,
cursorX: number,
cursorY: number
): boolean
export interface CartesianMarkerProps<V extends DatumValue = DatumValue> {
axis: 'x' | 'y'
value: V
legend?: string
legendOrientation?: 'horizontal' | 'vertical'
legendPosition?: BoxAlign
lineStyle?: Partial<React.CSSProperties>
textStyle?: Partial<React.CSSProperties>
}
interface CartesianMarkersProps<
X extends DatumValue = DatumValue,
Y extends DatumValue = DatumValue
> {
width: number
height: number
xScale: (value: X) => number
yScale: (value: Y) => number
markers: CartesianMarkerProps<X | Y>[]
}
type CartesianMarkersType = <
X extends DatumValue = DatumValue,
Y extends DatumValue = DatumValue
>(
props: CartesianMarkersProps<X, Y>
) => JSX.Element
export const CartesianMarkers: CartesianMarkersType
export type CurveFactoryId =
| 'basis'
| 'basisClosed'
| 'basisOpen'
| 'bundle'
| 'cardinal'
| 'cardinalClosed'
| 'cardinalOpen'
| 'catmullRom'
| 'catmullRomClosed'
| 'catmullRomOpen'
| 'linear'
| 'linearClosed'
| 'monotoneX'
| 'monotoneY'
| 'natural'
| 'step'
| 'stepAfter'
| 'stepBefore'
// Curve factories compatible d3 line shape generator
export type LineCurveFactoryId =
| 'basis'
| 'cardinal'
| 'catmullRom'
| 'linear'
| 'monotoneX'
| 'monotoneY'
| 'natural'
| 'step'
| 'stepAfter'
| 'stepBefore'
// Curve factories compatible d3 area shape generator
export type AreaCurveFactoryId =
| 'basis'
| 'cardinal'
| 'catmullRom'
| 'linear'
| 'monotoneX'
| 'monotoneY'
| 'natural'
| 'step'
| 'stepAfter'
| 'stepBefore'
export type ClosedCurveFactoryId =
| 'basisClosed'
| 'cardinalClosed'
| 'catmullRomClosed'
| 'linearClosed'
export const closedCurvePropKeys: ClosedCurveFactoryId[]
export const curveFromProp: (interpolation: CurveFactoryId) => CurveFactory
export const useCurveInterpolation: (interpolation: CurveFactoryId) => CurveFactory
export interface DotsItemSymbolProps {
size: number
color: string
borderWidth: number
borderColor: string
}
export type DotsItemSymbolComponent = React.FunctionComponent<DotsItemSymbolProps>
export interface DotsItemProps<D = any> {
datum: D
x: number
y: number
size: number
color: string
borderWidth: number
borderColor: string
label?: string | number
labelTextAnchor?: 'start' | 'middle' | 'end'
labelYOffset?: number
symbol?: DotsItemSymbolComponent
}
export const DotsItem: React.FunctionComponent<DotsItemProps>
export type ExtractProps<TComponent> = TComponent extends ComponentType<infer TProps>
? TProps
: never
}