victory-core 35.11.2 → 36.1.0

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 (47) hide show
  1. package/LICENSE.txt +30 -0
  2. package/dist/victory-core.js +4376 -1142
  3. package/dist/victory-core.min.js +1 -1
  4. package/es/index.d.ts +6 -0
  5. package/es/index.js +8 -2
  6. package/es/victory-accessible-group/victory-accessible-group.js +1 -3
  7. package/es/victory-animation/victory-animation.js +1 -3
  8. package/es/victory-clip-container/victory-clip-container.js +1 -3
  9. package/es/victory-container/victory-container.js +1 -3
  10. package/es/victory-label/victory-label.js +3 -3
  11. package/es/victory-portal/portal.js +1 -3
  12. package/es/victory-portal/victory-portal.js +1 -3
  13. package/es/victory-primitives/point.js +1 -1
  14. package/es/victory-transition/victory-transition.js +1 -3
  15. package/es/victory-util/add-events.js +305 -308
  16. package/es/victory-util/hooks.js +137 -0
  17. package/es/victory-util/line-helpers.js +45 -0
  18. package/es/{victory-primitives/path-helpers.js → victory-util/point-path-helpers.js} +0 -0
  19. package/es/victory-util/timer.js +1 -3
  20. package/es/victory-util/wrapper.js +372 -457
  21. package/lib/index.d.ts +6 -0
  22. package/lib/index.js +78 -8
  23. package/lib/victory-accessible-group/victory-accessible-group.js +1 -3
  24. package/lib/victory-animation/victory-animation.js +1 -3
  25. package/lib/victory-clip-container/victory-clip-container.js +1 -3
  26. package/lib/victory-container/victory-container.js +1 -3
  27. package/lib/victory-label/victory-label.js +3 -3
  28. package/lib/victory-portal/portal.js +1 -3
  29. package/lib/victory-portal/victory-portal.js +1 -3
  30. package/lib/victory-primitives/point.js +10 -10
  31. package/lib/victory-transition/victory-transition.js +1 -3
  32. package/lib/victory-util/add-events.js +301 -304
  33. package/lib/victory-util/hooks.js +162 -0
  34. package/lib/victory-util/line-helpers.js +56 -0
  35. package/lib/{victory-primitives/path-helpers.js → victory-util/point-path-helpers.js} +0 -0
  36. package/lib/victory-util/timer.js +1 -3
  37. package/lib/victory-util/wrapper.js +389 -446
  38. package/package.json +7 -3
  39. package/src/index.d.ts +6 -0
  40. package/src/index.js +5 -1
  41. package/src/victory-label/victory-label.js +3 -3
  42. package/src/victory-primitives/point.js +1 -1
  43. package/src/victory-util/hooks.js +131 -0
  44. package/src/victory-util/line-helpers.js +54 -0
  45. package/src/{victory-primitives/path-helpers.js → victory-util/point-path-helpers.js} +0 -0
  46. package/src/victory-util/transitions.js +0 -1
  47. package/src/victory-util/wrapper.js +422 -518
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "victory-core",
3
- "version": "35.11.2",
3
+ "version": "36.1.0",
4
4
  "description": "Victory Core",
5
5
  "keywords": [
6
6
  "data visualization",
@@ -28,11 +28,15 @@
28
28
  "prop-types": "^15.5.8",
29
29
  "react-fast-compare": "^2.0.0"
30
30
  },
31
+ "resolutions": {
32
+ "d3-interpolate/d3-color": "^3.0.0"
33
+ },
31
34
  "peerDependencies": {
32
35
  "react": "^16.6.0 || ^17.0.0"
33
36
  },
34
37
  "scripts": {
35
- "version": "nps build-libs && nps build-dists"
38
+ "version": "yarn run nps build-libs && nps build-dists"
36
39
  },
37
- "sideEffects": false
40
+ "sideEffects": false,
41
+ "gitHead": "038cd9b70d9ce54ac6b861014165583760734c99"
38
42
  }
package/src/index.d.ts CHANGED
@@ -429,6 +429,12 @@ export interface VictoryThemeDefinition {
429
429
  labels?: VictoryLabelStyleObject | VictoryLabelStyleObject[];
430
430
  };
431
431
  } & VictoryCommonThemeProps;
