forked from patternfly/patternfly-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChartContainer.tsx
More file actions
161 lines (156 loc) · 6.54 KB
/
ChartContainer.tsx
File metadata and controls
161 lines (156 loc) · 6.54 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
import * as React from 'react';
import hoistNonReactStatics from 'hoist-non-react-statics';
import { OriginType, VictoryContainer, VictoryContainerProps } from 'victory-core';
import { ChartThemeDefinition } from '../ChartTheme/ChartTheme';
import { getTheme } from '../ChartUtils/chart-theme';
import { getClassName } from '../ChartUtils/chart-helpers';
/**
* ChartContainer provides a top-level <svg> element for other Victory based components to render within. By default,
* ChartContainer renders responsive SVGs.
*
* See https://github.com/FormidableLabs/victory/blob/main/packages/victory-core/src/victory-container/victory-container.tsx
*/
export interface ChartContainerProps extends VictoryContainerProps {
/**
* The children prop specifies the child or children that will be rendered within the container. It will be set by
* whatever Victory component is rendering the container.
*/
children?: React.ReactElement | React.ReactElement[];
/**
* The className prop specifies a className that will be applied to the outermost div rendered by ChartContainer
*/
className?: string;
/**
* The containerId prop may be used to set a deterministic id for the container. When a containerId is not manually
* set, a unique id will be generated. It is usually necessary to set deterministic ids for automated testing.
*/
containerId?: number | string;
/**
* The containerRef prop may be used to attach a ref to the outermost element rendered by the container.
*
* @example containerRef={(ref) => { this.chartRef = ref; }}
*/
containerRef?: React.RefObject<HTMLElement>;
/**
* The desc prop specifies the description of the chart/SVG to assist with
* accessibility for screen readers. The more info about the chart provided in
* the description, the more usable it will be for people using screen readers.
* This prop defaults to an empty string.
*
* @example "Golden retreivers make up 30%, Labs make up 25%, and other dog breeds are
* not represented above 5% each."
*/
desc?: string;
/**
* The events prop attaches arbitrary event handlers to the container component.
* Event handlers passed from other Victory components are called with their
* corresponding events as well as scale, style, width, height, and data when
* applicable. Use the invert method to convert event coordinate information to
* data. `scale.x.invert(evt.offsetX)`.
*
* @example {onClick: (evt) => alert(`x: ${evt.clientX}, y: ${evt.clientY}`)}
*/
events?: React.DOMAttributes<any>;
/**
* The height props specifies the height the svg viewBox of the container.
* This value should be given as a number of pixels. If no height prop
* is given, the height prop from the child component passed will be used.
*/
height?: number;
/**
* 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;
/**
* 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
* @hide
*/
polar?: boolean;
/**
* The portalComponent prop takes a component instance which will be used as a container for children that should
* render inside a top-level container so that they will always appear above other elements. VictoryTooltip renders
* inside a portal so that tooltips always render above data. VictoryPortal is used to define elements that should
* render in the portal container. This prop defaults to Portal, and should only be overridden when changing rendered
* elements from SVG to another type of element e.g., react-native-svg elements.
*/
portalComponent?: React.ReactElement;
/**
* The portalZIndex prop determines the z-index of the div enclosing the portal component. If a portalZIndex prop is
* not set, the z-index of the enclosing div will be set to 99.
*/
portalZIndex?: number;
/**
* The responsive prop specifies whether the rendered container should be a responsive container
* with a viewBox attribute, or a static container with absolute width and height.
*/
responsive?: boolean;
/**
* The style prop specifies styles for your ChartContainer. Any valid inline style properties
* will be applied. Height and width should be specified via the height
* and width props, as they are used to calculate the alignment of
* components within the container. Styles from the child component will
* also be passed, if any exist.
*
* @example {border: 1px solid red}
*/
style?: React.CSSProperties;
/**
* The tabIndex prop specifies the description of the chart/SVG to assist with accessibility.
*/
tabIndex?: number;
/**
* The theme prop specifies a theme to use for determining styles and layout properties for a component. Any styles or
* props defined in theme may be overwritten by props specified on the component instance.
*
* @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 title prop specifies the title to be applied to the SVG to assist
* accessibility for screen readers. The more descriptive this title is, the more
* useful it will be. If no title prop is passed, it will default to Chart.
*
* @example "Popularity of Dog Breeds by Percentage"
*/
title?: string;
/**
* The width props specifies the width of the svg viewBox of the container
* This value should be given as a number of pixels. If no width prop
* is given, the width prop from the child component passed will be used.
*/
width?: number;
}
export const ChartContainer: React.FunctionComponent<ChartContainerProps> = ({
className,
themeColor,
// destructure last
theme = getTheme(themeColor),
...rest
}: ChartContainerProps) => {
const chartClassName = getClassName({ className });
// Note: className is valid, but Victory is missing a type
return <VictoryContainer className={chartClassName} theme={theme} {...rest} />;
};
ChartContainer.displayName = 'ChartContainer';
// Note: VictoryContainer.role must be hoisted
hoistNonReactStatics(ChartContainer, VictoryContainer);