victory-chart 36.5.0 → 36.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,7 @@ import { defaults, assign } from "lodash";
7
7
  const fallbackProps = {
8
8
  width: 450,
9
9
  height: 300,
10
- padding: 50
10
+ padding: 50,
11
11
  };
12
12
 
13
13
  function getAxisProps(child, props, calculatedProps) {
@@ -20,7 +20,7 @@ function getAxisProps(child, props, calculatedProps) {
20
20
  endAngle: props.endAngle,
21
21
  innerRadius: props.innerRadius,
22
22
  domain,
23
- scale
23
+ scale,
24
24
  };
25
25
  }
26
26
 
@@ -51,12 +51,12 @@ export function getBackgroundWithProps(props, calculatedProps) {
51
51
  x: xCoordinate,
52
52
  y: yCoordinate,
53
53
  key: `${parentName}-background`,
54
- width
54
+ width,
55
55
  };
56
56
 
57
57
  return React.cloneElement(
58
58
  backgroundElement,
59
- defaults({}, backgroundElement.props, backgroundProps)
59
+ defaults({}, backgroundElement.props, backgroundProps),
60
60
  );
61
61
  }
62
62
 
@@ -77,8 +77,8 @@ function getStyles(props) {
77
77
  parent: defaults({}, styleProps, {
78
78
  height: "100%",
79
79
  width: "100%",
80
- userSelect: "none"
81
- })
80
+ userSelect: "none",
81
+ }),
82
82
  };
83
83
  }
84
84
 
@@ -91,20 +91,20 @@ export function getCalculatedProps(props, childComponents) {
91
91
  const stringMap = createStringMap(props, childComponents, allStrings);
92
92
  const domain = {
93
93
  x: getDomain(assign({}, props, { categories }), "x", childComponents),
94
- y: getDomain(assign({}, props, { categories }), "y", childComponents)
94
+ y: getDomain(assign({}, props, { categories }), "y", childComponents),
95
95
  };
96
96
 
97
97
  const range = {
98
98
  x: Helpers.getRange(props, "x"),
99
- y: Helpers.getRange(props, "y")
99
+ y: Helpers.getRange(props, "y"),
100
100
  };
101
101
  const baseScale = {
102
102
  x: Scale.getScaleFromProps(props, "x") || Wrapper.getScale(props, "x"),
103
- y: Scale.getScaleFromProps(props, "y") || Wrapper.getScale(props, "y")
103
+ y: Scale.getScaleFromProps(props, "y") || Wrapper.getScale(props, "y"),
104
104
  };
105
105
  const scale = {
106
106
  x: baseScale.x.domain(domain.x).range(horizontal ? range.y : range.x),
107
- y: baseScale.y.domain(domain.y).range(horizontal ? range.x : range.y)
107
+ y: baseScale.y.domain(domain.y).range(horizontal ? range.x : range.y),
108
108
  };
109
109
 
110
110
  const origin = polar ? Helpers.getPolarOrigin(props) : Axis.getOrigin(domain);
@@ -120,7 +120,7 @@ export function getCalculatedProps(props, childComponents) {
120
120
  stringMap,
121
121
  style,
122
122
  origin,
123
- padding
123
+ padding,
124
124
  };
125
125
  }
126
126
 
@@ -152,15 +152,15 @@ export function getChildren(props, childComponents, calculatedProps) {
152
152
  origin: polar ? origin : undefined,
153
153
  padding: calculatedProps.padding,
154
154
  key: `${name}-key-${index}`,
155
- standalone: false
155
+ standalone: false,
156
156
  },
157
- childProps
157
+ childProps,
158
158
  );
159
159
  return React.cloneElement(child, newProps);
160
160
  });
161
161
  }
162
162
 