432
+ histogram?: {
433
+ style?: {
434
+ data?: VictoryStyleObject;
435
+ labels?: VictoryLabelStyleObject | VictoryLabelStyleObject[];
436
+ };
437
+ } & VictoryCommonThemeProps;
432
438
  independentAxis?: {
433
439
  style?: {
434
440
  axis?: VictoryStyleObject;
package/src/index.js CHANGED
@@ -40,7 +40,11 @@ export * as TextSize from "./victory-util/textsize";
40
40
  export { default as Timer } from "./victory-util/timer";
41
41
  export * as Transitions from "./victory-util/transitions";
42
42
  export * as CommonProps from "./victory-util/common-props";
43
- export { default as Wrapper } from "./victory-util/wrapper";
43
+ export * as Wrapper from "./victory-util/wrapper";
44
44
  export * as Axis from "./victory-util/axis";
45
45
  export { default as TimerContext } from "./victory-util/timer-context";
46
46
  export { default as PortalContext } from "./victory-portal/portal-context";
47
+ export * from "./victory-util/hooks";
48
+ export * as LineHelpers from "./victory-util/line-helpers";
49
+ // TODO: Fix this default export
50
+ export { default as PointPathHelpers } from "./victory-util/point-path-helpers";
@@ -51,7 +51,7 @@ const getSingleValue = (prop, index = 0) => {
51
51
  return Array.isArray(prop) ? prop[index] || prop[0] : prop;
52
52
  };
53
53
 
54
- const useMultiLineBackgrounds = (props) => {
54
+ const shouldUseMultilineBackgrounds = (props) => {
55
55
  const { backgroundStyle, backgroundPadding } = props;
56
56
  return (
57
57
  (Array.isArray(backgroundStyle) && !isEmpty(backgroundStyle)) ||
@@ -365,7 +365,7 @@ const getChildBackgrounds = (calculatedProps, tspanValues) => {
365
365
  };
366
366
 
367
367
  const getBackgroundElement = (calculatedProps, tspanValues) => {
368
- return useMultiLineBackgrounds(calculatedProps)
368
+ return shouldUseMultilineBackgrounds(calculatedProps)
369
369
  ? getChildBackgrounds(calculatedProps, tspanValues)
370
370
  : getFullBackground(calculatedProps, tspanValues);
371
371
  };
@@ -387,7 +387,7 @@ const calculateSpanDy = (tspanValues, i, calculatedProps) => {
387
387
  currentCaps / 2 +
388
388
  previousCaps / 2;
389
389
 
390
- return useMultiLineBackgrounds(calculatedProps)
390
+ return shouldUseMultilineBackgrounds(calculatedProps)
391
391
  ? textHeight +
392
392
  current.backgroundPadding.top +
393
393
  previous.backgroundPadding.bottom
@@ -2,7 +2,7 @@ import React from "react";
2
2
  import PropTypes from "prop-types";
3
3
  import { assign } from "lodash";
4
4
  import * as Helpers from "../victory-util/helpers";
5
- import pathHelpers from "./path-helpers";
5
+ import pathHelpers from "../victory-util/point-path-helpers";
6
6
  import * as CommonProps from "../victory-util/common-props";
7
7
  import Path from "./path";
8
8
 
@@ -0,0 +1,131 @@
1
+ import React from "react";
2
+ import { defaults, some } from "lodash";
3
+
4
+ import * as Collection from "./collection";
5
+ import * as Transitions from "./transitions";
6
+
7
+ export const usePreviousProps = (props) => {
8
+ const ref = React.useRef();
9
+ React.useEffect(() => {
10
+ ref.current = props;
11
+ });
12
+ return ref.current || {};
13
+ };
14
+
15
+ const INITIAL_STATE = {
16
+ nodesShouldLoad: false,
17
+ nodesDoneLoad: false,
18
+ animating: true
19
+ };
20
+
21
+ export const useAnimationState = (initialState = INITIAL_STATE) => {
22
+ const [state, _setState] = React.useState(initialState);
23
+
24
+ // This allows us to use a state object and maintain the same API as this.setState
25
+ const setState = React.useCallback(
26
+ (newState) => {
27
+ _setState((oldState) => ({ ...oldState, ...newState }));
28
+ },
29
+ [_setState]
30
+ );
31
+
32
+ // This is a copy of Wrapper.getAnimationProps
33
+ const getAnimationProps = React.useCallback(
34
+ (props, child, index) => {
35
+ if (!props.animate) {
36
+ return child.props.animate;
37
+ }
38
+ const getFilteredState = () => {
39
+ let childrenTransitions = state && state.childrenTransitions;
40
+ childrenTransitions = Collection.isArrayOfArrays(childrenTransitions)
41
+ ? childrenTransitions[index]
42
+ : childrenTransitions;
43
+ return defaults({ childrenTransitions }, state);
44
+ };
45
+
46
+ let getTransitions = props.animate && props.animate.getTransitions;
47
+ const filteredState = getFilteredState();
48
+ const parentState =
49
+ (props.animate && props.animate.parentState) || filteredState;
50
+ if (!getTransitions) {
51
+ const getTransitionProps = Transitions.getTransitionPropsFactory(
52
+ props,
53
+ filteredState,
54
+ (newState) => setState(newState)
55
+ );
56
+ getTransitions = (childComponent) =>
57
+ getTransitionProps(childComponent, index);
58
+ }
59
+ return defaults(
60
+ { getTransitions, parentState },
61
+ props.animate,
62
+ child.props.animate
63
+ );
64
+ },
65
+ [state, setState]
66
+ );
67
+
68
+ // This is a copy of Wrapper.setAnimationState
69
+ const setAnimationState = React.useCallback(
70
+ (props, nextProps) => {
71
+ if (!props.animate) {
72
+ return;
73
+ }
74
+ if (props.animate.parentState) {
75
+ const nodesWillExit = props.animate.parentState.nodesWillExit;
76
+ const oldProps = nodesWillExit ? props : null;
77
+ const newState = defaults(
78
+ { oldProps, nextProps },
79
+ props.animate.parentState
80
+ );
81
+ setState(newState);
82
+ } else {
83
+ const oldChildren = React.Children.toArray(props.children);
84
+ const nextChildren = React.Children.toArray(nextProps.children);
85
+ const isContinuous = (child) => {
86
+ const check = (c) => c.type && c.type.continuous;
87
+ return Array.isArray(child) ? some(child, check) : check(child);
88
+ };
89
+
90
+ const continuous =
91
+ !props.polar &&
92
+ some(oldChildren, (child) => {
93
+ return (
94
+ isContinuous(child) ||
95
+ (child.props.children && isContinuous(child.props.children))
96
+ );
97
+ });
98
+ const {
99
+ nodesWillExit,
100
+ nodesWillEnter,
101
+ childrenTransitions,
102
+ nodesShouldEnter
103
+ } = Transitions.getInitialTransitionState(oldChildren, nextChildren);
104
+
105
+ setState({
106
+ nodesWillExit,
107
+ nodesWillEnter,
108
+ nodesShouldEnter,
109
+ childrenTransitions: Collection.isArrayOfArrays(childrenTransitions)
110
+ ? childrenTransitions[0]
111
+ : childrenTransitions,
112
+ oldProps: nodesWillExit ? props : null,
113
+ nextProps,
114
+ continuous
115
+ });
116
+ }
117
+ },
118
+ [setState]
119
+ );
120
+
121
+ const getProps = React.useCallback(
122
+ (initialProps) => {
123
+ return state && state.nodesWillExit
124
+ ? state.oldProps || initialProps
125
+ : initialProps;
126
+ },
127
+ [state]
128
+ );
129
+
130
+ return { state, setState, getAnimationProps, setAnimationState, getProps };
131
+ };
@@ -0,0 +1,54 @@
1
+ import * as d3Shape from "d3-shape";
2
+
3
+ const defined = (d) => {
4
+ const y = d._y1 !== undefined ? d._y1 : d._y;
5
+ return y !== null && y !== undefined && d._y0 !== null;
6
+ };
7
+
8
+ const getXAccessor = (scale) => {
9
+ return (d) => scale.x(d._x1 !== undefined ? d._x1 : d._x);
10
+ };
11
+
12
+ const getYAccessor = (scale) => {
13
+ return (d) => scale.y(d._y1 !== undefined ? d._y1 : d._y);
14
+ };
15
+
16
+ const getAngleAccessor = (scale) => {
17
+ return (d) => {
18
+ const x = scale.x(d._x1 !== undefined ? d._x1 : d._x);
19
+ return -1 * x + Math.PI / 2;
20
+ };
21
+ };
22
+
23
+ const toNewName = (interpolation) => {
24
+ // d3 shape changed the naming scheme for interpolators from "basis" -> "curveBasis" etc.
25
+ const capitalize = (s) => s && s[0].toUpperCase() + s.slice(1);
26
+ return `curve${capitalize(interpolation)}`;
27
+ };
28
+
29
+ export const getLineFunction = (props) => {
30
+ const { polar, scale, horizontal } = props;
31
+ const defaultOpenCurve = polar ? false : true;
32
+ const openCurve =
33
+ props.openCurve === undefined ? defaultOpenCurve : props.openCurve;
34
+ const interpolationFunction =
35
+ typeof props.interpolation === "function" && props.interpolation;
36
+ const interpolationName =
37
+ typeof props.interpolation === "string" &&
38
+ (!openCurve
39
+ ? `${toNewName(props.interpolation)}Closed`
40
+ : toNewName(props.interpolation));
41
+ return polar
42
+ ? d3Shape
43
+ .lineRadial()
44
+ .defined(defined)
45
+ .curve(interpolationFunction || d3Shape[interpolationName])
46
+ .angle(getAngleAccessor(scale))
47
+ .radius(getYAccessor(scale))
48
+ : d3Shape
49
+ .line()
50
+ .defined(defined)
51
+ .curve(interpolationFunction || d3Shape[interpolationName])
52
+ .x(horizontal ? getYAccessor(scale) : getXAccessor(scale))
53
+ .y(horizontal ? getXAccessor(scale) : getYAccessor(scale));
54
+ };
@@ -82,7 +82,6 @@ export function getInitialTransitionState(oldChildren, nextChildren) {
82
82
  if (!newChild || oldChild.type !== newChild.type) {
83
83
  return {};
84
84
  }
85
-
86
85
  const { entering, exiting } =
87
86
  getNodeTransitions(getChildData(oldChild), getChildData(newChild)) || {};
88
87