victory-core 37.3.2 → 37.3.3

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.
Files changed (127) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/victory-core.js +423 -371
  3. package/dist/victory-core.min.js +1 -1
  4. package/es/types/callbacks.d.ts +11 -11
  5. package/es/types/prop-types.d.ts +28 -28
  6. package/es/victory-animation/util.js +6 -6
  7. package/es/victory-animation/victory-animation.d.ts +3 -3
  8. package/es/victory-clip-container/victory-clip-container.d.ts +6 -1
  9. package/es/victory-clip-container/victory-clip-container.js +20 -12
  10. package/es/victory-container/victory-container.js +2 -2
  11. package/es/victory-label/victory-label.d.ts +3 -3
  12. package/es/victory-label/victory-label.js +12 -16
  13. package/es/victory-portal/victory-portal.js +4 -4
  14. package/es/victory-primitives/arc.js +2 -2
  15. package/es/victory-primitives/background.js +2 -2
  16. package/es/victory-primitives/border.js +2 -2
  17. package/es/victory-primitives/line-segment.js +2 -2
  18. package/es/victory-primitives/point.js +2 -2
  19. package/es/victory-primitives/tspan.d.ts +0 -1
  20. package/es/victory-primitives/types.d.ts +1 -1
  21. package/es/victory-primitives/whisker.d.ts +1 -1
  22. package/es/victory-primitives/whisker.js +2 -2
  23. package/es/victory-theme/types.d.ts +11 -11
  24. package/es/victory-transition/victory-transition.d.ts +1 -1
  25. package/es/victory-transition/victory-transition.js +7 -7
  26. package/es/victory-util/add-events.d.ts +8 -8
  27. package/es/victory-util/add-events.js +13 -13
  28. package/es/victory-util/axis.js +11 -11
  29. package/es/victory-util/data.js +16 -16
  30. package/es/victory-util/domain.js +13 -13
  31. package/es/victory-util/events.d.ts +4 -4
  32. package/es/victory-util/events.js +14 -14
  33. package/es/victory-util/helpers.d.ts +94 -19
  34. package/es/victory-util/helpers.js +95 -49
  35. package/es/victory-util/hooks/use-animation-state.d.ts +2 -2
  36. package/es/victory-util/hooks/use-animation-state.js +4 -4
  37. package/es/victory-util/label-helpers.d.ts +4 -3
  38. package/es/victory-util/label-helpers.js +3 -2
  39. package/es/victory-util/line-helpers.d.ts +1 -1
  40. package/es/victory-util/log.js +3 -2
  41. package/es/victory-util/merge-refs.d.ts +1 -1
  42. package/es/victory-util/scale.js +2 -2
  43. package/es/victory-util/selection.d.ts +3 -3
  44. package/es/victory-util/textsize.js +7 -5
  45. package/es/victory-util/timer.d.ts +1 -1
  46. package/es/victory-util/transitions.d.ts +1 -1
  47. package/es/victory-util/transitions.js +12 -12
  48. package/es/victory-util/type-helpers.d.ts +0 -1
  49. package/es/victory-util/type-helpers.js +0 -5
  50. package/es/victory-util/user-props.d.ts +2 -2
  51. package/es/victory-util/wrapper.js +12 -12
  52. package/lib/types/callbacks.d.ts +11 -11
  53. package/lib/types/prop-types.d.ts +28 -28
  54. package/lib/victory-animation/util.js +6 -6
  55. package/lib/victory-animation/victory-animation.d.ts +3 -3
  56. package/lib/victory-clip-container/victory-clip-container.d.ts +6 -1
  57. package/lib/victory-clip-container/victory-clip-container.js +20 -12
  58. package/lib/victory-container/victory-container.js +3 -3
  59. package/lib/victory-label/victory-label.d.ts +3 -3
  60. package/lib/victory-label/victory-label.js +12 -16
  61. package/lib/victory-portal/victory-portal.js +5 -5
  62. package/lib/victory-primitives/arc.js +2 -2
  63. package/lib/victory-primitives/background.js +2 -2
  64. package/lib/victory-primitives/border.js +2 -2
  65. package/lib/victory-primitives/line-segment.js +2 -2
  66. package/lib/victory-primitives/point.js +2 -2
  67. package/lib/victory-primitives/tspan.d.ts +0 -1
  68. package/lib/victory-primitives/types.d.ts +1 -1
  69. package/lib/victory-primitives/whisker.d.ts +1 -1
  70. package/lib/victory-primitives/whisker.js +2 -2
  71. package/lib/victory-theme/types.d.ts +11 -11
  72. package/lib/victory-transition/victory-transition.d.ts +1 -1
  73. package/lib/victory-transition/victory-transition.js +7 -7
  74. package/lib/victory-util/add-events.d.ts +8 -8
  75. package/lib/victory-util/add-events.js +13 -13
  76. package/lib/victory-util/axis.js +11 -11
  77. package/lib/victory-util/data.js +16 -16
  78. package/lib/victory-util/domain.js +13 -13
  79. package/lib/victory-util/events.d.ts +4 -4
  80. package/lib/victory-util/events.js +14 -14
  81. package/lib/victory-util/helpers.d.ts +94 -19
  82. package/lib/victory-util/helpers.js +96 -50
  83. package/lib/victory-util/hooks/use-animation-state.d.ts +2 -2
  84. package/lib/victory-util/hooks/use-animation-state.js +4 -4
  85. package/lib/victory-util/label-helpers.d.ts +4 -3
  86. package/lib/victory-util/label-helpers.js +3 -3
  87. package/lib/victory-util/line-helpers.d.ts +1 -1
  88. package/lib/victory-util/log.js +3 -2
  89. package/lib/victory-util/merge-refs.d.ts +1 -1
  90. package/lib/victory-util/scale.js +2 -2
  91. package/lib/victory-util/selection.d.ts +3 -3
  92. package/lib/victory-util/textsize.js +5 -5
  93. package/lib/victory-util/timer.d.ts +1 -1
  94. package/lib/victory-util/transitions.d.ts +1 -1
  95. package/lib/victory-util/transitions.js +12 -12
  96. package/lib/victory-util/type-helpers.d.ts +0 -1
  97. package/lib/victory-util/type-helpers.js +0 -6
  98. package/lib/victory-util/user-props.d.ts +2 -2
  99. package/lib/victory-util/wrapper.js +12 -12
  100. package/package.json +2 -30
  101. package/src/victory-animation/util.ts +3 -1
  102. package/src/victory-clip-container/victory-clip-container.tsx +26 -11
  103. package/src/victory-container/victory-container.tsx +1 -1
  104. package/src/victory-label/victory-label.tsx +5 -3
  105. package/src/victory-portal/victory-portal.tsx +3 -1
  106. package/src/victory-primitives/arc.tsx +1 -1
  107. package/src/victory-primitives/background.tsx +1 -1
  108. package/src/victory-primitives/border.tsx +1 -1
  109. package/src/victory-primitives/line-segment.tsx +1 -1
  110. package/src/victory-primitives/point.tsx +1 -1
  111. package/src/victory-primitives/whisker.tsx +1 -1
  112. package/src/victory-transition/victory-transition.tsx +4 -2
  113. package/src/victory-util/add-events.tsx +5 -2
  114. package/src/victory-util/axis.tsx +7 -3
  115. package/src/victory-util/data.ts +9 -10
  116. package/src/victory-util/domain.ts +8 -4
  117. package/src/victory-util/events.ts +4 -1
  118. package/src/victory-util/helpers.ts +155 -39
  119. package/src/victory-util/hooks/use-animation-state.ts +1 -1
  120. package/src/victory-util/label-helpers.ts +1 -1
  121. package/src/victory-util/log.ts +3 -2
  122. package/src/victory-util/scale.ts +1 -1
  123. package/src/victory-util/textsize.ts +2 -1
  124. package/src/victory-util/transitions.ts +3 -1
  125. package/src/victory-util/type-helpers.ts +0 -5
  126. package/src/victory-util/user-props.ts +1 -1
  127. package/src/victory-util/wrapper.tsx +5 -1