163
- export const getChildComponents = (props, defaultAxes) => {
163
+ export const getChildComponents = (props, defaultAxes?) => {
164
164
  const childComponents = React.Children.toArray(props.children);
165
165
  let newChildComponents = [...childComponents];
166
166
 
@@ -171,8 +171,8 @@ export const getChildComponents = (props, defaultAxes) => {
171
171
  dependent: Axis.getAxisComponentsWithParent(childComponents, "dependent"),
172
172
  independent: Axis.getAxisComponentsWithParent(
173
173
  childComponents,
174
- "independent"
175
- )
174
+ "independent",
175
+ ),
176
176
  };
177
177
 
178
178
  if (
@@ -181,11 +181,11 @@ export const getChildComponents = (props, defaultAxes) => {
181
181
  ) {
182
182
  newChildComponents = props.prependDefaultAxes
183
183
  ? [defaultAxes.independent, defaultAxes.dependent].concat(
184
- newChildComponents
184
+ newChildComponents,
185
185
  )
186
186
  : newChildComponents.concat([
187
187
  defaultAxes.independent,
188
- defaultAxes.dependent
188
+ defaultAxes.dependent,
189
189
  ]);
190
190
  }
191
191
  }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./victory-chart";
@@ -0,0 +1,89 @@
1
+ import * as React from "react";
2
+ import {
3
+ CategoryPropType,
4
+ DomainPropType,
5
+ EventPropTypeInterface,
6
+ StringOrNumberOrCallback,
7
+ VictoryCommonProps,
8
+ VictoryStyleInterface,
9
+ VictoryStyleObject,
10
+ withContainer,
11
+ useDomain,
12
+ useScale,
13
+ useData,
14
+ } from "victory-core";
15
+ import { AxesType } from "..";
16
+ import { VictoryAxis, VictoryAxisProps } from "victory-axis";
17
+
18
+ interface VictoryChartProps extends VictoryCommonProps {
19
+ backgroundComponent?: React.ReactElement;
20
+ categories?: CategoryPropType;
21
+ children?: React.ReactNode | React.ReactNode[];
22
+ desc?: string;
23
+ defaultAxes?: AxesType;
24
+ defaultPolarAxes?: AxesType;
25
+ domain?: DomainPropType;
26
+ endAngle?: number;
27
+ eventKey?: StringOrNumberOrCallback;
28
+ events?: EventPropTypeInterface<
29
+ string,
30
+ string[] | number[] | string | number
31
+ >[];
32
+ innerRadius?: number;
33
+ prependDefaultAxes?: boolean;
34
+ startAngle?: number;
35
+ style?: Pick<VictoryStyleInterface, "parent"> & {
36
+ background?: VictoryStyleObject;
37
+ };
38
+ title?: string;
39
+ }
40
+
41
+ const DEFAULT_AXES = {
42
+ independent: <VictoryAxis />,
43
+ dependent: <VictoryAxis dependentAxis />,
44
+ };
45
+
46
+ // TODO: This does not accept data
47
+ const VictoryChart = ({
48
+ defaultAxes = DEFAULT_AXES,
49
+ groupComponent = <g />,
50
+ children,
51
+ }: VictoryChartProps) => {
52
+ const scale = useScale();
53
+ const data = useData();
54
+ const domain = useDomain();
55
+
56
+ const axes = React.useMemo(() => {
57
+ const { dependent, independent } = {
58
+ ...defaultAxes,
59
+ ...DEFAULT_AXES,
60
+ };
61
+ const axisProps: VictoryAxisProps = {
62
+ data,
63
+ domain,
64
+ // @ts-expect-error we need to fix this scale type
65
+ scale,
66
+ standalone: false,
67
+ };
68
+ return [
69
+ React.cloneElement(dependent, { ...axisProps, key: "dependent-axis" }),
70
+ React.cloneElement(independent, {
71
+ ...axisProps,
72
+ key: "independent-axis",
73
+ }),
74
+ ];
75
+ }, [defaultAxes, domain, scale, data]);
76
+
77
+ const childComponents = React.Children.map(children, (child, index) => {
78
+ // @ts-expect-error Why is this throwing a type error?
79
+ return React.cloneElement(child, {
80
+ key: `child-${index}`,
81
+ index,
82
+ standalone: false,
83
+ });
84
+ });
85
+
86
+ return React.cloneElement(groupComponent, {}, axes, childComponents);
87
+ };
88
+
89
+ export default withContainer(VictoryChart);
@@ -10,7 +10,14 @@ import {
10
10
  UserProps,
11
11
  VictoryContainer,
12
12
  VictoryTheme,
13
- Wrapper
13
+ Wrapper,
14
+ CategoryPropType,
15
+ DomainPropType,
16
+ EventPropTypeInterface,
17
+ StringOrNumberOrCallback,
18
+ VictoryCommonProps,
19
+ VictoryStyleInterface,
20
+ VictoryStyleObject,
14
21
  } from "victory-core";
15
22
  import { VictorySharedEvents } from "victory-shared-events";
16
23
  import { VictoryAxis } from "victory-axis";
@@ -19,17 +26,17 @@ import {
19
26
  getBackgroundWithProps,
20
27
  getChildComponents,
21
28
  getCalculatedProps,
22
- getChildren
29
+ getChildren,
23
30
  } from "./helper-methods";
24
31
  import isEqual from "react-fast-compare";
25
32
 
26
33
  const fallbackProps = {
27
34
  width: 450,
28
35
  height: 300,
29
- padding: 50
36
+ padding: 50,
30
37
  };
31
38
 
32
- const VictoryChart = (initialProps) => {
39
+ const VictoryChartImpl: React.FC<VictoryChartProps> = (initialProps) => {
33
40
  const role = "chart";
34
41
  const { getAnimationProps, setAnimationState, getProps } =
35
42
  Hooks.useAnimationState();
@@ -48,7 +55,7 @@ const VictoryChart = (initialProps) => {
48
55
  theme,
49
56
  polar,
50
57
  name,
51
- title
58
+ title,
52
59
  } = modifiedProps;
53
60
 
54
61
  const axes = props.polar
@@ -57,14 +64,14 @@ const VictoryChart = (initialProps) => {
57
64
 
58
65
  const childComponents = React.useMemo(
59
66
  () => getChildComponents(modifiedProps, axes),
60
- [modifiedProps, axes]
67
+ [modifiedProps, axes],
61
68
  );
62
69
 
63
70
  const calculatedProps = React.useMemo(
64
71
  () => getCalculatedProps(modifiedProps, childComponents),
65
- [modifiedProps, childComponents]
72
+ [modifiedProps, childComponents],
66
73
  );
67
- const { domain, scale, style, origin, radius, horizontal } = calculatedProps;
74
+ const { domain, scale, style, origin, horizontal } = calculatedProps;
68
75
 
69
76
  const newChildren = React.useMemo(() => {
70
77
  const children = getChildren(props, childComponents, calculatedProps);
@@ -72,7 +79,7 @@ const VictoryChart = (initialProps) => {
72
79
  const mappedChildren = children.map((child, index) => {
73
80
  const childProps = assign(
74
81
  { animate: getAnimationProps(props, child, index, "victory chart") },
75
- child.props
82
+ child.props,
76
83
  );
77
84
  return React.cloneElement(child, childProps);
78
85
  });
@@ -80,7 +87,7 @@ const VictoryChart = (initialProps) => {
80
87
  if (props.style && props.style.background) {
81
88
  const backgroundComponent = getBackgroundWithProps(
82
89
  props,
83
- calculatedProps
90
+ calculatedProps,
84
91
  );
85
92
 
86
93
  mappedChildren.unshift(backgroundComponent);
@@ -100,12 +107,11 @@ const VictoryChart = (initialProps) => {
100
107
  name,
101
108
  origin: polar ? origin : undefined,
102
109
  polar,
103
- radius,
104
110
  theme,
105
111
  title,
106
112
  scale,
107
113
  standalone,
108
- style: style.parent
114
+ style: style.parent,
109
115
  };
110
116
  }
111
117
  return {};
@@ -117,13 +123,12 @@ const VictoryChart = (initialProps) => {
117
123
  name,
118
124
  origin,
119
125
  polar,
120
- radius,
121
126
  scale,
122
127
  standalone,
123
128
  style,
124
129
  title,
125
130
  theme,
126
- width
131
+ width,
127
132
  ]);
128
133
 
129
134
  const container = React.useMemo(() => {
@@ -132,7 +137,7 @@ const VictoryChart = (initialProps) => {
132
137
  {},
133
138
  containerComponent.props,
134
139
  containerProps,
135
- UserProps.getSafeUserProps(initialProps)
140
+ UserProps.getSafeUserProps(initialProps),
136
141
  );
137
142
  return React.cloneElement(containerComponent, defaultContainerProps);
138
143
  }
@@ -142,7 +147,7 @@ const VictoryChart = (initialProps) => {
142
147
  standalone,
143
148
  containerComponent,
144
149
  containerProps,
145
- initialProps
150
+ initialProps,
146
151
  ]);
147
152
 
148
153
  const events = React.useMemo(() => {
@@ -175,46 +180,73 @@ const VictoryChart = (initialProps) => {
175
180
  return React.cloneElement(container, container.props, newChildren);
176
181
  };
177
182
 
178
- VictoryChart.propTypes = {
183
+ VictoryChartImpl.propTypes = {
179
184
  ...CommonProps.baseProps,
180
185
  backgroundComponent: PropTypes.element,
181
186
  children: PropTypes.oneOfType([
182
187
  PropTypes.arrayOf(PropTypes.node),
183
- PropTypes.node
188
+ PropTypes.node,
184
189
  ]),
185
190
  defaultAxes: PropTypes.shape({
186
191
  independent: PropTypes.element,
187
- dependent: PropTypes.element
192
+ dependent: PropTypes.element,
188
193
  }),
189
194
  defaultPolarAxes: PropTypes.shape({
190
195
  independent: PropTypes.element,
191
- dependent: PropTypes.element
196
+ dependent: PropTypes.element,
192
197
  }),
193
198
  endAngle: PropTypes.number,
194
199
  innerRadius: CustomPropTypes.nonNegative,
195
200
  prependDefaultAxes: PropTypes.bool,
196
- startAngle: PropTypes.number
201
+ startAngle: PropTypes.number,
197
202
  };
198
203
 
199
- VictoryChart.defaultProps = {
204
+ VictoryChartImpl.defaultProps = {
200
205
  backgroundComponent: <Background />,
201
206
  containerComponent: <VictoryContainer />,
202
207
  defaultAxes: {
203
208
  independent: <VictoryAxis />,
204
- dependent: <VictoryAxis dependentAxis />
209
+ dependent: <VictoryAxis dependentAxis />,
205
210
  },
206
211
  defaultPolarAxes: {
207
212
  independent: <VictoryPolarAxis />,
208
- dependent: <VictoryPolarAxis dependentAxis />
213
+ dependent: <VictoryPolarAxis dependentAxis />,
209
214
  },
210
215
  groupComponent: <g />,
211
216
  standalone: true,
212
- theme: VictoryTheme.grayscale
217
+ theme: VictoryTheme.grayscale,
213
218
  };
214
219
 
215
- const VictoryChartMemo = React.memo(VictoryChart, isEqual);
220
+ export const VictoryChart = React.memo(VictoryChartImpl, isEqual);
216
221
 
217
- VictoryChartMemo.displayName = "VictoryChart";
218
- VictoryChartMemo.expectedComponents = ["groupComponent", "containerComponent"];
222
+ VictoryChart.displayName = "VictoryChart";
223
+ // @ts-expect-error FIXME: Does this "expectedComponents" do anything?
224
+ VictoryChart.expectedComponents = ["groupComponent", "containerComponent"];
225
+
226
+ export type AxesType = {
227
+ dependent?: React.ReactElement | null;
228
+ independent?: React.ReactElement | null;
229
+ };
219
230
 
220
- export default VictoryChartMemo;
231
+ export interface VictoryChartProps extends VictoryCommonProps {
232
+ backgroundComponent?: React.ReactElement;
233
+ categories?: CategoryPropType;
234
+ children?: React.ReactNode | React.ReactNode[];
235
+ desc?: string;
236
+ defaultAxes?: AxesType;
237
+ defaultPolarAxes?: AxesType;
238
+ domain?: DomainPropType;
239
+ endAngle?: number;
240
+ eventKey?: StringOrNumberOrCallback;
241
+ events?: EventPropTypeInterface<
242
+ string,
243
+ string[] | number[] | string | number
244
+ >[];
245
+ innerRadius?: number;
246
+ prependDefaultAxes?: boolean;
247
+ startAngle?: number;
248
+ style?: Pick<VictoryStyleInterface, "parent"> & {
249
+ background?: VictoryStyleObject;
250
+ };
251
+ title?: string;
252
+ }
package/src/index.d.ts DELETED
@@ -1,40 +0,0 @@
1
- import * as React from "react";
2
- import {
3
- CategoryPropType,
4
- DomainPropType,
5
- EventPropTypeInterface,
6
- StringOrNumberOrCallback,
7
- VictoryCommonProps,
8
- VictoryStyleInterface,
9
- VictoryStyleObject
10
- } from "victory-core";
11
-
12
- export type AxesType = {
13
- dependent?: React.ReactElement;
14
- independent?: React.ReactElement;
15
- };
16
-
17
- export interface VictoryChartProps extends VictoryCommonProps {
18
- backgroundComponent?: React.ReactElement;
19
- categories?: CategoryPropType;
20
- children?: React.ReactNode | React.ReactNode[];
21
- desc?: string;
22
- defaultAxes?: AxesType;
23
- defaultPolarAxes?: AxesType;
24
- domain?: DomainPropType;
25
- endAngle?: number;
26
- eventKey?: StringOrNumberOrCallback;
27
- events?: EventPropTypeInterface<
28
- string,
29
- string[] | number[] | string | number
30
- >[];
31
- innerRadius?: number;
32
- prependDefaultAxes?: boolean;
33
- startAngle?: number;
34
- style?: Pick<VictoryStyleInterface, "parent"> & {
35
- background?: VictoryStyleObject;
36
- };
37
- title?: string;
38
- }
39
-
40
- export class VictoryChart extends React.Component<VictoryChartProps, any> {}
package/src/index.js DELETED
@@ -1 +0,0 @@
1
- export { default as VictoryChart } from "./victory-chart";