UNPKG

35.6 kBPlain TextView Raw
1import {
2 AriaAttributes,
3 SVGProps,
4 SyntheticEvent,
5 ClipboardEvent,
6 CompositionEvent,
7 DragEvent,
8 FocusEvent,
9 FormEvent,
10 KeyboardEvent,
11 MouseEvent,
12 TouchEvent,
13 PointerEvent,
14 UIEvent,
15 WheelEvent,
16 AnimationEvent,
17 TransitionEvent,
18 ReactNode,
19 Component,
20 isValidElement,
21 FunctionComponent,
22 ReactElement,
23} from 'react';
24import _ from 'lodash';
25import { ScaleContinuousNumeric as D3ScaleContinuousNumeric } from 'd3-scale';
26
27export type StackOffsetType = 'sign' | 'expand' | 'none' | 'wiggle' | 'silhouette';
28export type LayoutType = 'horizontal' | 'vertical' | 'centric' | 'radial';
29export type PolarLayoutType = 'radial' | 'centric';
30export type AxisType = 'xAxis' | 'yAxis' | 'angleAxis' | 'radiusAxis';
31export type DataKey<T> = string | number | ((obj: T) => any);
32export type PresentationAttributesWithProps<P, T> = AriaAttributes &
33 DOMAttributesWithProps<P, T> &
34 Omit<SVGProps<T>, keyof DOMAttributesWithProps<P, T>>;
35export type PresentationAttributesAdaptChildEvent<P, T> = AriaAttributes &
36 DOMAttributesAdaptChildEvent<P, T> &
37 Omit<SVGProps<T>, keyof DOMAttributesAdaptChildEvent<P, T>>;
38
39export type SymbolType = 'circle' | 'cross' | 'diamond' | 'square' | 'star' | 'triangle' | 'wye';
40export type LegendType =
41 | 'plainline'
42 | 'line'
43 | 'square'
44 | 'rect'
45 | 'circle'
46 | 'cross'
47 | 'diamond'
48 | 'star'
49 | 'triangle'
50 | 'wye'
51 | 'none';
52export type TooltipType = 'none';
53export interface Coordinate {
54 x: number;
55 y: number;
56}
57
58export interface ChartCoordinate extends Coordinate {
59 xAxis?: any;
60 yAxis?: any;
61 width?: any;
62 height?: any;
63 offset?: ChartOffset;
64 angle?: number;
65 radius?: number;
66 cx?: number;
67 cy?: number;
68 startAngle?: number;
69 endAngle?: number;
70 innerRadius?: number;
71 outerRadius?: number;
72}
73
74export type ScaleType =
75 | 'auto'
76 | 'linear'
77 | 'pow'
78 | 'sqrt'
79 | 'log'
80 | 'identity'
81 | 'time'
82 | 'band'
83 | 'point'
84 | 'ordinal'
85 | 'quantile'
86 | 'quantize'
87 | 'utc'
88 | 'sequential'
89 | 'threshold';
90
91//
92// Event Handler Types -- Copied from @types/react/index.d.ts and adapted for Props.
93//
94
95type EventHandler<P, E extends SyntheticEvent<any>> = {
96 bivarianceHack(props: P, event: E): void;
97}['bivarianceHack'];
98
99type ReactEventHandler<P, T = Element> = EventHandler<P, SyntheticEvent<T>>;
100type ClipboardEventHandler<P, T = Element> = EventHandler<P, ClipboardEvent<T>>;
101type CompositionEventHandler<P, T = Element> = EventHandler<P, CompositionEvent<T>>;
102type DragEventHandler<P, T = Element> = EventHandler<P, DragEvent<T>>;
103type FocusEventHandler<P, T = Element> = EventHandler<P, FocusEvent<T>>;
104type FormEventHandler<P, T = Element> = EventHandler<P, FormEvent<T>>;
105type KeyboardEventHandler<P, T = Element> = EventHandler<P, KeyboardEvent<T>>;
106type MouseEventHandler<P, T = Element> = EventHandler<P, MouseEvent<T>>;
107type TouchEventHandler<P, T = Element> = EventHandler<P, TouchEvent<T>>;
108type PointerEventHandler<P, T = Element> = EventHandler<P, PointerEvent<T>>;
109type UIEventHandler<P, T = Element> = EventHandler<P, UIEvent<T>>;
110type WheelEventHandler<P, T = Element> = EventHandler<P, WheelEvent<T>>;
111type AnimationEventHandler<P, T = Element> = EventHandler<P, AnimationEvent<T>>;
112type TransitionEventHandler<P, T = Element> = EventHandler<P, TransitionEvent<T>>;
113
114export interface DOMAttributesWithProps<P, T> {
115 children?: ReactNode;
116 dangerouslySetInnerHTML?: {
117 __html: string;
118 };
119
120 // Clipboard Events
121 onCopy?: ClipboardEventHandler<P, T>;
122 onCopyCapture?: ClipboardEventHandler<P, T>;
123 onCut?: ClipboardEventHandler<P, T>;
124 onCutCapture?: ClipboardEventHandler<P, T>;
125 onPaste?: ClipboardEventHandler<P, T>;
126 onPasteCapture?: ClipboardEventHandler<P, T>;
127
128 // Composition Events
129 onCompositionEnd?: CompositionEventHandler<P, T>;
130 onCompositionEndCapture?: CompositionEventHandler<P, T>;
131 onCompositionStart?: CompositionEventHandler<P, T>;
132 onCompositionStartCapture?: CompositionEventHandler<P, T>;
133 onCompositionUpdate?: CompositionEventHandler<P, T>;
134 onCompositionUpdateCapture?: CompositionEventHandler<P, T>;
135
136 // Focus Events
137 onFocus?: FocusEventHandler<P, T>;
138 onFocusCapture?: FocusEventHandler<P, T>;
139 onBlur?: FocusEventHandler<P, T>;
140 onBlurCapture?: FocusEventHandler<P, T>;
141
142 // Form Events
143 onChange?: FormEventHandler<P, T>;
144 onChangeCapture?: FormEventHandler<P, T>;
145 onBeforeInput?: FormEventHandler<P, T>;
146 onBeforeInputCapture?: FormEventHandler<P, T>;
147 onInput?: FormEventHandler<P, T>;
148 onInputCapture?: FormEventHandler<P, T>;
149 onReset?: FormEventHandler<P, T>;
150 onResetCapture?: FormEventHandler<P, T>;
151 onSubmit?: FormEventHandler<P, T>;
152 onSubmitCapture?: FormEventHandler<P, T>;
153 onInvalid?: FormEventHandler<P, T>;
154 onInvalidCapture?: FormEventHandler<P, T>;
155
156 // Image Events
157 onLoad?: ReactEventHandler<P, T>;
158 onLoadCapture?: ReactEventHandler<P, T>;
159 onError?: ReactEventHandler<P, T>; // also a Media Event
160 onErrorCapture?: ReactEventHandler<P, T>; // also a Media Event
161
162 // Keyboard Events
163 onKeyDown?: KeyboardEventHandler<P, T>;
164 onKeyDownCapture?: KeyboardEventHandler<P, T>;
165 onKeyPress?: KeyboardEventHandler<P, T>;
166 onKeyPressCapture?: KeyboardEventHandler<P, T>;
167 onKeyUp?: KeyboardEventHandler<P, T>;
168 onKeyUpCapture?: KeyboardEventHandler<P, T>;
169
170 // Media Events
171 onAbort?: ReactEventHandler<P, T>;
172 onAbortCapture?: ReactEventHandler<P, T>;
173 onCanPlay?: ReactEventHandler<P, T>;
174 onCanPlayCapture?: ReactEventHandler<P, T>;
175 onCanPlayThrough?: ReactEventHandler<P, T>;
176 onCanPlayThroughCapture?: ReactEventHandler<P, T>;
177 onDurationChange?: ReactEventHandler<P, T>;
178 onDurationChangeCapture?: ReactEventHandler<P, T>;
179 onEmptied?: ReactEventHandler<P, T>;
180 onEmptiedCapture?: ReactEventHandler<P, T>;
181 onEncrypted?: ReactEventHandler<P, T>;
182 onEncryptedCapture?: ReactEventHandler<P, T>;
183 onEnded?: ReactEventHandler<P, T>;
184 onEndedCapture?: ReactEventHandler<P, T>;
185 onLoadedData?: ReactEventHandler<P, T>;
186 onLoadedDataCapture?: ReactEventHandler<P, T>;
187 onLoadedMetadata?: ReactEventHandler<P, T>;
188 onLoadedMetadataCapture?: ReactEventHandler<P, T>;
189 onLoadStart?: ReactEventHandler<P, T>;
190 onLoadStartCapture?: ReactEventHandler<P, T>;
191 onPause?: ReactEventHandler<P, T>;
192 onPauseCapture?: ReactEventHandler<P, T>;
193 onPlay?: ReactEventHandler<P, T>;
194 onPlayCapture?: ReactEventHandler<P, T>;
195 onPlaying?: ReactEventHandler<P, T>;
196 onPlayingCapture?: ReactEventHandler<P, T>;
197 onProgress?: ReactEventHandler<P, T>;
198 onProgressCapture?: ReactEventHandler<P, T>;
199 onRateChange?: ReactEventHandler<P, T>;
200 onRateChangeCapture?: ReactEventHandler<P, T>;
201 onSeeked?: ReactEventHandler<P, T>;
202 onSeekedCapture?: ReactEventHandler<P, T>;
203 onSeeking?: ReactEventHandler<P, T>;
204 onSeekingCapture?: ReactEventHandler<P, T>;
205 onStalled?: ReactEventHandler<P, T>;
206 onStalledCapture?: ReactEventHandler<P, T>;
207 onSuspend?: ReactEventHandler<P, T>;
208 onSuspendCapture?: ReactEventHandler<P, T>;
209 onTimeUpdate?: ReactEventHandler<P, T>;
210 onTimeUpdateCapture?: ReactEventHandler<P, T>;
211 onVolumeChange?: ReactEventHandler<P, T>;
212 onVolumeChangeCapture?: ReactEventHandler<P, T>;
213 onWaiting?: ReactEventHandler<P, T>;
214 onWaitingCapture?: ReactEventHandler<P, T>;
215
216 // MouseEvents
217 onAuxClick?: MouseEventHandler<P, T>;
218 onAuxClickCapture?: MouseEventHandler<P, T>;
219 onClick?: MouseEventHandler<P, T>;
220 onClickCapture?: MouseEventHandler<P, T>;
221 onContextMenu?: MouseEventHandler<P, T>;
222 onContextMenuCapture?: MouseEventHandler<P, T>;
223 onDoubleClick?: MouseEventHandler<P, T>;
224 onDoubleClickCapture?: MouseEventHandler<P, T>;
225 onDrag?: DragEventHandler<P, T>;
226 onDragCapture?: DragEventHandler<P, T>;
227 onDragEnd?: DragEventHandler<P, T>;
228 onDragEndCapture?: DragEventHandler<P, T>;
229 onDragEnter?: DragEventHandler<P, T>;
230 onDragEnterCapture?: DragEventHandler<P, T>;
231 onDragExit?: DragEventHandler<P, T>;
232 onDragExitCapture?: DragEventHandler<P, T>;
233 onDragLeave?: DragEventHandler<P, T>;
234 onDragLeaveCapture?: DragEventHandler<P, T>;
235 onDragOver?: DragEventHandler<P, T>;
236 onDragOverCapture?: DragEventHandler<P, T>;
237 onDragStart?: DragEventHandler<P, T>;
238 onDragStartCapture?: DragEventHandler<P, T>;
239 onDrop?: DragEventHandler<P, T>;
240 onDropCapture?: DragEventHandler<P, T>;
241 onMouseDown?: MouseEventHandler<P, T>;
242 onMouseDownCapture?: MouseEventHandler<P, T>;
243 onMouseEnter?: MouseEventHandler<P, T>;
244 onMouseLeave?: MouseEventHandler<P, T>;
245 onMouseMove?: MouseEventHandler<P, T>;
246 onMouseMoveCapture?: MouseEventHandler<P, T>;
247 onMouseOut?: MouseEventHandler<P, T>;
248 onMouseOutCapture?: MouseEventHandler<P, T>;
249 onMouseOver?: MouseEventHandler<P, T>;
250 onMouseOverCapture?: MouseEventHandler<P, T>;
251 onMouseUp?: MouseEventHandler<P, T>;
252 onMouseUpCapture?: MouseEventHandler<P, T>;
253
254 // Selection Events
255 onSelect?: ReactEventHandler<P, T>;
256 onSelectCapture?: ReactEventHandler<P, T>;
257
258 // Touch Events
259 onTouchCancel?: TouchEventHandler<P, T>;
260 onTouchCancelCapture?: TouchEventHandler<P, T>;
261 onTouchEnd?: TouchEventHandler<P, T>;
262 onTouchEndCapture?: TouchEventHandler<P, T>;
263 onTouchMove?: TouchEventHandler<P, T>;
264 onTouchMoveCapture?: TouchEventHandler<P, T>;
265 onTouchStart?: TouchEventHandler<P, T>;
266 onTouchStartCapture?: TouchEventHandler<P, T>;
267
268 // Pointer Events
269 onPointerDown?: PointerEventHandler<P, T>;
270 onPointerDownCapture?: PointerEventHandler<P, T>;
271 onPointerMove?: PointerEventHandler<P, T>;
272 onPointerMoveCapture?: PointerEventHandler<P, T>;
273 onPointerUp?: PointerEventHandler<P, T>;
274 onPointerUpCapture?: PointerEventHandler<P, T>;
275 onPointerCancel?: PointerEventHandler<P, T>;
276 onPointerCancelCapture?: PointerEventHandler<P, T>;
277 onPointerEnter?: PointerEventHandler<P, T>;
278 onPointerEnterCapture?: PointerEventHandler<P, T>;
279 onPointerLeave?: PointerEventHandler<P, T>;
280 onPointerLeaveCapture?: PointerEventHandler<P, T>;
281 onPointerOver?: PointerEventHandler<P, T>;
282 onPointerOverCapture?: PointerEventHandler<P, T>;
283 onPointerOut?: PointerEventHandler<P, T>;
284 onPointerOutCapture?: PointerEventHandler<P, T>;
285 onGotPointerCapture?: PointerEventHandler<P, T>;
286 onGotPointerCaptureCapture?: PointerEventHandler<P, T>;
287 onLostPointerCapture?: PointerEventHandler<P, T>;
288 onLostPointerCaptureCapture?: PointerEventHandler<P, T>;
289
290 // UI Events
291 onScroll?: UIEventHandler<P, T>;
292 onScrollCapture?: UIEventHandler<P, T>;
293
294 // Wheel Events
295 onWheel?: WheelEventHandler<P, T>;
296 onWheelCapture?: WheelEventHandler<P, T>;
297
298 // Animation Events
299 onAnimationStart?: AnimationEventHandler<P, T>;
300 onAnimationStartCapture?: AnimationEventHandler<P, T>;
301 onAnimationEnd?: AnimationEventHandler<P, T>;
302 onAnimationEndCapture?: AnimationEventHandler<P, T>;
303 onAnimationIteration?: AnimationEventHandler<P, T>;
304 onAnimationIterationCapture?: AnimationEventHandler<P, T>;
305
306 // Transition Events
307 onTransitionEnd?: TransitionEventHandler<P, T>;
308 onTransitionEndCapture?: TransitionEventHandler<P, T>;
309}
310
311type AdaptChildEventHandler<P, E extends SyntheticEvent<any>> = {
312 bivarianceHack(data: P, index: number, event: E): void;
313}['bivarianceHack'];
314
315type AdaptChildReactEventHandler<P, T = Element> = AdaptChildEventHandler<P, SyntheticEvent<T>>;
316type AdaptChildClipboardEventHandler<P, T = Element> = AdaptChildEventHandler<P, ClipboardEvent<T>>;
317type AdaptChildCompositionEventHandler<P, T = Element> = AdaptChildEventHandler<P, CompositionEvent<T>>;
318type AdaptChildDragEventHandler<P, T = Element> = AdaptChildEventHandler<P, DragEvent<T>>;
319type AdaptChildFocusEventHandler<P, T = Element> = AdaptChildEventHandler<P, FocusEvent<T>>;
320type AdaptChildFormEventHandler<P, T = Element> = AdaptChildEventHandler<P, FormEvent<T>>;
321type AdaptChildKeyboardEventHandler<P, T = Element> = AdaptChildEventHandler<P, KeyboardEvent<T>>;
322type AdaptChildMouseEventHandler<P, T = Element> = AdaptChildEventHandler<P, MouseEvent<T>>;
323type AdaptChildTouchEventHandler<P, T = Element> = AdaptChildEventHandler<P, TouchEvent<T>>;
324type AdaptChildPointerEventHandler<P, T = Element> = AdaptChildEventHandler<P, PointerEvent<T>>;
325type AdaptChildUIEventHandler<P, T = Element> = AdaptChildEventHandler<P, UIEvent<T>>;
326type AdaptChildWheelEventHandler<P, T = Element> = AdaptChildEventHandler<P, WheelEvent<T>>;
327type AdaptChildAnimationEventHandler<P, T = Element> = AdaptChildEventHandler<P, AnimationEvent<T>>;
328type AdaptChildTransitionEventHandler<P, T = Element> = AdaptChildEventHandler<P, TransitionEvent<T>>;
329
330export type DOMAttributesAdaptChildEvent<P, T> = {
331 children?: ReactNode;
332 dangerouslySetInnerHTML?: {
333 __html: string;
334 };
335
336 // Clipboard Events
337 onCopy?: AdaptChildClipboardEventHandler<P, T>;
338 onCopyCapture?: AdaptChildClipboardEventHandler<P, T>;
339 onCut?: AdaptChildClipboardEventHandler<P, T>;
340 onCutCapture?: AdaptChildClipboardEventHandler<P, T>;
341 onPaste?: AdaptChildClipboardEventHandler<P, T>;
342 onPasteCapture?: AdaptChildClipboardEventHandler<P, T>;
343
344 // Composition Events
345 onCompositionEnd?: AdaptChildCompositionEventHandler<P, T>;
346 onCompositionEndCapture?: AdaptChildCompositionEventHandler<P, T>;
347 onCompositionStart?: AdaptChildCompositionEventHandler<P, T>;
348 onCompositionStartCapture?: AdaptChildCompositionEventHandler<P, T>;
349 onCompositionUpdate?: AdaptChildCompositionEventHandler<P, T>;
350 onCompositionUpdateCapture?: AdaptChildCompositionEventHandler<P, T>;
351
352 // Focus Events
353 onFocus?: AdaptChildFocusEventHandler<P, T>;
354 onFocusCapture?: AdaptChildFocusEventHandler<P, T>;
355 onBlur?: AdaptChildFocusEventHandler<P, T>;
356 onBlurCapture?: AdaptChildFocusEventHandler<P, T>;
357
358 // Form Events
359 onChange?: AdaptChildFormEventHandler<P, T>;
360 onChangeCapture?: AdaptChildFormEventHandler<P, T>;
361 onBeforeInput?: AdaptChildFormEventHandler<P, T>;
362 onBeforeInputCapture?: AdaptChildFormEventHandler<P, T>;
363 onInput?: AdaptChildFormEventHandler<P, T>;
364 onInputCapture?: AdaptChildFormEventHandler<P, T>;
365 onReset?: AdaptChildFormEventHandler<P, T>;
366 onResetCapture?: AdaptChildFormEventHandler<P, T>;
367 onSubmit?: AdaptChildFormEventHandler<P, T>;
368 onSubmitCapture?: AdaptChildFormEventHandler<P, T>;
369 onInvalid?: AdaptChildFormEventHandler<P, T>;
370 onInvalidCapture?: AdaptChildFormEventHandler<P, T>;
371
372 // Image Events
373 onLoad?: AdaptChildReactEventHandler<P, T>;
374 onLoadCapture?: AdaptChildReactEventHandler<P, T>;
375 onError?: AdaptChildReactEventHandler<P, T>; // also a Media Event
376 onErrorCapture?: AdaptChildReactEventHandler<P, T>; // also a Media Event
377
378 // Keyboard Events
379 onKeyDown?: AdaptChildKeyboardEventHandler<P, T>;
380 onKeyDownCapture?: AdaptChildKeyboardEventHandler<P, T>;
381 onKeyPress?: AdaptChildKeyboardEventHandler<P, T>;
382 onKeyPressCapture?: AdaptChildKeyboardEventHandler<P, T>;
383 onKeyUp?: AdaptChildKeyboardEventHandler<P, T>;
384 onKeyUpCapture?: AdaptChildKeyboardEventHandler<P, T>;
385
386 // Media Events
387 onAbort?: AdaptChildReactEventHandler<P, T>;
388 onAbortCapture?: AdaptChildReactEventHandler<P, T>;
389 onCanPlay?: AdaptChildReactEventHandler<P, T>;
390 onCanPlayCapture?: AdaptChildReactEventHandler<P, T>;
391 onCanPlayThrough?: AdaptChildReactEventHandler<P, T>;
392 onCanPlayThroughCapture?: AdaptChildReactEventHandler<P, T>;
393 onDurationChange?: AdaptChildReactEventHandler<P, T>;
394 onDurationChangeCapture?: AdaptChildReactEventHandler<P, T>;
395 onEmptied?: AdaptChildReactEventHandler<P, T>;
396 onEmptiedCapture?: AdaptChildReactEventHandler<P, T>;
397 onEncrypted?: AdaptChildReactEventHandler<P, T>;
398 onEncryptedCapture?: AdaptChildReactEventHandler<P, T>;
399 onEnded?: AdaptChildReactEventHandler<P, T>;
400 onEndedCapture?: AdaptChildReactEventHandler<P, T>;
401 onLoadedData?: AdaptChildReactEventHandler<P, T>;
402 onLoadedDataCapture?: AdaptChildReactEventHandler<P, T>;
403 onLoadedMetadata?: AdaptChildReactEventHandler<P, T>;
404 onLoadedMetadataCapture?: AdaptChildReactEventHandler<P, T>;
405 onLoadStart?: AdaptChildReactEventHandler<P, T>;
406 onLoadStartCapture?: AdaptChildReactEventHandler<P, T>;
407 onPause?: AdaptChildReactEventHandler<P, T>;
408 onPauseCapture?: AdaptChildReactEventHandler<P, T>;
409 onPlay?: AdaptChildReactEventHandler<P, T>;
410 onPlayCapture?: AdaptChildReactEventHandler<P, T>;
411 onPlaying?: AdaptChildReactEventHandler<P, T>;
412 onPlayingCapture?: AdaptChildReactEventHandler<P, T>;
413 onProgress?: AdaptChildReactEventHandler<P, T>;
414 onProgressCapture?: AdaptChildReactEventHandler<P, T>;
415 onRateChange?: AdaptChildReactEventHandler<P, T>;
416 onRateChangeCapture?: AdaptChildReactEventHandler<P, T>;
417 onSeeked?: AdaptChildReactEventHandler<P, T>;
418 onSeekedCapture?: AdaptChildReactEventHandler<P, T>;
419 onSeeking?: AdaptChildReactEventHandler<P, T>;
420 onSeekingCapture?: AdaptChildReactEventHandler<P, T>;
421 onStalled?: AdaptChildReactEventHandler<P, T>;
422 onStalledCapture?: AdaptChildReactEventHandler<P, T>;
423 onSuspend?: AdaptChildReactEventHandler<P, T>;
424 onSuspendCapture?: AdaptChildReactEventHandler<P, T>;
425 onTimeUpdate?: AdaptChildReactEventHandler<P, T>;
426 onTimeUpdateCapture?: AdaptChildReactEventHandler<P, T>;
427 onVolumeChange?: AdaptChildReactEventHandler<P, T>;
428 onVolumeChangeCapture?: AdaptChildReactEventHandler<P, T>;
429 onWaiting?: AdaptChildReactEventHandler<P, T>;
430 onWaitingCapture?: AdaptChildReactEventHandler<P, T>;
431
432 // MouseEvents
433 onAuxClick?: AdaptChildMouseEventHandler<P, T>;
434 onAuxClickCapture?: AdaptChildMouseEventHandler<P, T>;
435 onClick?: AdaptChildMouseEventHandler<P, T>;
436 onClickCapture?: AdaptChildMouseEventHandler<P, T>;
437 onContextMenu?: AdaptChildMouseEventHandler<P, T>;
438 onContextMenuCapture?: AdaptChildMouseEventHandler<P, T>;
439 onDoubleClick?: AdaptChildMouseEventHandler<P, T>;
440 onDoubleClickCapture?: AdaptChildMouseEventHandler<P, T>;
441 onDrag?: AdaptChildDragEventHandler<P, T>;
442 onDragCapture?: AdaptChildDragEventHandler<P, T>;
443 onDragEnd?: AdaptChildDragEventHandler<P, T>;
444 onDragEndCapture?: AdaptChildDragEventHandler<P, T>;
445 onDragEnter?: AdaptChildDragEventHandler<P, T>;
446 onDragEnterCapture?: AdaptChildDragEventHandler<P, T>;
447 onDragExit?: AdaptChildDragEventHandler<P, T>;
448 onDragExitCapture?: AdaptChildDragEventHandler<P, T>;
449 onDragLeave?: AdaptChildDragEventHandler<P, T>;
450 onDragLeaveCapture?: AdaptChildDragEventHandler<P, T>;
451 onDragOver?: AdaptChildDragEventHandler<P, T>;
452 onDragOverCapture?: AdaptChildDragEventHandler<P, T>;
453 onDragStart?: AdaptChildDragEventHandler<P, T>;
454 onDragStartCapture?: AdaptChildDragEventHandler<P, T>;
455 onDrop?: AdaptChildDragEventHandler<P, T>;
456 onDropCapture?: AdaptChildDragEventHandler<P, T>;
457 onMouseDown?: AdaptChildMouseEventHandler<P, T>;
458 onMouseDownCapture?: AdaptChildMouseEventHandler<P, T>;
459 onMouseEnter?: AdaptChildMouseEventHandler<P, T>;
460 onMouseLeave?: AdaptChildMouseEventHandler<P, T>;
461 onMouseMove?: AdaptChildMouseEventHandler<P, T>;
462 onMouseMoveCapture?: AdaptChildMouseEventHandler<P, T>;
463 onMouseOut?: AdaptChildMouseEventHandler<P, T>;
464 onMouseOutCapture?: AdaptChildMouseEventHandler<P, T>;
465 onMouseOver?: AdaptChildMouseEventHandler<P, T>;
466 onMouseOverCapture?: AdaptChildMouseEventHandler<P, T>;
467 onMouseUp?: AdaptChildMouseEventHandler<P, T>;
468 onMouseUpCapture?: AdaptChildMouseEventHandler<P, T>;
469
470 // Selection Events
471 onSelect?: AdaptChildReactEventHandler<P, T>;
472 onSelectCapture?: AdaptChildReactEventHandler<P, T>;
473
474 // Touch Events
475 onTouchCancel?: AdaptChildTouchEventHandler<P, T>;
476 onTouchCancelCapture?: AdaptChildTouchEventHandler<P, T>;
477 onTouchEnd?: AdaptChildTouchEventHandler<P, T>;
478 onTouchEndCapture?: AdaptChildTouchEventHandler<P, T>;
479 onTouchMove?: AdaptChildTouchEventHandler<P, T>;
480 onTouchMoveCapture?: AdaptChildTouchEventHandler<P, T>;
481 onTouchStart?: AdaptChildTouchEventHandler<P, T>;
482 onTouchStartCapture?: AdaptChildTouchEventHandler<P, T>;
483
484 // Pointer Events
485 onPointerDown?: AdaptChildPointerEventHandler<P, T>;
486 onPointerDownCapture?: AdaptChildPointerEventHandler<P, T>;
487 onPointerMove?: AdaptChildPointerEventHandler<P, T>;
488 onPointerMoveCapture?: AdaptChildPointerEventHandler<P, T>;
489 onPointerUp?: AdaptChildPointerEventHandler<P, T>;
490 onPointerUpCapture?: AdaptChildPointerEventHandler<P, T>;
491 onPointerCancel?: AdaptChildPointerEventHandler<P, T>;
492 onPointerCancelCapture?: AdaptChildPointerEventHandler<P, T>;
493 onPointerEnter?: AdaptChildPointerEventHandler<P, T>;
494 onPointerEnterCapture?: AdaptChildPointerEventHandler<P, T>;
495 onPointerLeave?: AdaptChildPointerEventHandler<P, T>;
496 onPointerLeaveCapture?: AdaptChildPointerEventHandler<P, T>;
497 onPointerOver?: AdaptChildPointerEventHandler<P, T>;
498 onPointerOverCapture?: AdaptChildPointerEventHandler<P, T>;
499 onPointerOut?: AdaptChildPointerEventHandler<P, T>;
500 onPointerOutCapture?: AdaptChildPointerEventHandler<P, T>;
501 onGotPointerCapture?: AdaptChildPointerEventHandler<P, T>;
502 onGotPointerCaptureCapture?: AdaptChildPointerEventHandler<P, T>;
503 onLostPointerCapture?: AdaptChildPointerEventHandler<P, T>;
504 onLostPointerCaptureCapture?: AdaptChildPointerEventHandler<P, T>;
505
506 // UI Events
507 onScroll?: AdaptChildUIEventHandler<P, T>;
508 onScrollCapture?: AdaptChildUIEventHandler<P, T>;
509
510 // Wheel Events
511 onWheel?: AdaptChildWheelEventHandler<P, T>;
512 onWheelCapture?: AdaptChildWheelEventHandler<P, T>;
513
514 // Animation Events
515 onAnimationStart?: AdaptChildAnimationEventHandler<P, T>;
516 onAnimationStartCapture?: AdaptChildAnimationEventHandler<P, T>;
517 onAnimationEnd?: AdaptChildAnimationEventHandler<P, T>;
518 onAnimationEndCapture?: AdaptChildAnimationEventHandler<P, T>;
519 onAnimationIteration?: AdaptChildAnimationEventHandler<P, T>;
520 onAnimationIterationCapture?: AdaptChildAnimationEventHandler<P, T>;
521
522 // Transition Events
523 onTransitionEnd?: AdaptChildTransitionEventHandler<P, T>;
524 onTransitionEndCapture?: AdaptChildTransitionEventHandler<P, T>;
525};
526const SVGContainerPropKeys = ['viewBox', 'children'];
527const SVGElementPropKeys = [
528 'className',
529 'color',
530 'height',
531 'id',
532 'lang',
533 'max',
534 'media',
535 'method',
536 'min',
537 'name',
538 'style',
539 'target',
540 'type',
541 'width',
542 'role',
543 'tabIndex',
544 'accentHeight',
545 'accumulate',
546 'additive',
547 'alignmentBaseline',
548 'allowReorder',
549 'alphabetic',
550 'amplitude',
551 'arabicForm',
552 'ascent',
553 'attributeName',
554 'attributeType',
555 'autoReverse',
556 'azimuth',
557 'baseFrequency',
558 'baselineShift',
559 'baseProfile',
560 'bbox',
561 'begin',
562 'bias',
563 'by',
564 'calcMode',
565 'capHeight',
566 'clip',
567 'clipPath',
568 'clipPathUnits',
569 'clipRule',
570 'colorInterpolation',
571 'colorInterpolationFilters',
572 'colorProfile',
573 'colorRendering',
574 'contentScriptType',
575 'contentStyleType',
576 'cursor',
577 'cx',
578 'cy',
579 'd',
580 'decelerate',
581 'descent',
582 'diffuseConstant',
583 'direction',
584 'display',
585 'divisor',
586 'dominantBaseline',
587 'dur',
588 'dx',
589 'dy',
590 'edgeMode',
591 'elevation',
592 'enableBackground',
593 'end',
594 'exponent',
595 'externalResourcesRequired',
596 'fill',
597 'fillOpacity',
598 'fillRule',
599 'filter',
600 'filterRes',
601 'filterUnits',
602 'floodColor',
603 'floodOpacity',
604 'focusable',
605 'fontFamily',
606 'fontSize',
607 'fontSizeAdjust',
608 'fontStretch',
609 'fontStyle',
610 'fontVariant',
611 'fontWeight',
612 'format',
613 'from',
614 'fx',
615 'fy',
616 'g1',
617 'g2',
618 'glyphName',
619 'glyphOrientationHorizontal',
620 'glyphOrientationVertical',
621 'glyphRef',
622 'gradientTransform',
623 'gradientUnits',
624 'hanging',
625 'horizAdvX',
626 'horizOriginX',
627 'href',
628 'ideographic',
629 'imageRendering',
630 'in2',
631 'in',
632 'intercept',
633 'k1',
634 'k2',
635 'k3',
636 'k4',
637 'k',
638 'kernelMatrix',
639 'kernelUnitLength',
640 'kerning',
641 'keyPoints',
642 'keySplines',
643 'keyTimes',
644 'lengthAdjust',
645 'letterSpacing',
646 'lightingColor',
647 'limitingConeAngle',
648 'local',
649 'markerEnd',
650 'markerHeight',
651 'markerMid',
652 'markerStart',
653 'markerUnits',
654 'markerWidth',
655 'mask',
656 'maskContentUnits',
657 'maskUnits',
658 'mathematical',
659 'mode',
660 'numOctaves',
661 'offset',
662 'opacity',
663 'operator',
664 'order',
665 'orient',
666 'orientation',
667 'origin',
668 'overflow',
669 'overlinePosition',
670 'overlineThickness',
671 'paintOrder',
672 'panose1',
673 'pathLength',
674 'patternContentUnits',
675 'patternTransform',
676 'patternUnits',
677 'pointerEvents',
678 'points',
679 'pointsAtX',
680 'pointsAtY',
681 'pointsAtZ',
682 'preserveAlpha',
683 'preserveAspectRatio',
684 'primitiveUnits',
685 'r',
686 'radius',
687 'refX',
688 'refY',
689 'renderingIntent',
690 'repeatCount',
691 'repeatDur',
692 'requiredExtensions',
693 'requiredFeatures',
694 'restart',
695 'result',
696 'rotate',
697 'rx',
698 'ry',
699 'seed',
700 'shapeRendering',
701 'slope',
702 'spacing',
703 'specularConstant',
704 'specularExponent',
705 'speed',
706 'spreadMethod',
707 'startOffset',
708 'stdDeviation',
709 'stemh',
710 'stemv',
711 'stitchTiles',
712 'stopColor',
713 'stopOpacity',
714 'strikethroughPosition',
715 'strikethroughThickness',
716 'string',
717 'stroke',
718 'strokeDasharray',
719 'strokeDashoffset',
720 'strokeLinecap',
721 'strokeLinejoin',
722 'strokeMiterlimit',
723 'strokeOpacity',
724 'strokeWidth',
725 'surfaceScale',
726 'systemLanguage',
727 'tableValues',
728 'targetX',
729 'targetY',
730 'textAnchor',
731 'textDecoration',
732 'textLength',
733 'textRendering',
734 'to',
735 'transform',
736 'u1',
737 'u2',
738 'underlinePosition',
739 'underlineThickness',
740 'unicode',
741 'unicodeBidi',
742 'unicodeRange',
743 'unitsPerEm',
744 'vAlphabetic',
745 'values',
746 'vectorEffect',
747 'version',
748 'vertAdvY',
749 'vertOriginX',
750 'vertOriginY',
751 'vHanging',
752 'vIdeographic',
753 'viewTarget',
754 'visibility',
755 'vMathematical',
756 'widths',
757 'wordSpacing',
758 'writingMode',
759 'x1',
760 'x2',
761 'x',
762 'xChannelSelector',
763 'xHeight',
764 'xlinkActuate',
765 'xlinkArcrole',
766 'xlinkHref',
767 'xlinkRole',
768 'xlinkShow',
769 'xlinkTitle',
770 'xlinkType',
771 'xmlBase',
772 'xmlLang',
773 'xmlns',
774 'xmlnsXlink',
775 'xmlSpace',
776 'y1',
777 'y2',
778 'y',
779 'yChannelSelector',
780 'z',
781 'zoomAndPan',
782 'ref',
783 'key',
784 'angle',
785];
786
787const EventKeys = [
788 'dangerouslySetInnerHTML',
789 'onCopy',
790 'onCopyCapture',
791 'onCut',
792 'onCutCapture',
793 'onPaste',
794 'onPasteCapture',
795 'onCompositionEnd',
796 'onCompositionEndCapture',
797 'onCompositionStart',
798 'onCompositionStartCapture',
799 'onCompositionUpdate',
800 'onCompositionUpdateCapture',
801 'onFocus',
802 'onFocusCapture',
803 'onBlur',
804 'onBlurCapture',
805 'onChange',
806 'onChangeCapture',
807 'onBeforeInput',
808 'onBeforeInputCapture',
809 'onInput',
810 'onInputCapture',
811 'onReset',
812 'onResetCapture',
813 'onSubmit',
814 'onSubmitCapture',
815 'onInvalid',
816 'onInvalidCapture',
817 'onLoad',
818 'onLoadCapture',
819 'onError',
820 'onErrorCapture',
821 'onKeyDown',
822 'onKeyDownCapture',
823 'onKeyPress',
824 'onKeyPressCapture',
825 'onKeyUp',
826 'onKeyUpCapture',
827 'onAbort',
828 'onAbortCapture',
829 'onCanPlay',
830 'onCanPlayCapture',
831 'onCanPlayThrough',
832 'onCanPlayThroughCapture',
833 'onDurationChange',
834 'onDurationChangeCapture',
835 'onEmptied',
836 'onEmptiedCapture',
837 'onEncrypted',
838 'onEncryptedCapture',
839 'onEnded',
840 'onEndedCapture',
841 'onLoadedData',
842 'onLoadedDataCapture',
843 'onLoadedMetadata',
844 'onLoadedMetadataCapture',
845 'onLoadStart',
846 'onLoadStartCapture',
847 'onPause',
848 'onPauseCapture',
849 'onPlay',
850 'onPlayCapture',
851 'onPlaying',
852 'onPlayingCapture',
853 'onProgress',
854 'onProgressCapture',
855 'onRateChange',
856 'onRateChangeCapture',
857 'onSeeked',
858 'onSeekedCapture',
859 'onSeeking',
860 'onSeekingCapture',
861 'onStalled',
862 'onStalledCapture',
863 'onSuspend',
864 'onSuspendCapture',
865 'onTimeUpdate',
866 'onTimeUpdateCapture',
867 'onVolumeChange',
868 'onVolumeChangeCapture',
869 'onWaiting',
870 'onWaitingCapture',
871 'onAuxClick',
872 'onAuxClickCapture',
873 'onClick',
874 'onClickCapture',
875 'onContextMenu',
876 'onContextMenuCapture',
877 'onDoubleClick',
878 'onDoubleClickCapture',
879 'onDrag',
880 'onDragCapture',
881 'onDragEnd',
882 'onDragEndCapture',
883 'onDragEnter',
884 'onDragEnterCapture',
885 'onDragExit',
886 'onDragExitCapture',
887 'onDragLeave',
888 'onDragLeaveCapture',
889 'onDragOver',
890 'onDragOverCapture',
891 'onDragStart',
892 'onDragStartCapture',
893 'onDrop',
894 'onDropCapture',
895 'onMouseDown',
896 'onMouseDownCapture',
897 'onMouseEnter',
898 'onMouseLeave',
899 'onMouseMove',
900 'onMouseMoveCapture',
901 'onMouseOut',
902 'onMouseOutCapture',
903 'onMouseOver',
904 'onMouseOverCapture',
905 'onMouseUp',
906 'onMouseUpCapture',
907 'onSelect',
908 'onSelectCapture',
909 'onTouchCancel',
910 'onTouchCancelCapture',
911 'onTouchEnd',
912 'onTouchEndCapture',
913 'onTouchMove',
914 'onTouchMoveCapture',
915 'onTouchStart',
916 'onTouchStartCapture',
917 'onPointerDown',
918 'onPointerDownCapture',
919 'onPointerMove',
920 'onPointerMoveCapture',
921 'onPointerUp',
922 'onPointerUpCapture',
923 'onPointerCancel',
924 'onPointerCancelCapture',
925 'onPointerEnter',
926 'onPointerEnterCapture',
927 'onPointerLeave',
928 'onPointerLeaveCapture',
929 'onPointerOver',
930 'onPointerOverCapture',
931 'onPointerOut',
932 'onPointerOutCapture',
933 'onGotPointerCapture',
934 'onGotPointerCaptureCapture',
935 'onLostPointerCapture',
936 'onLostPointerCaptureCapture',
937 'onScroll',
938 'onScrollCapture',
939 'onWheel',
940 'onWheelCapture',
941 'onAnimationStart',
942 'onAnimationStartCapture',
943 'onAnimationEnd',
944 'onAnimationEndCapture',
945 'onAnimationIteration',
946 'onAnimationIterationCapture',
947 'onTransitionEnd',
948 'onTransitionEndCapture',
949];
950
951// Animation Types => TODO: Should be moved when react-smooth is typescriptified.
952export type AnimationTiming = 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'linear';
953
954/** the offset of a chart, which define the blank space all around */
955export interface ChartOffset {
956 top?: number;
957 bottom?: number;
958 left?: number;
959 right?: number;
960 width?: number;
961 height?: number;
962 brushBottom?: number;
963}
964
965export interface Padding {
966 top?: number;
967 bottom?: number;
968 left?: number;
969 right?: number;
970}
971
972export interface GeometrySector {
973 cx?: number;
974 cy?: number;
975 innerRadius?: number;
976 outerRadius?: number;
977 startAngle?: number;
978 endAngle?: number;
979 cornerRadius?: number;
980 forceCornerRadius?: boolean;
981 cornerIsExternal?: boolean;
982}
983
984export type D3Scale<T> = D3ScaleContinuousNumeric<T, number>;
985
986export type AxisDomainItem = string | number | Function | 'auto' | 'dataMin' | 'dataMax';
987/** The domain of axis */
988export type AxisDomain = string[] | number[] | [AxisDomainItem, AxisDomainItem];
989
990/** The props definition of base axis */
991export interface BaseAxisProps {
992 /** The type of axis */
993 type?: 'number' | 'category';
994 /** The key of data displayed in the axis */
995 dataKey?: DataKey<any>;
996 /** Whether or not display the axis */
997 hide?: boolean;
998 /** The scale type or functor of scale */
999 scale?: ScaleType | Function;
1000 /** The option for tick */
1001 tick?: SVGProps<SVGTextElement> | ReactElement<SVGElement> | ((props: any) => ReactElement<SVGElement>) | boolean;
1002 /** The count of ticks */
1003 tickCount?: number;
1004 /** The option for axisLine */
1005 axisLine?: boolean | SVGProps<SVGLineElement>;
1006 /** The option for tickLine */
1007 tickLine?: boolean | SVGProps<SVGTextElement>;
1008 /** The size of tick line */
1009 tickSize?: number;
1010 /** The formatter function of tick */
1011 tickFormatter?: (value: any, index: number) => string;
1012 /**
1013 * When domain of the axis is specified and the type of the axis is 'number',
1014 * if allowDataOverflow is set to be false,
1015 * the domain will be adjusted when the minimum value of data is smaller than domain[0] or
1016 * the maximum value of data is greater than domain[1] so that the axis displays all data values.
1017 * If set to true, graphic elements (line, area, bars) will be clipped to conform to the specified domain.
1018 */
1019 allowDataOverflow?: boolean;
1020 /**
1021 * Allow the axis has duplicated categorys or not when the type of axis is "category".
1022 */
1023 allowDuplicatedCategory?: boolean;
1024 /**
1025 * Allow the ticks of axis to be decimals or not.
1026 */
1027 allowDecimals?: boolean;
1028 /** The domain of scale in this axis */
1029 domain?: AxisDomain;
1030 /** The name of data displayed in the axis */
1031 name?: string;
1032 /** The unit of data displayed in the axis */
1033 unit?: string | number;
1034 /** The type of axis */
1035 axisType?: AxisType;
1036 range?: Array<number>;
1037 /** axis react component */
1038 AxisComp?: any;
1039 /** Needed to allow usage of the label prop on the X and Y axis */
1040 label?: string | number | ReactElement | object;
1041}
1042
1043export type AxisInterval = number | 'preserveStart' | 'preserveEnd' | 'preserveStartEnd';
1044
1045export interface TickItem {
1046 value?: any;
1047 coordinate: number;
1048 index?: number;
1049}
1050
1051export interface Margin {
1052 top?: number;
1053 right?: number;
1054 bottom?: number;
1055 left?: number;
1056}
1057
1058export interface CartesianViewBox {
1059 x?: number;
1060 y?: number;
1061 width?: number;
1062 height?: number;
1063}
1064
1065export interface PolarViewBox {
1066 cx?: number;
1067 cy?: number;
1068 innerRadius?: number;
1069 outerRadius?: number;
1070 startAngle?: number;
1071 endAngle?: number;
1072 clockWise?: boolean;
1073}
1074
1075export type ViewBox = CartesianViewBox | PolarViewBox;
1076
1077export const filterProps = (
1078 props: Record<string, any> | Component | FunctionComponent | boolean,
1079 includeEvents?: boolean,
1080 isSvg?: boolean,
1081) => {
1082 if (!props || typeof props === 'function' || typeof props === 'boolean') {
1083 return null;
1084 }
1085
1086 let inputProps = props as Record<string, any>;
1087
1088 if (isValidElement(props)) {
1089 inputProps = props.props as Record<string, any>;
1090 }
1091
1092 if (!_.isObject(inputProps)) {
1093 return null;
1094 }
1095
1096 const out: Record<string, any> = {};
1097
1098 Object.keys(inputProps).forEach(key => {
1099 // viewBox only exist in <svg />
1100 if (
1101 SVGElementPropKeys.includes(key) ||
1102 (isSvg && SVGContainerPropKeys.includes(key)) ||
1103 (includeEvents && EventKeys.includes(key))
1104 ) {
1105 out[key] = (inputProps as any)[key];
1106 }
1107 });
1108
1109 return out;
1110};
1111
1112export const adaptEventHandlers = (
1113 props: Record<string, any> | Component | FunctionComponent | boolean,
1114 newHandler?: (e?: Event) => any,
1115): Record<string, (e?: Event) => any> => {
1116 if (!props || typeof props === 'function' || typeof props === 'boolean') {
1117 return null;
1118 }
1119
1120 let inputProps = props as Record<string, any>;
1121
1122 if (isValidElement(props)) {
1123 inputProps = props.props as Record<string, any>;
1124 }
1125
1126 if (!_.isObject(inputProps)) {
1127 return null;
1128 }
1129
1130 const out: Record<string, (e: Event) => void> = {};
1131
1132 Object.keys(inputProps).forEach(key => {
1133 if (EventKeys.includes(key)) {
1134 out[key] = newHandler || ((e: Event) => inputProps[key](inputProps, e));
1135 }
1136 });
1137
1138 return out;
1139};
1140
1141const getEventHandlerOfChild = (originalHandler: Function, data: any, index: number) => (e: Event): void => {
1142 originalHandler(data, index, e);
1143
1144 return null;
1145};
1146
1147export const adaptEventsOfChild = (
1148 props: Record<string, any>,
1149 data: any,
1150 index: number,
1151): Record<string, (e?: Event) => any> => {
1152 if (!_.isObject(props) || typeof props !== 'object') {
1153 return null;
1154 }
1155
1156 let out: Record<string, (e: Event) => void> = null;
1157
1158 Object.keys(props).forEach((key: string) => {
1159 const item = (props as any)[key];
1160 if (EventKeys.includes(key) && typeof item === 'function') {
1161 if (!out) out = {};
1162 out[key] = getEventHandlerOfChild(item, data, index);
1163 }
1164 });
1165 return out;
1166};
1167
1168export interface CategoricalChartOptions {
1169 chartName?: string;
1170 GraphicalChild?: any;
1171 defaultTooltipEventType?: string;
1172 validateTooltipEventTypes?: string[];
1173 axisComponents?: BaseAxisProps[];
1174 legendContent?: any;
1175 formatAxisMap?: any;
1176 defaultProps?: any;
1177}
1178
1179export interface TreemapNode {
1180 x: number;
1181 y: number;
1182 width: number;
1183 height: number;
1184 depth: number;
1185 index: number;
1186 children?: any;
1187 name: string;
1188 value: number;
1189 [k: string]: any;
1190}
1191
1192export interface SankeyNode {
1193 x: number;
1194 y: number;
1195 dx: number;
1196 dy: number;
1197 depth: number;
1198 value: number;
1199}
1200export interface SankeyLink {
1201 target: number;
1202 source: number;
1203 value: number;
1204 sy: number;
1205 dy: number;
1206 ty: number;
1207}