@@ -1,31 +1,77 @@
1
1
  import React, { isValidElement } from "react";
2
- import { defaults, property, pick } from "lodash";
3
- import { CallbackArgs } from "../types/callbacks";
2
+ import defaults from "lodash/defaults";
3
+ import property from "lodash/property";
4
+ import pick from "lodash/pick";
5
+
4
6
  import { ValueOrAccessor } from "../types/prop-types";
5
7
 
6
- // Private Functions
8
+ export type ElementPadding = {
9
+ top: number;
10
+ bottom: number;
11
+ left: number;
12
+ right: number;
13
+ };
14
+
15
+ export type MaybePointData = {
16
+ x?: number;
17
+ x0?: number;
18
+ x1?: number;
19
+ y?: number;
20
+ y0?: number;
21
+ y1?: number;
22
+ _x?: number;
23
+ _x0?: number;
24
+ _x1?: number;
25
+ _y?: number;
26
+ _y0?: number;
27
+ _y1?: number;
28
+ _voronoiX?: number;
29
+ _voronoiY?: number;
30
+ };
7
31
 
8
- function getCartesianRange(props, axis) {
9
- // determine how to lay the axis and what direction positive and negative are
10
- const vertical = axis !== "x";
11
- const padding = getPadding(props);
32
+ /**
33
+ * Determine the range of a cartesian axis
34
+ */
35
+ function getCartesianRange(options: {
36
+ axis: "x" | "y";
37
+ height: number;
38
+ width: number;
39
+ padding: ElementPadding;
40
+ }): [number, number] {
41
+ const vertical = options.axis !== "x";
12
42
  if (vertical) {
13
- return [props.height - padding.bottom, padding.top];
43
+ return [options.height - options.padding.bottom, options.padding.top];
14
44
  }
15
- return [padding.left, props.width - padding.right];
45
+ return [options.padding.left, options.width - options.padding.right];
16
46
  }
17
47
 
18
- function getPolarRange(props, axis) {
19
- if (axis === "x") {
20
- const startAngle = degreesToRadians(props.startAngle || 0);
21
- const endAngle = degreesToRadians(props.endAngle || 360);
48
+ /**
49
+ * Determine the range of a polar axis in radians
50
+ */
51
+ function getPolarRange(options: {
52
+ axis: "x" | "y";
53
+ innerRadius?: number;
54
+ startAngle?: number;
55
+ endAngle?: number;
56
+ padding: ElementPadding;
57
+ height: number;
58
+ width: number;
59
+ }): [number, number] {
60
+ if (options.axis === "x") {
61
+ const startAngle = degreesToRadians(options.startAngle || 0);
62
+ const endAngle = degreesToRadians(options.endAngle || 360);
22
63
  return [startAngle, endAngle];
23
64
  }
24
- return [props.innerRadius || 0, getRadius(props)];
65
+ return [
66
+ options.innerRadius || 0,
67
+ getRadius({
68
+ height: options.height,
69
+ width: options.width,
70
+ padding: options.padding,
71
+ }),
72
+ ];
25
73
  }
26
74
 
27
- // Exported Functions
28
-
29
75
  /**
30
76
  * Creates an object composed of the inverted keys and values of object.
31
77
  * If object contains duplicate values, subsequent values overwrite property assignments of previous values.
@@ -63,21 +109,36 @@ export function omit<T, Keys extends keyof T>(
63
109
  return newObject;
64
110
  }
65
111
 
66
- export function getPoint(datum) {
67
- const exists = (val) => val !== undefined;
112
+ /**
113
+ * Coalesce the x and y values from a data point
114
+ */
115
+ export function getPoint(datum: MaybePointData): MaybePointData {
68
116
  const { _x, _x1, _x0, _voronoiX, _y, _y1, _y0, _voronoiY } = datum;
69
- const defaultX = exists(_x1) ? _x1 : _x;
70
- const defaultY = exists(_y1) ? _y1 : _y;
117
+ const defaultX = _x1 ?? _x;
118
+ const defaultY = _y1 ?? _y;
119
+
71
120
  const point = {
72
- x: exists(_voronoiX) ? _voronoiX : defaultX,
73
- x0: exists(_x0) ? _x0 : _x,
74
- y: exists(_voronoiY) ? _voronoiY : defaultY,
75
- y0: exists(_y0) ? _y0 : _y,
121
+ x: _voronoiX ?? defaultX,
122
+ x0: _x0 ?? _x,
123
+ y: _voronoiY ?? defaultY,
124
+ y0: _y0 ?? _y,
76
125
  };
126
+
77
127
  return defaults({}, point, datum);
78
128
  }
79
129
 
80
- export function scalePoint(props, datum) {
130
+ /**
131
+ * Scale a point based on the origin, direction, and given scale function
132
+ */
133
+ export function scalePoint(
134
+ props: {
135
+ scale: { x: (x?: number) => number; y: (y?: number) => number };
136
+ polar?: boolean;
137
+ horizontal?: boolean;
138
+ origin?: { x: number; y: number };
139
+ },
140
+ datum: MaybePointData,
141
+ ) {
81
142
  const { scale, polar, horizontal } = props;
82
143
  const d = getPoint(datum);
83
144
  const origin = props.origin || { x: 0, y: 0 };
@@ -93,8 +154,12 @@ export function scalePoint(props, datum) {
93
154
  };
94
155
  }
95
156
 
96
- export function getPadding(props, name = "padding") {
97
- const padding = props[name];
157
+ /**
158
+ * Returns a padding value from a number or partial padding values
159
+ */
160
+ export function getPadding(
161
+ padding?: number | Partial<ElementPadding>,
162
+ ): ElementPadding {
98
163
  const paddingVal = typeof padding === "number" ? padding : 0;
99
164
  const paddingObj = typeof padding === "object" ? padding : {};
100
165
  return {
@@ -105,7 +170,10 @@ export function getPadding(props, name = "padding") {
105
170
  };
106
171
  }
107
172
 
108
- export function isTooltip(component) {
173
+ /**
174
+ * Returns true if the component is defined as a tooltip
175
+ */
176
+ export function isTooltip(component?: { type?: { role?: string } }) {
109
177
  const labelRole = component && component.type && component.type.role;
110
178
  return labelRole === "tooltip";
111
179
  }
@@ -138,9 +206,12 @@ export function getStyles(style, defaultStyles) {
138
206
  };
139
207
  }
140
208
 
209
+ /**
210
+ * Returns the value of a prop or accessor function with the given props
211
+ */
141
212
  export function evaluateProp<TValue>(
142
- prop: ValueOrAccessor<TValue, CallbackArgs>,
143
- props: CallbackArgs,
213
+ prop: ValueOrAccessor<TValue, Record<string, any>>,
214
+ props: Record<string, any>,
144
215
  ): TValue {
145
216
  return isFunction(prop) ? prop(props) : prop;
146
217
  }
@@ -166,15 +237,29 @@ export function radiansToDegrees(radians) {
166
237
  return typeof radians === "number" ? radians / (Math.PI / 180) : radians;
167
238
  }
168
239
 
169
- export function getRadius(props) {
170
- const { left, right, top, bottom } = getPadding(props);
171
- const { width, height } = props;
240
+ /**
241
+ * Get the maximum radius that will fit in the container
242
+ */
243
+ export function getRadius(options: {
244
+ height: number;
245
+ width: number;
246
+ padding: ElementPadding;
247
+ }) {
248
+ const { width, height, padding } = options;
249
+ const { left, right, top, bottom } = padding;
172
250
  return Math.min(width - left - right, height - top - bottom) / 2;
173
251
  }
174
252
 
175
- export function getPolarOrigin(props) {
253
+ /**
254
+ * Returns the origin for a polar chart within the padded area
255
+ */
256
+ export function getPolarOrigin(props: {
257
+ height: number;
258
+ width: number;
259
+ padding: ElementPadding;
260
+ }): { x: number; y: number } {
176
261
  const { width, height } = props;
177
- const { top, bottom, left, right } = getPadding(props);
262
+ const { top, bottom, left, right } = getPadding(props.padding);
178
263
  const radius = Math.min(width - left - right, height - top - bottom) / 2;
179
264
  const offsetWidth = width / 2 + left - right;
180
265
  const offsetHeight = height / 2 + top - bottom;
@@ -184,15 +269,43 @@ export function getPolarOrigin(props) {
184
269
  };
185
270
  }
186
271
 
187
- export function getRange(props, axis) {
272
+ /**
273
+ * Determine the range of an axis based on the given props
274
+ */
275
+ export function getRange(
276
+ props: {
277
+ range?: [number, number];
278
+ polar?: boolean;
279
+ innerRadius?: number;
280
+ startAngle?: number;
281
+ endAngle?: number;
282
+ height: number;
283
+ width: number;
284
+ padding: number | Partial<ElementPadding>;
285
+ },
286
+ axis: "x" | "y",
287
+ ) {
188
288
  if (props.range && props.range[axis]) {
189
289
  return props.range[axis];
190
290
  } else if (props.range && Array.isArray(props.range)) {
191
291
  return props.range;
192
292
  }
193
293
  return props.polar
194
- ? getPolarRange(props, axis)
195
- : getCartesianRange(props, axis);
294
+ ? getPolarRange({
295
+ axis,
296
+ innerRadius: props.innerRadius,
297
+ startAngle: props.startAngle,
298
+ endAngle: props.endAngle,
299
+ height: props.height,
300
+ width: props.width,
301
+ padding: getPadding(props.padding),
302
+ })
303
+ : getCartesianRange({
304
+ axis,
305
+ height: props.height,
306
+ width: props.width,
307
+ padding: getPadding(props.padding),
308
+ });
196
309
  }
197
310
 
198
311
  /**
@@ -390,7 +503,10 @@ export function reduceChildren<
390
503
  * @returns {Boolean} returns true if the props object contains `horizontal: true` of if any
391
504
  * children or nested children are horizontal
392
505
  */
393
- export function isHorizontal(props) {
506
+ export function isHorizontal(props: {
507
+ horizontal?: boolean;
508
+ children?: React.ReactNode;
509
+ }) {
394
510
  if (props.horizontal !== undefined || !props.children) {
395
511
  return props.horizontal;
396
512
  }
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { defaults } from "lodash";
2
+ import defaults from "lodash/defaults";
3
3
 
4
4
  import * as Collection from "../collection";
5
5
  import * as Transitions from "../transitions";
@@ -1,6 +1,6 @@
1
1
  import { VictoryLabelProps } from "../victory-label/victory-label";
2
2
  import * as Helpers from "./helpers";
3
- import { defaults } from "lodash";
3
+ import defaults from "lodash/defaults";
4
4
 
5
5
  // Private Functions
6
6
 
@@ -1,8 +1,9 @@
1
- /* global console */
1
+ /* global console process */
2
2
  /* eslint-disable no-console */
3
3
 
4
- // TODO: Use "warning" npm module like React is switching to.
5
4
  export function warn(message: string) {
5
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
6
+ // @ts-ignore - Webpack DefinePlugin will replace process.env.NODE_ENV
6
7
  if (process.env.NODE_ENV !== "production") {
7
8
  if (console && console.warn) {
8
9
  console.warn(message);
@@ -1,4 +1,4 @@
1
- import { isPlainObject } from "lodash";
1
+ import isPlainObject from "lodash/isPlainObject";
2
2
  import * as Helpers from "./helpers";
3
3
  import * as Collection from "./collection";
4
4
  import * as d3Scale from "victory-vendor/d3-scale";
@@ -1,6 +1,7 @@
1
1
  // http://www.pearsonified.com/2012/01/characters-per-line.php
2
2
  /* eslint-disable no-magic-numbers */
3
- import { defaults, memoize } from "lodash";
3
+ import defaults from "lodash/defaults";
4
+ import memoize from "lodash/memoize";
4
5
 
5
6
  // Based on measuring specific character widths
6
7
  // as in the following example https://bl.ocks.org/tophtucker/62f93a4658387bb61e4510c37e2e97cf
@@ -1,5 +1,7 @@
1
- import { defaults, identity } from "lodash";
2
1
  import React from "react";
2
+ import defaults from "lodash/defaults";
3
+ import identity from "lodash/identity";
4
+
3
5
  import { AnimatePropTypeInterface } from "../types/prop-types";
4
6
 
5
7
  function getDatumKey(datum, idx) {
@@ -30,11 +30,6 @@ export function getValueForAxis<T = unknown>(
30
30
  return value;
31
31
  }
32
32
 
33
- // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
34
- export function isFunction<T = Function>(func?: unknown): func is T {
35
- return typeof func === "function";
36
- }
37
-
38
33
  export function isDate(value: unknown): value is Date {
39
34
  return value instanceof Date;
40
35
  }
@@ -78,7 +78,7 @@ export function assert<T>(
78
78
  * @returns {Object}: object containing remaining acceptable props
79
79
  */
80
80
  export const getSafeUserProps = <T>(
81
- props: T,
81
+ props: T extends Record<string, any> ? T : never,
82
82
  ): Record<SafeAttribute, string> => {
83
83
  const propsToFilter = { ...props };
84
84
  return Object.fromEntries(
@@ -1,5 +1,9 @@
1
- import { defaults, uniq, groupBy, uniqBy } from "lodash";
2
1
  import React from "react";
2
+ import defaults from "lodash/defaults";
3
+ import uniq from "lodash/uniq";
4
+ import groupBy from "lodash/groupBy";
5
+ import uniqBy from "lodash/uniqBy";
6
+
3
7
  import * as Axis from "./axis";
4
8
  import * as Style from "./style";
5
9
  import * as Data from "./data";