forked from patternfly/patternfly-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChartBoxPlot.tsx
More file actions
699 lines (694 loc) · 31.4 KB
/
ChartBoxPlot.tsx
File metadata and controls
699 lines (694 loc) · 31.4 KB
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
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
import { cloneElement } from 'react';
import hoistNonReactStatics from 'hoist-non-react-statics';
import {
AnimatePropTypeInterface,
CategoryPropType,
D3Scale,
DataGetterPropType,
DomainPropType,
DomainPaddingPropType,
EventCallbackInterface,
EventPropTypeInterface,
OriginType,
PaddingProps,
RangePropType,
ScalePropType,
SortOrderPropType,
StringOrNumberOrCallback,
StringOrNumberOrList,
VictoryStyleInterface,
OrientationTypes
} from 'victory-core';
import {
VictoryBoxPlot,
VictoryBoxPlotLabelOrientationInterface,
VictoryBoxPlotLabelType,
VictoryBoxPlotProps
} from 'victory-box-plot';
import { ChartContainer } from '../ChartContainer/ChartContainer';
import { ChartThemeDefinition } from '../ChartTheme/ChartTheme';
import { getTheme } from '../ChartUtils/chart-theme';
/**
* ChartBoxPlot renders a box plot to describe the distribution of a set of data. Data for ChartBoxPlot may be given
* with summary statistics pre-calculated (min, median, max, q1, q3), or as an array of raw data. ChartBoxPlot can be
* composed with Chart to create box plot charts.
*
* See https://github.com/FormidableLabs/victory/blob/main/packages/victory-bar/src/index.d.ts
*
*/
export interface ChartBoxPlotProps extends VictoryBoxPlotProps {
/**
* The animate prop specifies props for VictoryAnimation to use.
* The animate prop should also be used to specify enter and exit
* transition configurations with the `onExit` and `onEnter` namespaces respectively.
*
* @propType boolean | object
* @example {duration: 500, onExit: () => {}, onEnter: {duration: 500, before: () => ({y: 0})})}
*/
animate?: boolean | AnimatePropTypeInterface;
/**
* The boxWidth prop specifies how wide each box should be. If the whiskerWidth prop is not set, this prop will also
* determine the width of the whisker crosshair.
*/
boxWidth?: number;
/**
* The categories prop specifies how categorical data for a chart should be ordered.
* This prop should be given as an array of string values, or an object with
* these arrays of values specified for x and y. If this prop is not set,
* categorical data will be plotted in the order it was given in the data array
*
* @propType string[] | { x: string[], y: string[] }
* @example ["dogs", "cats", "mice"]
*/
categories?: CategoryPropType;
/**
* The containerComponent prop takes an entire component which will be used to
* create a container element for standalone charts.
* The new element created from the passed containerComponent wil be provided with
* these props from ChartBoxPlot: height, width, children
* (the chart itself) and style. Props that are not provided by the
* child chart component include title and desc, both of which
* are intended to add accessibility to Victory components. The more descriptive these props
* are, the more accessible your data will be for people using screen readers.
* Any of these props may be overridden by passing in props to the supplied component,
* or modified or ignored within the custom component itself. If a dataComponent is
* not provided, ChartBoxPlot will use the default ChartContainer component.
*
* @example <ChartContainer title="Chart of Dog Breeds" desc="This chart shows..." />
*/
containerComponent?: React.ReactElement<any>;
/**
* The data prop for ChartBoxPlot may be given in a variety of formats:
*
* @example
* As an array of standard data objects with values specified for x and y When given in this format, repeated values
* for x will be used for calculating summary statistics
*
* data={[
* { x: 1, y: 2 },
* { x: 1, y: 3 },
* { x: 1, y: 5 },
* { x: 2, y: 1 },
* { x: 2, y: 4 },
* { x: 2, y: 5 },
* ...
* ]}
*
* @example As an array of data objects where y is given as an array of values When given in this format, array values
* are used for calculating summary statistics.
*
* data={[
* { x: 1, y: [1, 2, 3, 5] },
* { x: 2, y: [3, 2, 8, 10] },
* { x: 3, y: [2, 8, 6, 5] },
* { x: 4, y: [1, 3, 2, 9] }
* ]}
*
* @example As an array of data objects with pre-calculated summary statistics(min, median, max, q1, q3) When given in
* this format, ChartBoxPlot will not perform statistical analysis. Pre-calculating summary statistics for large
* datasets will improve performance.
*
* data={[
* { x: 1, min: 2, median: 5, max: 10, q1: 3, q3: 7 },
* { x: 2, min: 1, median: 4, max: 9, q1: 3, q3: 6 },
* { x: 3, min: 1, median: 6, max: 12, q1: 4, q3: 10 },
* ]}
*
* Use the x, y, min, max, median, q1, and q3 data accessor props to specify custom data formats.
*/
data?: any[];
/**
* The domain prop describes the range of values your chart will cover. This prop can be
* given as a array of the minimum and maximum expected values for your bar chart,
* or as an object that specifies separate arrays for x and y.
* If this prop is not provided, a domain will be calculated from data, or other
* available information.
*
* @propType number[] | { x: number[], y: number[] }
* @example [low, high], { x: [low, high], y: [low, high] }
*
* [-1, 1], {x: [0, 100], y: [0, 1]}
*/
domain?: DomainPropType;
/**
* The domainPadding prop specifies a number of pixels of padding to add to the
* beginning and end of a domain. This prop is useful for explicitly spacing ticks farther
* from the origin to prevent crowding. This prop should be given as an object with
* numbers specified for x and y.
*
* @propType number | number[] | { x: number[], y: number[] }
* @example [left, right], { x: [left, right], y: [bottom, top] }
*
* {x: [10, -10], y: 5}
*/
domainPadding?: DomainPaddingPropType;
/**
* Similar to data accessor props `x` and `y`, this prop may be used to functionally
* assign eventKeys to data
*
* @propType number | string | Function
*/
eventKey?: StringOrNumberOrCallback;
/**
* The event prop take an array of event objects. Event objects are composed of
* a target, an eventKey, and eventHandlers. Targets may be any valid style namespace
* for a given component, so "data" and "labels" are all valid targets for ChartBoxPlot events.
* The eventKey may optionally be used to select a single element by index rather than an entire
* set. The eventHandlers object should be given as an object whose keys are standard
* event names (i.e. onClick) and whose values are event callbacks. The return value
* of an event handler is used to modify elements. The return value should be given
* as an object or an array of objects with optional target and eventKey keys,
* and a mutation key whose value is a function. The target and eventKey keys
* will default to those corresponding to the element the event handler was attached to.
* The mutation function will be called with the calculated props for the individual selected
* element (i.e. a single bar), and the object returned from the mutation function
* will override the props of the selected element via object assignment.
*
* @propType object[]
* @example
*
* events={[
* {
* target: "data",
* eventKey: "thisOne",
* eventHandlers: {
* onClick: () => {
* return [
* {
* eventKey: "theOtherOne",
* mutation: (props) => {
* return {style: merge({}, props.style, {fill: "orange"})};
* }
* }, {
* eventKey: "theOtherOne",
* target: "labels",
* mutation: () => {
* return {text: "hey"};
* }
* }
* ];
* }
* }
* }
* ]}
*/
events?: EventPropTypeInterface<string, StringOrNumberOrCallback>[];
/**
* ChartBoxPlot uses the standard externalEventMutations prop.
*
* @propType object[]
*/
externalEventMutations?: EventCallbackInterface<string | string[], StringOrNumberOrList>[];
/**
* The groupComponent prop takes an entire component which will be used to
* create group elements for use within container elements. This prop defaults
* to a <g> tag on web, and a react-native-svg <G> tag on mobile
*/
groupComponent?: React.ReactElement<any>;
/**
* The height props specifies the height the svg viewBox of the chart container.
* This value should be given as a number of pixels
*/
height?: number;
/**
* The horizontal prop determines whether the bars will be laid vertically or
* horizontally. The bars will be vertical if this prop is false or unspecified,
* or horizontal if the prop is set to true.
*/
horizontal?: boolean;
/**
* The labelOrientation prop determines where labels are placed relative to their corresponding data. If this prop is
* not set, it will be set to "top" for horizontal charts, and "right" for vertical charts.
*/
labelOrientation?: OrientationTypes | VictoryBoxPlotLabelOrientationInterface;
/**
* When the boolean labels prop is set to true, the values for min, max, median, q1, and q3 will be displayed for
* each box. For more granular label control, use the individual minLabels, maxLabels, medianLabels, q1Labels, and
* q3Labels props.
*/
labels?: boolean;
/**
* Use the max data accessor prop to define the max value of a box plot.
*
* @propType string | array[string] | function
* @example Specify which property in an array of data objects should be used as the max value
*
* max="max_value"
*
* @example Use a function to translate each element in a data array into a max value
*
* max={() => 10}
*
* @example Specify which property in an array of nested data objects should be used as a max value
*
* max="bonds.max", max={["bonds", "max"]}
*/
max?: StringOrNumberOrCallback | string[];
/**
* The maxComponent prop takes a component instance which will be responsible for rendering an element to represent
* the maximum value of the box plot. The new element created from the passed maxComponent will be provided with the
* following props calculated by ChartBoxPlot: datum, index, scale, style, events, majorWhisker and minorWhisker.
* The majorWhisker and minorWhisker props are given as objects with values for x1, y1, x2 and y2 that describes the
* lines that make up the major and minor whisker. Any of these props may be overridden by passing in props to the
* supplied component, or modified or ignored within the custom component itself. If a maxComponent is not provided,
* ChartBoxPlot will use its default Whisker component.
*/
maxComponent?: React.ReactElement<any>;
/**
* The maxDomain prop defines a maximum domain value for a chart. This prop is useful in situations where the maximum
* domain of a chart is static, while the minimum value depends on data or other variable information. If the domain
* prop is set in addition to maximumDomain, domain will be used.
*
* Note: The x value supplied to the maxDomain prop refers to the independent variable, and the y value refers to the
* dependent variable. This may cause confusion in horizontal charts, as the independent variable will corresponds to
* the y axis.
*
* @example
*
* maxDomain={0}
* maxDomain={{ y: 0 }}
*/
maxDomain?: number | { x?: number; y?: number };
/**
* The maxLabelComponent prop takes a component instance which will be used to render the label corresponding to the
* maximum value for each box. The new element created from the passed maxLabelComponent will be supplied with the
* following props: x, y, datum, index, scale, verticalAnchor, textAnchor, angle, transform, style and events. Any of
* these props may be overridden by passing in props to the supplied component, or modified or ignored within the
* custom component itself. If maxLabelComponent is omitted, a new ChartLabel will be created with props described
* above.
*/
maxLabelComponent?: React.ReactElement<any>;
/**
* The maxLabels prop defines the labels that will appear above each point. This prop should be given as a boolean,
* an array or as a function of the props corresponding to that label. When given as a boolean value, the max value
* of each datum will be used for the label.
*
* @example
*
* maxLabels={["first", "second", "third"]}
* maxLabels={({ datum }) => Math.round(datum.max)}
*/
maxLabels?: VictoryBoxPlotLabelType;
/**
* Use the median data accessor prop to define the median value of a box plot.
*
* @propType string | array[string] | function
* @example Specify which property in an array of data objects should be used as the median value
*
* median="median_value"
*
* @example Use a function to translate each element in a data array into a median value
*
* median={() => 10}
*
* @example Specify which property in an array of nested data objects should be used as a median value
*
* median="bonds.median", median={["bonds", "median"]}
*/
median?: StringOrNumberOrCallback | string[];
/**
* The medianComponent prop takes a component instance which will be responsible for rendering an element to represent
* the median value of the box plot. The new element created from the passed medianComponent will be provided with the
* following props calculated by ChartBoxPlot: datum, index, scale, style, events, x1, y1, x2 and y2 Any of these
* props may be overridden by passing in props to the supplied component, or modified or ignored within the custom
* component itself. If a medianComponent is not provided, ChartBoxPlot will use its default Line component.
*/
medianComponent?: React.ReactElement<any>;
/**
* The medianLabelComponent prop takes a component instance which will be used to render the label corresponding to
* the median value for each box. The new element created from the passed medianLabelComponent will be supplied with
* the following props: x, y, datum, index, scale, verticalAnchor, textAnchor, angle, transform, style and events. Any
* of these props may be overridden by passing in props to the supplied component, or modified or ignored within the
* custom component itself. If medianLabelComponent is omitted, a new ChartLabel will be created with props
* described above.
*/
medianLabelComponent?: React.ReactElement<any>;
/**
* The medianLabels prop defines the labels that will appear above each point. This prop should be given as a boolean,
* an array or as a function of the props corresponding to that label. When given as a boolean value, the median value
* of each datum will be used for the label.
*
* @propType string | function | boolean
* @example
*
* medianLabels={["first", "second", "third"]}
* medianLabels={({ datum }) => Math.round(datum.median)}
*/
medianLabels?: VictoryBoxPlotLabelType;
/**
* Use the min data accessor prop to define the min value of a box plot.
*
* @propType string | array[string] | function
* @example Specify which property in an array of data objects should be used as the min value
*
* min="min_value"
*
* @example Use a function to translate each element in a data array into a min value
*
* min={() => 10}
*
* @example Specify which property in an array of nested data objects should be used as a min value
*
* min="bonds.min", min={["bonds", "min"]}
*/
min?: StringOrNumberOrCallback | string[];
/**
* The minComponent prop takes a component instance which will be responsible for rendering an element to represent
* the minimum value of the box plot. The new element created from the passed minComponent will be provided with the
* following props calculated by ChartBoxPlot: datum, index, scale, style, events, majorWhisker and minorWhisker.
* The majorWhisker and minorWhisker props are given as objects with values for x1, y1, x2 and y2 that describes the
* lines that make up the major and minor whisker. Any of these props may be overridden by passing in props to the
* supplied component, or modified or ignored within the custom component itself. If a minComponent is not provided,
* ChartBoxPlot will use its default Whisker component.
*/
minComponent?: React.ReactElement<any>;
/**
* The minDomain prop defines a minimum domain value for a chart. This prop is useful in situations where the minimum
* domain of a chart is static, while the maximum value depends on data or other variable information. If the domain
* prop is set in addition to minimumDomain, domain will be used.
*
* Note: The x value supplied to the minDomain prop refers to the independent variable, and the y value refers to the
* dependent variable. This may cause confusion in horizontal charts, as the independent variable will corresponds to
* the y axis.
*
* @example
*
* minDomain={0}
* minDomain={{ y: 0 }}
*/
minDomain?: number | { x?: number; y?: number };
/**
* The minLabelComponent prop takes a component instance which will be used to render the label corresponding to the
* minimum value for each box. The new element created from the passed minLabelComponent will be supplied with the
* following props: x, y, datum, index, scale, verticalAnchor, textAnchor, angle, transform, style and events. Any of
* these props may be overridden by passing in props to the supplied component, or modified or ignored within the
* custom component itself. If minLabelComponent is omitted, a new ChartLabel will be created with props described
* above.
*/
minLabelComponent?: React.ReactElement<any>;
/**
* The minLabels prop defines the labels that will appear above each point. This prop should be given as a boolean, an
* array or as a function of the props corresponding to that label. When given as a boolean value, the min value of
* each datum will be used for the label.
*
* @propType string | function | boolean
* @example
*
* minLabels={["first", "second", "third"]}
* minLabels={({ datum }) => Math.round(datum.min)}
*/
minLabels?: VictoryBoxPlotLabelType;
/**
* The name prop is used to reference a component instance when defining shared events.
*/
name?: string;
/**
* Victory components will pass an origin prop is to define the center point in svg coordinates for polar charts.
*
* Note: It will not typically be necessary to set an origin prop manually
*
* @propType { x: number, y: number }
*/
origin?: OriginType;
/**
* The padding props specifies the amount of padding in number of pixels between
* the edge of the chart and any rendered child components. This prop can be given
* as a number or as an object with padding specified for top, bottom, left
* and right.
*
* @propType number | { top: number, bottom: number, left: number, right: number }
*/
padding?: PaddingProps;
/**
* Victory components can pass a boolean polar prop to specify whether a label is part of a polar chart.
*
* Note: This prop should not be set manually.
*
* @private Not intended as public API and subject to change
* @hide
*/
polar?: boolean;
/**
* Use the q1 data accessor prop to define the q1 value of a box plot.
*
* @propType string | array[string] | function
* @example Specify which property in an array of data objects should be used as the q1 value
*
* q1="q1_value"
*
* @example Use a function to translate each element in a data array into a q1 value
*
* q1={() => 10}
*
* @example Specify which property in an array of nested data objects should be used as a q1 value
*
* q1="bonds.q1", q1={["bonds", "q1"]}
*/
q1?: StringOrNumberOrCallback | string[];
/**
* The q1Component prop takes a component instance which will be responsible for rendering an element to represent the
* q1 value of the box plot. The new element created from the passed q1Component will be provided with the following
* props calculated by ChartBoxPlot: datum, index, scale, style, events, x, y, width and height Any of these props
* may be overridden by passing in props to the supplied component, or modified or ignored within the custom component
* itself. If a q1Component is not provided, ChartBoxPlot will use its default Box component.
*/
q1Component?: React.ReactElement<any>;
/**
* The q1LabelComponent prop takes a component instance which will be used to render the label corresponding to the q1
* value for each box. The new element created from the passed q1LabelComponent will be supplied with the following
* props: x, y, datum, index, scale, verticalAnchor, textAnchor, angle, transform, style and events. Any of these
* props may be overridden by passing in props to the supplied component, or modified or ignored within the custom
* component itself. If q1LabelComponent is omitted, a new ChartLabel will be created with props described above.
*/
q1LabelComponent?: React.ReactElement<any>;
/**
* The q1Labels prop defines the labels that will appear above each point. This prop should be given as a boolean, an
* array or as a function of the props corresponding to that label. When given as a boolean value, the q1 value of
* each datum will be used for the label.
*
* @propType string | function | boolean
* @example
*
* q1Labels={["first", "second", "third"]}
* q1Labels={({ datum }) => Math.round(datum.q1)}
*/
q1Labels?: VictoryBoxPlotLabelType;
/**
* Use the q3 data accessor prop to define the q3 value of a box plot.
*
* @propType string | array[string] | function
* @example Specify which property in an array of data objects should be used as the q3 value
*
* q3="q3_value"
*
* @example Use a function to translate each element in a data array into a q3 value
*
* q3={() => 10}
*
* @example Specify which property in an array of nested data objects should be used as a q3 value
*
* q3="bonds.q3", q3={["bonds", "q3"]}
*/
q3?: StringOrNumberOrCallback | string[];
/**
* The q3Component prop takes a component instance which will be responsible for rendering an element to represent the
* q3 value of the box plot. The new element created from the passed q3Component will be provided with the following
* props calculated by ChartBoxPlot: datum, index, scale, style, events, x, y, width and height Any of these props
* may be overridden by passing in props to the supplied component, or modified or ignored within the custom component
* itself. If a q3Component is not provided, ChartBoxPlot will use its default Box component.
*/
q3Component?: React.ReactElement<any>;
/**
* The q3LabelComponent prop takes a component instance which will be used to render the label corresponding to the q3
* value for each box. The new element created from the passed q3LabelComponent will be supplied with the following
* props: x, y, datum, index, scale, verticalAnchor, textAnchor, angle, transform, style and events. Any of these
* props may be overridden by passing in props to the supplied component, or modified or ignored within the custom
* component itself. If q3LabelComponent is omitted, a new ChartLabel will be created with props described above.
*/
q3LabelComponent?: React.ReactElement<any>;
/**
* The q3Labels prop defines the labels that will appear above each point. This prop should be given as a boolean, an
* array or as a function of the props corresponding to that label. When given as a boolean value, the q3 value of
* each datum will be used for the label.
*
* @propType string | function | boolean
* @example
*
* q3Labels={["first", "second", "third"]}
* q3Labels={({ datum }) => Math.round(datum.q3)}
*/
q3Labels?: VictoryBoxPlotLabelType;
/**
* The range prop describes the dimensions over which data may be plotted. For cartesian coordinate systems, this
* corresponds to minimum and maximum svg coordinates in the x and y dimension. In polar coordinate systems this
* corresponds to a range of angles and radii. When this value is not given it will be calculated from the width,
* height, and padding, or from the startAngle and endAngle in the case of polar charts. All components in a given
* chart must share the same range, so setting this prop on children nested within Chart or
* ChartGroup will have no effect. This prop is usually not set manually.
*
* @propType number[] | { x: number[], y: number[] }
* @example [low, high] | { x: [low, high], y: [low, high] }
*
* Cartesian: range={{ x: [50, 250], y: [50, 250] }}
* Polar: range={{ x: [0, 360], y: [0, 250] }}
*/
range?: RangePropType;
/**
* The samples prop specifies how many individual points to plot when plotting
* y as a function of x. Samples is ignored if x props are provided instead.
*/
samples?: number;
/**
* The scale prop determines which scales your chart should use. This prop can be
* given as a string specifying a supported scale ("linear", "time", "log", "sqrt"),
* as a d3 scale function, or as an object with scales specified for x and y
*
* @propType string | { x: string, y: string }
* @example d3Scale.time(), {x: "linear", y: "log"}
*/
scale?:
| ScalePropType
| D3Scale
| {
x?: ScalePropType | D3Scale;
y?: ScalePropType | D3Scale;
};
/**
* The sharedEvents prop is used internally to coordinate events between components.
*
* Note: This prop should not be set manually.
*
* @private Not intended as public API and subject to change
* @hide
*/
sharedEvents?: { events: any[]; getEventState: Function };
/**
* By default domainPadding is coerced to existing quadrants. This means that if a given domain only includes positive
* values, no amount of padding applied by domainPadding will result in a domain with negative values. This is the
* desired behavior in most cases. For users that need to apply padding without regard to quadrant, the
* singleQuadrantDomainPadding prop may be used. This prop may be given as a boolean or an object with boolean values
* specified for "x" and/or "y". When this prop is false (or false for a given dimension), padding will be applied
* without regard to quadrant. If this prop is not specified, domainPadding will be coerced to existing quadrants.
*
* Note: The x value supplied to the singleQuadrantDomainPadding prop refers to the independent variable, and the y
* value refers to the dependent variable. This may cause confusion in horizontal charts, as the independent variable
* will corresponds to the y axis.
*
* @example
*
* singleQuadrantDomainPadding={false}
* singleQuadrantDomainPadding={{ x: false }}
*/
singleQuadrantDomainPadding?: boolean | { x?: boolean; y?: boolean };
/**
* Use the sortKey prop to indicate how data should be sorted. This prop
* is given directly to the lodash sortBy function to be executed on the
* final dataset.
*
* @propType number | string | Function | string[]
*/
sortKey?: DataGetterPropType;
/**
* The sortOrder prop specifies whether sorted data should be returned in 'ascending' or 'descending' order.
*
* @propType string
*/
sortOrder?: SortOrderPropType;
/**
* The standalone prop determines whether the component will render a standalone svg
* or a <g> tag that will be included in an external svg. Set standalone to false to
* compose ChartBoxPlot with other components within an enclosing <svg> tag.
*/
standalone?: boolean;
/**
* The style prop specifies styles for your ChartBoxPlot. Any valid inline style properties
* will be applied. Height, width, and padding should be specified via the height,
* width, and padding props, as they are used to calculate the alignment of
* components within chart.
*
* @propType { parent: object, data: object, labels: object }
* @example {data: {fill: "red"}, labels: {fontSize: 12}}
*/
style?: VictoryStyleInterface;
/**
* The theme prop takes a style object with nested data, labels, and parent objects.
* You can create this object yourself, or you can use a theme provided by
* When using ChartBoxPlot as a solo component, implement the theme directly on
* ChartBoxPlot. If you are wrapping ChartBoxPlot in ChartChart or ChartGroup,
* please call the theme on the outermost wrapper component instead.
*
* @propType object
*/
theme?: ChartThemeDefinition;
/**
* Specifies the theme color. Valid values are 'blue', 'green', 'multi', etc.
*
* Note: Not compatible with theme prop
*
* @example themeColor={ChartThemeColor.blue}
*/
themeColor?: string;
/**
* The whiskerWidth prop specifies how wide each whisker crosshair should be. If the whiskerWidth prop is not set, the
* width of the whisker crosshair will match the width of the box.
*/
whiskerWidth?: number;
/**
* The width props specifies the width of the svg viewBox of the chart container
* This value should be given as a number of pixels
*/
width?: number;
/**
* The x prop specifies how to access the X value of each data point.
* If given as a function, it will be run on each data point, and returned value will be used.
* If given as an integer, it will be used as an array index for array-type data points.
* If given as a string, it will be used as a property key for object-type data points.
* If given as an array of strings, or a string containing dots or brackets,
* it will be used as a nested object property path (for details see Lodash docs for _.get).
* If `null` or `undefined`, the data value will be used as is (identity function/pass-through).
*
* @propType number | string | Function | string[]
* @example 0, 'x', 'x.value.nested.1.thing', 'x[2].also.nested', null, d => Math.sin(d)
*/
x?: DataGetterPropType;
/**
* The y prop specifies how to access the Y value of each data point.
* If given as a function, it will be run on each data point, and returned value will be used.
* If given as an integer, it will be used as an array index for array-type data points.
* If given as a string, it will be used as a property key for object-type data points.
* If given as an array of strings, or a string containing dots or brackets,
* it will be used as a nested object property path (for details see Lodash docs for _.get).
* If `null` or `undefined`, the data value will be used as is (identity function/pass-through).
*
* @propType number | string | Function | string[]
* @example 0, 'y', 'y.value.nested.1.thing', 'y[2].also.nested', null, d => Math.sin(d)
*/
y?: DataGetterPropType;
/**
* Use y0 data accessor prop to determine how the component defines the baseline y0 data.
* This prop is useful for defining custom baselines for components like ChartBoxPlot.
* This prop may be given in a variety of formats.
*
* @propType number | string | Function | string[]
* @example 'last_quarter_profit', () => 10, 1, 'employees.salary', ["employees", "salary"]
*/
y0?: DataGetterPropType;
}
export const ChartBoxPlot: React.FunctionComponent<ChartBoxPlotProps> = ({
containerComponent = <ChartContainer />,
themeColor,
// destructure last
theme = getTheme(themeColor),
...rest
}: ChartBoxPlotProps) => {
// Clone so users can override container props
const container = cloneElement(containerComponent, {
theme,
...containerComponent.props
});
// Note: containerComponent is required for theme
return <VictoryBoxPlot containerComponent={container} theme={theme} {...rest} />;
};
ChartBoxPlot.displayName = 'ChartBoxPlot';
// Note: VictoryBar.getDomain & VictoryBar.role must be hoisted
hoistNonReactStatics(ChartBoxPlot, VictoryBoxPlot);