1 | import * as React from 'react'
|
2 | import { Interpolation, SpringConfig } from '@react-spring/web'
|
3 | import { CurveFactory } from 'd3-shape'
|
4 | import { ComponentType } from 'react'
|
5 |
|
6 | export type DatumValue = string | number | Date
|
7 |
|
8 | export interface Dimensions {
|
9 | height: number
|
10 | width: number
|
11 | }
|
12 |
|
13 | export interface Point {
|
14 | x: number
|
15 | y: number
|
16 | }
|
17 |
|
18 | export interface AlignBox extends Dimensions, Point {}
|
19 |
|
20 | export type Margin = {
|
21 | bottom: number
|
22 | left: number
|
23 | right: number
|
24 | top: number
|
25 | }
|
26 | export type Padding = Margin
|
27 |
|
28 | export type Box = Partial<Margin>
|
29 | export type BoxAlign =
|
30 | | 'center'
|
31 | | 'top-left'
|
32 | | 'top'
|
33 | | 'top-right'
|
34 | | 'right'
|
35 | | 'bottom-right'
|
36 | | 'bottom'
|
37 | | 'bottom-left'
|
38 | | 'left'
|
39 | export const boxAlignments: readonly BoxAlign[]
|
40 | export function alignBox(box: AlignBox, container: AlignBox, alignment: BoxAlign): [number, number]
|
41 |
|
42 | export type GetColor<T> = (datum: T) => string
|
43 | export type Colors = readonly string[] | string
|
44 | export interface ColorProps<T> {
|
45 | colors?: Colors
|
46 | colorBy?: string | GetColor<T>
|
47 | }
|
48 |
|
49 |
|
50 |
|
51 |
|
52 | export type TextStyle = {
|
53 | fontFamily: Exclude<React.CSSProperties['fontFamily'], undefined>
|
54 | fontSize: Exclude<React.CSSProperties['fontSize'], undefined>
|
55 | fill: string
|
56 | outlineWidth: number
|
57 | outlineColor: string
|
58 | outlineOpacity: number
|
59 | } & Partial<React.CSSProperties>
|
60 |
|
61 | export function sanitizeSvgTextStyle(style: TextStyle): any
|
62 |
|
63 | export type CompleteTheme = {
|
64 | background: string
|
65 | text: TextStyle
|
66 | axis: {
|
67 | domain: {
|
68 | line: Partial<React.CSSProperties>
|
69 | }
|
70 | ticks: {
|
71 | line: Partial<React.CSSProperties>
|
72 | text: TextStyle
|
73 | }
|
74 | legend: {
|
75 | text: TextStyle
|
76 | }
|
77 | }
|
78 | grid: {
|
79 | line: Partial<React.CSSProperties>
|
80 | }
|
81 | crosshair: {
|
82 | line: {
|
83 | stroke: string
|
84 | strokeWidth: number
|
85 | strokeOpacity: number
|
86 | strokeDasharray: string
|
87 | }
|
88 | }
|
89 | legends: {
|
90 | hidden: {
|
91 | symbol: Partial<{
|
92 | fill: string
|
93 | opacity: number
|
94 | }>
|
95 | text: TextStyle
|
96 | }
|
97 | title: {
|
98 | text: TextStyle
|
99 | }
|
100 | text: TextStyle
|
101 | ticks: {
|
102 | line: Partial<React.CSSProperties>
|
103 | text: TextStyle
|
104 | }
|
105 | }
|
106 | labels: {
|
107 | text: TextStyle
|
108 | }
|
109 | markers: {
|
110 | lineColor: string
|
111 | lineStrokeWidth: number
|
112 | textColor: string
|
113 | fontSize: string | 0
|
114 | text: TextStyle
|
115 | }
|
116 | dots: {
|
117 | text: TextStyle
|
118 | }
|
119 | tooltip: {
|
120 | wrapper: Partial<React.CSSProperties>
|
121 | container: Partial<React.CSSProperties>
|
122 | basic: Partial<React.CSSProperties>
|
123 | chip: Partial<React.CSSProperties>
|
124 | table: Partial<React.CSSProperties>
|
125 | tableCell: Partial<React.CSSProperties>
|
126 | tableCellValue: Partial<React.CSSProperties>
|
127 | }
|
128 | annotations: {
|
129 | text: {
|
130 | fill: string
|
131 | outlineWidth: number
|
132 | outlineColor: string
|
133 | outlineOpacity: number
|
134 | } & Partial<Omit<React.CSSProperties, 'fill'>>
|
135 | link: {
|
136 | stroke: string
|
137 | strokeWidth: number
|
138 | outlineWidth: number
|
139 | outlineColor: string
|
140 | outlineOpacity: number
|
141 | } & Partial<Omit<React.CSSProperties, 'stroke' | 'strokeWidth'>>
|
142 | outline: {
|
143 | stroke: string
|
144 | strokeWidth: number
|
145 | outlineWidth: number
|
146 | outlineColor: string
|
147 | outlineOpacity: number
|
148 | } & Partial<Omit<React.CSSProperties, 'stroke' | 'strokeWidth'>>
|
149 | symbol: {
|
150 | fill: string
|
151 | outlineWidth: number
|
152 | outlineColor: string
|
153 | outlineOpacity: number
|
154 | } & Partial<Omit<React.CSSProperties, 'fill'>>
|
155 | }
|
156 | }
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 | export type ThemeWithoutInheritance = {
|
169 | background: CompleteTheme['background']
|
170 | text: CompleteTheme['text']
|
171 | axis: {
|
172 | domain: {
|
173 | line: CompleteTheme['axis']['domain']['line']
|
174 | }
|
175 | ticks: {
|
176 | line: CompleteTheme['axis']['ticks']['line']
|
177 | text: Partial<CompleteTheme['axis']['ticks']['text']>
|
178 | }
|
179 | legend: Partial<{
|
180 | text: Partial<CompleteTheme['axis']['legend']['text']>
|
181 | }>
|
182 | }
|
183 | grid: {
|
184 | line: CompleteTheme['grid']['line']
|
185 | }
|
186 | crosshair: {
|
187 | line: CompleteTheme['crosshair']['line']
|
188 | }
|
189 | legends: {
|
190 | hidden: {
|
191 | symbol: CompleteTheme['legends']['hidden']['symbol']
|
192 | text: Partial<CompleteTheme['legends']['hidden']['text']>
|
193 | }
|
194 | title: {
|
195 | text: Partial<CompleteTheme['legends']['title']['text']>
|
196 | }
|
197 | text: Partial<CompleteTheme['legends']['text']>
|
198 | ticks: {
|
199 | line: CompleteTheme['legends']['ticks']['line']
|
200 | text: Partial<CompleteTheme['legends']['ticks']['text']>
|
201 | }
|
202 | }
|
203 | labels: {
|
204 | text: Partial<CompleteTheme['labels']['text']>
|
205 | }
|
206 | markers: Partial<CompleteTheme['markers']>
|
207 | dots: {
|
208 | text: Partial<CompleteTheme['dots']['text']>
|
209 | }
|
210 | tooltip: CompleteTheme['tooltip']
|
211 | annotations: {
|
212 | text: Partial<CompleteTheme['annotations']['text']>
|
213 | link: CompleteTheme['annotations']['link']
|
214 | outline: CompleteTheme['annotations']['outline']
|
215 | symbol: CompleteTheme['annotations']['symbol']
|
216 | }
|
217 | }
|
218 |
|
219 | export type Theme = Partial<{
|
220 | background: CompleteTheme['background']
|
221 | text: Partial<CompleteTheme['text']>
|
222 | axis: Partial<{
|
223 | domain: Partial<{
|
224 | line: Partial<CompleteTheme['axis']['domain']['line']>
|
225 | }>
|
226 | ticks: Partial<{
|
227 | line: Partial<CompleteTheme['axis']['ticks']['line']>
|
228 | text: Partial<CompleteTheme['axis']['ticks']['text']>
|
229 | }>
|
230 | legend: Partial<{
|
231 | text: Partial<CompleteTheme['axis']['legend']['text']>
|
232 | }>
|
233 | }>
|
234 | grid: Partial<{
|
235 | line: Partial<CompleteTheme['grid']['line']>
|
236 | }>
|
237 | crosshair: Partial<{
|
238 | line: Partial<CompleteTheme['crosshair']['line']>
|
239 | }>
|
240 | legends: Partial<{
|
241 | hidden: Partial<{
|
242 | symbol: CompleteTheme['legends']['hidden']['symbol']
|
243 | text: CompleteTheme['legends']['hidden']['text']
|
244 | }>
|
245 | title: Partial<{
|
246 | text: Partial<CompleteTheme['legends']['title']['text']>
|
247 | }>
|
248 | text: Partial<CompleteTheme['legends']['text']>
|
249 | ticks: Partial<{
|
250 | line: Partial<CompleteTheme['legends']['ticks']['line']>
|
251 | text: Partial<CompleteTheme['legends']['ticks']['text']>
|
252 | }>
|
253 | }>
|
254 | labels: Partial<{
|
255 | text: Partial<CompleteTheme['labels']['text']>
|
256 | }>
|
257 | markers: Partial<CompleteTheme['markers']>
|
258 | dots: Partial<{
|
259 | text: Partial<CompleteTheme['dots']['text']>
|
260 | }>
|
261 | tooltip: Partial<CompleteTheme['tooltip']>
|
262 | annotations: Partial<{
|
263 | text: Partial<CompleteTheme['annotations']['text']>
|
264 | link: Partial<CompleteTheme['annotations']['link']>
|
265 | outline: Partial<CompleteTheme['annotations']['outline']>
|
266 | symbol: Partial<CompleteTheme['annotations']['symbol']>
|
267 | }>
|
268 | }>
|
269 |
|
270 | export function useTheme(): CompleteTheme
|
271 | export function usePartialTheme(theme?: Theme): CompleteTheme
|
272 | export function extendDefaultTheme(
|
273 | defaultTheme: ThemeWithoutInheritance,
|
274 | customTheme: Theme
|
275 | ): CompleteTheme
|
276 |
|
277 | export type MotionProps = Partial<{
|
278 | animate: boolean
|
279 | motionConfig: string | SpringConfig
|
280 | }>
|
281 |
|
282 | export function useMotionConfig(): {
|
283 | animate: boolean
|
284 | config: SpringConfig
|
285 | }
|
286 |
|
287 | export type SvgFillMatcher<T> = (datum: T) => boolean
|
288 | export interface SvgDefsAndFill<T> {
|
289 | defs?: readonly {
|
290 | id: string
|
291 | [key: string]: any
|
292 | }[]
|
293 | fill?: readonly { id: string; match: Record<string, unknown> | SvgFillMatcher<T> | '*' }[]
|
294 | }
|
295 |
|
296 | export type CssMixBlendMode =
|
297 | | 'normal'
|
298 | | 'multiply'
|
299 | | 'screen'
|
300 | | 'overlay'
|
301 | | 'darken'
|
302 | | 'lighten'
|
303 | | 'color-dodge'
|
304 | | 'color-burn'
|
305 | | 'hard-light'
|
306 | | 'soft-light'
|
307 | | 'difference'
|
308 | | 'exclusion'
|
309 | | 'hue'
|
310 | | 'saturation'
|
311 | | 'color'
|
312 | | 'luminosity'
|
313 |
|
314 | export type StackOrder = 'ascending' | 'descending' | 'insideOut' | 'none' | 'reverse'
|
315 |
|
316 | export type StackOffset = 'expand' | 'diverging' | 'none' | 'silhouette' | 'wiggle'
|
317 |
|
318 | export type AreaCurve =
|
319 | | 'basis'
|
320 | | 'cardinal'
|
321 | | 'catmullRom'
|
322 | | 'linear'
|
323 | | 'monotoneX'
|
324 | | 'monotoneY'
|
325 | | 'natural'
|
326 | | 'step'
|
327 | | 'stepAfter'
|
328 | | 'stepBefore'
|
329 |
|
330 | export function useAnimatedPath(path: string): Interpolation<string>
|
331 |
|
332 | // ------------------------------------------------------------------------
|
333 | // Patterns & Gradients
|
334 | // ------------------------------------------------------------------------
|
335 |
|
336 | export type GradientColor = {
|
337 | offset: number
|
338 | color: string
|
339 | opacity?: number
|
340 | }
|
341 |
|
342 | export function linearGradientDef(
|
343 | id: string,
|
344 | colors: GradientColor[],
|
345 | options?: React.SVGProps<SVGLinearGradientElement>
|
346 | ): {
|
347 | id: string
|
348 | type: 'linearGradient'
|
349 | colors: GradientColor[]
|
350 | } & React.SVGProps<SVGLinearGradientElement>
|
351 |
|
352 | export type LinearGradientDef = {
|
353 | id: string
|
354 | type: 'linearGradient'
|
355 | colors: {
|
356 | offset: number
|
357 | color: string
|
358 | opacity?: number
|
359 | }[]
|
360 | gradientTransform?: string
|
361 | }
|
362 |
|
363 | export type PatternDotsDef = {
|
364 | id: string
|
365 | type: 'patternDots'
|
366 | color?: string
|
367 | background?: string
|
368 | size?: number
|
369 | padding?: number
|
370 | stagger?: boolean
|
371 | }
|
372 | export function patternDotsDef(
|
373 | id: string,
|
374 | options?: Omit<PatternDotsDef, 'id' | 'type'>
|
375 | ): PatternDotsDef
|
376 | export function PatternDots(props: Omit<PatternDotsDef, 'type'>): JSX.Element
|
377 |
|
378 | export type PatternSquaresDef = Omit<PatternDotsDef, 'type'> & {
|
379 | type: 'patternSquares'
|
380 | }
|
381 | export function patternSquaresDef(
|
382 | id: string,
|
383 | options?: Omit<PatternSquaresDef, 'id' | 'type'>
|
384 | ): PatternSquaresDef
|
385 | export function PatternSquares(props: Omit<PatternSquaresDef, 'type'>): JSX.Element
|
386 |
|
387 | export type PatternLinesDef = {
|
388 | id: string
|
389 | type: 'patternLines'
|
390 | spacing?: number
|
391 | rotation?: number
|
392 | background?: string
|
393 | color?: string
|
394 | lineWidth?: number
|
395 | }
|
396 | export function patternLinesDef(
|
397 | id: string,
|
398 | options?: Omit<PatternLinesDef, 'id' | 'type'>
|
399 | ): PatternLinesDef
|
400 | export function PatternLines(props: Omit<PatternLinesDef, 'type'>): JSX.Element
|
401 |
|
402 | export type Def = LinearGradientDef | PatternDotsDef | PatternSquaresDef | PatternLinesDef
|
403 |
|
404 | export type DefsProps = {
|
405 | defs: readonly Def[]
|
406 | }
|
407 |
|
408 | export function Defs(props: DefsProps): JSX.Element
|
409 |
|
410 | // ------------------------------------------------------------------------
|
411 | // Motion
|
412 | // ------------------------------------------------------------------------
|
413 |
|
414 | export const defaultAnimate = true
|
415 |
|
416 | type MotionDefaultProps = {
|
417 | animate: true
|
418 | config: 'default'
|
419 | }
|
420 | export const motionDefaultProps: MotionDefaultProps
|
421 |
|
422 | type DefaultMargin = {
|
423 | top: 0
|
424 | right: 0
|
425 | bottom: 0
|
426 | left: 0
|
427 | }
|
428 | export const defaultMargin: DefaultMargin
|
429 |
|
430 | export function degreesToRadians(degrees: number): number
|
431 | export function radiansToDegrees(radians: number): number
|
432 | export function absoluteAngleDegrees(degrees: number): number
|
433 | export function normalizeAngle(degrees: number): number
|
434 | export function clampArc(startAngle: number, endAngle: number, length?: number): [number, number]
|
435 |
|
436 | type Accessor<T extends keyof U, U> = T extends string ? U[T] : never
|
437 |
|
438 | export type DatumPropertyAccessor<RawDatum, T> = (datum: RawDatum) => T
|
439 |
|
440 | export function useDimensions(
|
441 | width: number,
|
442 | height: number,
|
443 | margin?: Box
|
444 | ): {
|
445 | margin: Margin
|
446 | innerWidth: number
|
447 | innerHeight: number
|
448 | outerWidth: number
|
449 | outerHeight: number
|
450 | }
|
451 |
|
452 | export function useMeasure(): [
|
453 | React.RefObject<HTMLDivElement>,
|
454 | { left: number; top: number; width: number; height: number }
|
455 | ]
|
456 |
|
457 | type SvgWrapperType = (
|
458 | props: React.PropsWithChildren<{
|
459 | width: number
|
460 | height: number
|
461 | margin: Margin
|
462 | defs?: any
|
463 | role?: string
|
464 | ariaLabel?: React.AriaAttributes['aria-label']
|
465 | ariaLabelledBy?: React.AriaAttributes['aria-labelledby']
|
466 | ariaDescribedBy?: React.AriaAttributes['aria-describedby']
|
467 | isFocusable?: boolean
|
468 | }>
|
469 | ) => JSX.Element
|
470 | export const SvgWrapper: SvgWrapperType
|
471 |
|
472 | interface ContainerProps {
|
473 | theme?: Theme
|
474 | renderWrapper?: boolean
|
475 | isInteractive?: boolean
|
476 | animate?: boolean
|
477 | motionConfig?: string | SpringConfig
|
478 | }
|
479 | type ContainerType = (props: React.PropsWithChildren<ContainerProps>) => JSX.Element
|
480 | export const Container: ContainerType
|
481 |
|
482 | type ResponsiveWrapperType = (props: {
|
483 | children: (dimensions: { width: number; height: number }) => JSX.Element
|
484 | }) => JSX.Element
|
485 | export const ResponsiveWrapper: ResponsiveWrapperType
|
486 |
|
487 | interface ThemeProviderProps {
|
488 | theme?: Theme
|
489 | }
|
490 |
|
491 | type ThemeProviderType = (props: React.PropsWithChildren<ThemeProviderProps>) => JSX.Element
|
492 | export const ThemeProvider: ThemeProviderType
|
493 |
|
494 | export function getDistance(x1: number, y1: number, x2: number, y2: number): number
|
495 | export function getAngle(x1: number, y1: number, x2: number, y2: number): number
|
496 |
|
497 | export function positionFromAngle(
|
498 | angle: number,
|
499 | distance: number
|
500 | ): {
|
501 | x: number
|
502 | y: number
|
503 | }
|
504 |
|
505 | export type ValueFormat<Value, Context = void> =
|
506 | | string // d3 formatter
|
507 | // explicit formatting function
|
508 | | (Context extends void ? (value: Value) => string : (value: Value, context: Context) => string)
|
509 | export function getValueFormatter<Value, Context = void>(
|
510 | format?: ValueFormat<Value, Context>
|
511 | ): Context extends void ? (value: Value) => string : (value: Value, context: Context) => string
|
512 | export function useValueFormatter<Value, Context = void>(
|
513 | format?: ValueFormat<Value, Context>
|
514 | ): Context extends void ? (value: Value) => string : (value: Value, context: Context) => string
|
515 |
|
516 | export type PropertyAccessor<Datum, Value> =
|
517 | // path to use with `lodash.get()`
|
518 | | string
|
519 | // explicit accessor function
|
520 | | ((datum: Datum) => Value)
|
521 | export function getPropertyAccessor<Datum, Value>(
|
522 | accessor: PropertyAccessor<Datum, Value>
|
523 | ): (datum: Datum) => Value
|
524 | export function usePropertyAccessor<Datum, Value>(
|
525 | accessor: PropertyAccessor<Datum, Value>
|
526 | ): (datum: Datum) => Value
|
527 |
|
528 | export function getRelativeCursor(
|
529 | element: Element,
|
530 | event: React.MouseEvent | React.TouchEvent
|
531 | ): [number, number]
|
532 | export function isCursorInRect(
|
533 | x: number,
|
534 | y: number,
|
535 | width: number,
|
536 | height: number,
|
537 | cursorX: number,
|
538 | cursorY: number
|
539 | ): boolean
|
540 |
|
541 | export interface CartesianMarkerProps<V extends DatumValue = DatumValue> {
|
542 | axis: 'x' | 'y'
|
543 | value: V
|
544 | legend?: string
|
545 | legendOrientation?: 'horizontal' | 'vertical'
|
546 | legendPosition?: BoxAlign
|
547 | lineStyle?: Partial<React.CSSProperties>
|
548 | textStyle?: Partial<React.CSSProperties>
|
549 | }
|
550 | interface CartesianMarkersProps<
|
551 | X extends DatumValue = DatumValue,
|
552 | Y extends DatumValue = DatumValue
|
553 | > {
|
554 | width: number
|
555 | height: number
|
556 | xScale: (value: X) => number
|
557 | yScale: (value: Y) => number
|
558 | markers: readonly CartesianMarkerProps<X | Y>[]
|
559 | }
|
560 | type CartesianMarkersType = <X extends DatumValue = DatumValue, Y extends DatumValue = DatumValue>(
|
561 | props: CartesianMarkersProps<X, Y>
|
562 | ) => JSX.Element
|
563 | export const CartesianMarkers: CartesianMarkersType
|
564 |
|
565 | export type CurveFactoryId =
|
566 | | 'basis'
|
567 | | 'basisClosed'
|
568 | | 'basisOpen'
|
569 | | 'bundle'
|
570 | | 'cardinal'
|
571 | | 'cardinalClosed'
|
572 | | 'cardinalOpen'
|
573 | | 'catmullRom'
|
574 | | 'catmullRomClosed'
|
575 | | 'catmullRomOpen'
|
576 | | 'linear'
|
577 | | 'linearClosed'
|
578 | | 'monotoneX'
|
579 | | 'monotoneY'
|
580 | | 'natural'
|
581 | | 'step'
|
582 | | 'stepAfter'
|
583 | | 'stepBefore'
|
584 |
|
585 | // Curve factories compatible d3 line shape generator
|
586 | export type LineCurveFactoryId =
|
587 | | 'basis'
|
588 | | 'cardinal'
|
589 | | 'catmullRom'
|
590 | | 'linear'
|
591 | | 'monotoneX'
|
592 | | 'monotoneY'
|
593 | | 'natural'
|
594 | | 'step'
|
595 | | 'stepAfter'
|
596 | | 'stepBefore'
|
597 |
|
598 | // Curve factories compatible d3 area shape generator
|
599 | export type AreaCurveFactoryId =
|
600 | | 'basis'
|
601 | | 'cardinal'
|
602 | | 'catmullRom'
|
603 | | 'linear'
|
604 | | 'monotoneX'
|
605 | | 'monotoneY'
|
606 | | 'natural'
|
607 | | 'step'
|
608 | | 'stepAfter'
|
609 | | 'stepBefore'
|
610 |
|
611 | export type ClosedCurveFactoryId =
|
612 | | 'basisClosed'
|
613 | | 'cardinalClosed'
|
614 | | 'catmullRomClosed'
|
615 | | 'linearClosed'
|
616 | export const closedCurvePropKeys: readonly ClosedCurveFactoryId[]
|
617 |
|
618 | export const curveFromProp: (interpolation: CurveFactoryId) => CurveFactory
|
619 |
|
620 | export const useCurveInterpolation: (interpolation: CurveFactoryId) => CurveFactory
|
621 |
|
622 | export interface DotsItemSymbolProps {
|
623 | size: number
|
624 | color: string
|
625 | borderWidth: number
|
626 | borderColor: string
|
627 | }
|
628 | export type DotsItemSymbolComponent = React.FunctionComponent<DotsItemSymbolProps>
|
629 |
|
630 | export interface DotsItemProps<D = any> {
|
631 | datum: D
|
632 | x: number
|
633 | y: number
|
634 | size: number
|
635 | color: string
|
636 | borderWidth: number
|
637 | borderColor: string
|
638 | label?: string | number
|
639 | labelTextAnchor?: 'start' | 'middle' | 'end'
|
640 | labelYOffset?: number
|
641 | symbol?: DotsItemSymbolComponent
|
642 | }
|
643 | export const DotsItem: React.FunctionComponent<DotsItemProps>
|
644 |
|
645 | export type ExtractProps<TComponent> = TComponent extends ComponentType<infer TProps>
|
646 | ? TProps
|
647 | : never
|
648 |
|
\ | No newline at end of file |