forked from patternfly/patternfly-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChartBulletComparativeWarningMeasure.tsx
More file actions
223 lines (218 loc) · 8.93 KB
/
ChartBulletComparativeWarningMeasure.tsx
File metadata and controls
223 lines (218 loc) · 8.93 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
import * as React from 'react';
import hoistNonReactStatics from 'hoist-non-react-statics';
import { DataGetterPropType, DomainPropType, NumberOrCallback, PaddingProps } from 'victory-core';
import { VictoryBar } from 'victory-bar';
import { ChartBulletComparativeMeasure } from './ChartBulletComparativeMeasure';
import { ChartContainer } from '../ChartContainer/ChartContainer';
import { ChartThemeDefinition } from '../ChartTheme/ChartTheme';
import { getBulletComparativeWarningMeasureTheme } from '../ChartUtils/chart-theme-types';
/**
* ChartBulletComparativeWarningMeasure renders a dataset as a comparative warning measure.
*
* See https://github.com/FormidableLabs/victory/blob/main/packages/victory-bar/src/index.d.ts
*/
export interface ChartBulletComparativeWarningMeasureProps {
/**
* Specifies the tooltip capability of the container component. A value of true allows the chart to add a
* ChartTooltip component to the labelComponent property. This is a shortcut to display tooltips when the labels
* property is also provided.
*/
allowTooltip?: boolean;
/**
* The ariaDesc prop specifies the description of the chart/SVG to assist with
* accessibility for screen readers.
*
* Note: Overridden by the desc prop of containerComponent
*/
ariaDesc?: string;
/**
* The ariaTitle prop specifies the title to be applied to the SVG to assist
* accessibility for screen readers.
*
* Note: Overridden by the title prop of containerComponent
*/
ariaTitle?: string;
/**
* The barWidth prop is used to specify the width of each bar. This prop may be given as
* a number of pixels or as a function that returns a number. When this prop is given as
* a function, it will be evaluated with the arguments datum, and active. When this value
* is not given, a default value will be calculated based on the overall dimensions of
* the chart, and the number of bars.
*
* @propType number | Function
*/
barWidth?: NumberOrCallback;
/**
* The constrainToVisibleArea prop determines whether to coerce tooltips so that they fit within the visible area of
* the chart. When this prop is set to true, tooltip pointers will still point to the correct data point, but the
* center of the tooltip will be shifted to fit within the overall width and height of the svg Victory renders.
*/
constrainToVisibleArea?: boolean;
/**
* The data prop specifies the data to be plotted. Data should be in the form of an array
* of data points, or an array of arrays of data points for multiple datasets.
* Each data point may be any format you wish (depending on the `comparativeErrorMeasureDataY` accessor prop),
* but by default, an object with y properties is expected.
*
* @example data={[{ y: 50 }]}
*/
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.
*
* Note: The x domain is expected to be `x: [0, 2]` in order to position all measures properly
*
* @propType number[] | { x: number[], y: number[] }
* @example [low, high], { x: [low, high], y: [low, high] }
*
* {x: [0, 2], y: [0, 100]}
*/
domain?: DomainPropType;
/**
* 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 data will be plotted horizontally.
* When this prop is set to true, the independent variable will be plotted on the y axis
* and the dependent variable will be plotted on the x axis.
*/
horizontal?: boolean;
/**
* The labelComponent prop takes in an entire label component which will be used
* to create a label for the bar. The new element created from the passed labelComponent
* will be supplied with the following properties: x, y, index, data, verticalAnchor,
* textAnchor, angle, style, text, 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 labelComponent is omitted, a new ChartLabel
* will be created with props described above. This labelComponent prop should be used to
* provide a series label for ChartBar. If individual labels are required for each
* data point, they should be created by composing ChartBar with VictoryScatter
*/
labelComponent?: React.ReactElement<any>;
/**
* The labels prop defines labels that will appear above each bar in your chart.
* This prop should be given as an array of values or as a function of data.
* If given as an array, the number of elements in the array should be equal to
* the length of the data array. Labels may also be added directly to the data object
* like data={[{y: 1, label: "first"}]}.
*
* @example ["spring", "summer", "fall", "winter"], (datum) => datum.title
*/
labels?: string[] | number[] | ((data: any) => string | number | null);
/**
* The measureComponent prop takes an entire component which will be used to create the chart
*/
measureComponent?: React.ReactElement<any>;
/**
* 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;
/**
* 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 ChartLine with other components within an enclosing <svg> tag.
*/
standalone?: boolean;
/**
* 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 ChartLine as a solo component, implement the theme directly on
* ChartLine. If you are wrapping ChartLine 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 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 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;
}
export const ChartBulletComparativeWarningMeasure: React.FunctionComponent<
ChartBulletComparativeWarningMeasureProps
> = ({
allowTooltip = true,
ariaDesc,
ariaTitle,
barWidth,
constrainToVisibleArea = false,
data,
domain,
horizontal = true,
labelComponent,
labels,
measureComponent = <ChartBulletComparativeMeasure />,
padding,
standalone = true,
themeColor,
y,
// destructure last
theme = getBulletComparativeWarningMeasureTheme(themeColor),
height = theme.bar.height,
width = theme.bar.width
}: ChartBulletComparativeWarningMeasureProps) => {
// Comparative measure component
const measure = React.cloneElement(measureComponent, {
allowTooltip,
ariaDesc,
ariaTitle,
barWidth,
constrainToVisibleArea,
data,
domain,
height,
horizontal,
labelComponent,
labels,
padding,
standalone: false,
theme,
themeColor,
width,
y,
...measureComponent.props
});
return standalone ? (
<ChartContainer desc={ariaDesc} height={height} title={ariaTitle} width={width}>
{measure}
</ChartContainer>
) : (
<React.Fragment>{measure}</React.Fragment>
);
};
ChartBulletComparativeWarningMeasure.displayName = 'ChartBulletComparativeWarningMeasure';
// Note: VictoryBar.role must be hoisted
hoistNonReactStatics(ChartBulletComparativeWarningMeasure, VictoryBar);