victory-core 36.6.3 → 36.6.6
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.
- package/CHANGELOG.md +25 -0
- package/dist/victory-core.js +2053 -4568
- package/dist/victory-core.min.js +1 -1
- package/es/index.d.ts +0 -1
- package/es/index.js +1 -2
- package/es/types/callbacks.d.ts +0 -1
- package/es/types/prop-types.d.ts +3 -3
- package/es/v37/clone.d.ts +23 -0
- package/es/v37/clone.js +32 -0
- package/es/v37/index.d.ts +5 -0
- package/es/v37/index.js +4 -0
- package/es/{victory-state → v37/victory-state}/defaults.d.ts +0 -0
- package/es/{victory-state → v37/victory-state}/defaults.js +0 -0
- package/es/v37/victory-state/helpers/get-axis-data.d.ts +3 -0
- package/es/{victory-state → v37/victory-state}/helpers/get-axis-data.js +1 -1
- package/es/{victory-state → v37/victory-state}/helpers/get-data.d.ts +1 -1
- package/es/{victory-state → v37/victory-state}/helpers/get-data.js +1 -1
- package/{lib → es/v37}/victory-state/helpers/get-domain.d.ts +1 -1
- package/es/{victory-state → v37/victory-state}/helpers/get-domain.js +1 -1
- package/{lib → es/v37}/victory-state/helpers/get-range.d.ts +1 -1
- package/es/{victory-state → v37/victory-state}/helpers/get-range.js +2 -2
- package/{lib → es/v37}/victory-state/helpers/get-scale.d.ts +1 -1
- package/es/{victory-state → v37/victory-state}/helpers/get-scale.js +2 -2
- package/es/v37/victory-state/index.d.ts +4 -0
- package/es/{victory-state/index.d.ts → v37/victory-state/index.js} +1 -1
- package/{lib → es/v37}/victory-state/types.d.ts +2 -2
- package/es/{victory-state → v37/victory-state}/types.js +0 -0
- package/{lib → es/v37}/victory-state/victory-provider.d.ts +5 -4
- package/es/{victory-state → v37/victory-state}/victory-provider.js +58 -27
- package/es/v37/victory-state/with-victory-provider.d.ts +7 -0
- package/es/v37/victory-state/with-victory-provider.js +43 -0
- package/es/{victory-util → v37}/with-container.d.ts +2 -2
- package/es/{victory-util → v37}/with-container.js +1 -1
- package/es/v37/with-normalized-props.d.ts +17 -0
- package/es/v37/with-normalized-props.js +18 -0
- package/es/victory-label/victory-label.d.ts +5 -4
- package/es/victory-util/helpers.d.ts +3 -2
- package/es/victory-util/immutable-types.d.ts +2523 -0
- package/es/victory-util/immutable.d.ts +1 -1
- package/es/victory-util/index.d.ts +0 -1
- package/es/victory-util/index.js +1 -2
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -14
- package/lib/types/callbacks.d.ts +0 -1
- package/lib/types/prop-types.d.ts +3 -3
- package/lib/v37/clone.d.ts +23 -0
- package/lib/v37/clone.js +43 -0
- package/lib/v37/index.d.ts +5 -0
- package/lib/v37/index.js +57 -0
- package/lib/{victory-state → v37/victory-state}/defaults.d.ts +0 -0
- package/lib/{victory-state → v37/victory-state}/defaults.js +0 -0
- package/lib/v37/victory-state/helpers/get-axis-data.d.ts +3 -0
- package/lib/{victory-state → v37/victory-state}/helpers/get-axis-data.js +1 -1
- package/lib/{victory-state → v37/victory-state}/helpers/get-data.d.ts +1 -1
- package/lib/{victory-state → v37/victory-state}/helpers/get-data.js +1 -1
- package/{es → lib/v37}/victory-state/helpers/get-domain.d.ts +1 -1
- package/lib/{victory-state → v37/victory-state}/helpers/get-domain.js +1 -1
- package/{es → lib/v37}/victory-state/helpers/get-range.d.ts +1 -1
- package/lib/{victory-state → v37/victory-state}/helpers/get-range.js +2 -2
- package/{es → lib/v37}/victory-state/helpers/get-scale.d.ts +1 -1
- package/lib/{victory-state → v37/victory-state}/helpers/get-scale.js +2 -2
- package/lib/v37/victory-state/index.d.ts +4 -0
- package/lib/{victory-state → v37/victory-state}/index.js +13 -0
- package/{es → lib/v37}/victory-state/types.d.ts +2 -2
- package/lib/{victory-state → v37/victory-state}/types.js +0 -0
- package/{es → lib/v37}/victory-state/victory-provider.d.ts +5 -4
- package/lib/{victory-state → v37/victory-state}/victory-provider.js +60 -28
- package/lib/v37/victory-state/with-victory-provider.d.ts +7 -0
- package/lib/v37/victory-state/with-victory-provider.js +56 -0
- package/lib/{victory-util → v37}/with-container.d.ts +2 -2
- package/lib/{victory-util → v37}/with-container.js +1 -1
- package/lib/v37/with-normalized-props.d.ts +17 -0
- package/lib/v37/with-normalized-props.js +29 -0
- package/lib/victory-label/victory-label.d.ts +5 -4
- package/lib/victory-util/helpers.d.ts +3 -2
- package/lib/victory-util/immutable-types.d.ts +2523 -0
- package/lib/victory-util/immutable.d.ts +1 -1
- package/lib/victory-util/index.d.ts +0 -1
- package/lib/victory-util/index.js +0 -14
- package/package.json +2 -2
- package/src/index.ts +0 -1
- package/src/types/callbacks.ts +0 -2
- package/src/types/prop-types.ts +4 -3
- package/src/v37/clone.tsx +30 -0
- package/src/v37/index.tsx +4 -0
- package/src/{victory-state → v37/victory-state}/defaults.ts +0 -0
- package/src/{victory-state → v37/victory-state}/helpers/get-axis-data.ts +2 -2
- package/src/{victory-state → v37/victory-state}/helpers/get-data.ts +3 -3
- package/src/{victory-state → v37/victory-state}/helpers/get-domain.ts +2 -2
- package/src/{victory-state → v37/victory-state}/helpers/get-range.ts +3 -3
- package/src/{victory-state → v37/victory-state}/helpers/get-scale.ts +6 -3
- package/src/{victory-state → v37/victory-state}/index.ts +1 -0
- package/src/{victory-state → v37/victory-state}/types.ts +2 -2
- package/src/{victory-state → v37/victory-state}/victory-provider.tsx +61 -27
- package/src/v37/victory-state/with-victory-provider.tsx +53 -0
- package/src/{victory-util → v37}/with-container.tsx +2 -2
- package/src/v37/with-normalized-props.tsx +43 -0
- package/src/victory-label/victory-label.tsx +4 -4
- package/src/victory-util/data.ts +1 -1
- package/src/victory-util/helpers.ts +3 -2
- package/src/victory-util/immutable-types.d.ts +2523 -0
- package/src/victory-util/immutable.ts +1 -1
- package/src/victory-util/index.ts +0 -1
- package/es/victory-state/helpers/get-axis-data.d.ts +0 -3
- package/es/victory-state/index.js +0 -2
- package/lib/victory-state/helpers/get-axis-data.d.ts +0 -3
- package/lib/victory-state/index.d.ts +0 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Iterable, List, Map } from "immutable";
|
|
1
|
+
import type { Iterable, List, Map } from "./immutable-types";
|
|
2
2
|
export declare const IMMUTABLE_ITERABLE = "@@__IMMUTABLE_ITERABLE__@@";
|
|
3
3
|
export declare const IMMUTABLE_RECORD = "@@__IMMUTABLE_RECORD__@@";
|
|
4
4
|
export declare const IMMUTABLE_LIST = "@@__IMMUTABLE_LIST__@@";
|
|
@@ -25,5 +25,4 @@ export { default as TimerContext } from "./timer-context";
|
|
|
25
25
|
export * as Transitions from "./transitions";
|
|
26
26
|
export * as UserProps from "./user-props";
|
|
27
27
|
export * as Wrapper from "./wrapper";
|
|
28
|
-
export * from "./with-container";
|
|
29
28
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -159,20 +159,6 @@ var _Wrapper = _interopRequireWildcard(require("./wrapper"));
|
|
|
159
159
|
|
|
160
160
|
exports.Wrapper = _Wrapper;
|
|
161
161
|
|
|
162
|
-
var _withContainer = require("./with-container");
|
|
163
|
-
|
|
164
|
-
Object.keys(_withContainer).forEach(function (key) {
|
|
165
|
-
if (key === "default" || key === "__esModule") return;
|
|
166
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
167
|
-
if (key in exports && exports[key] === _withContainer[key]) return;
|
|
168
|
-
Object.defineProperty(exports, key, {
|
|
169
|
-
enumerable: true,
|
|
170
|
-
get: function () {
|
|
171
|
-
return _withContainer[key];
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
|
|
176
162
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
177
163
|
|
|
178
164
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "victory-core",
|
|
3
|
-
"version": "36.6.
|
|
3
|
+
"version": "36.6.6",
|
|
4
4
|
"description": "Victory Core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data visualization",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"lodash": "^4.17.21",
|
|
24
24
|
"prop-types": "^15.8.1",
|
|
25
25
|
"react-fast-compare": "^3.2.0",
|
|
26
|
-
"victory-vendor": "^36.6.
|
|
26
|
+
"victory-vendor": "^36.6.6"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"react": ">=16.6.0"
|
package/src/index.ts
CHANGED
package/src/types/callbacks.ts
CHANGED
package/src/types/prop-types.ts
CHANGED
|
@@ -9,14 +9,14 @@ import {
|
|
|
9
9
|
AnimationEasing,
|
|
10
10
|
AnimationStyle,
|
|
11
11
|
} from "../victory-animation/victory-animation";
|
|
12
|
-
import { StringOrNumberOrCallback } from "./callbacks";
|
|
12
|
+
import { CallbackArgs, StringOrNumberOrCallback } from "./callbacks";
|
|
13
13
|
|
|
14
14
|
export type AxisType = "x" | "y";
|
|
15
15
|
export type DatumValue = number | string | Date | null | undefined;
|
|
16
16
|
export type Datum = any;
|
|
17
17
|
export type ForAxes<T> = T | { x?: T; y?: T };
|
|
18
18
|
export type ID = number | string;
|
|
19
|
-
export type ValueOrAccessor<ValueType
|
|
19
|
+
export type ValueOrAccessor<ValueType, PropsType = CallbackArgs> =
|
|
20
20
|
| ValueType
|
|
21
21
|
| ((props: PropsType) => ValueType);
|
|
22
22
|
export type Tuple<T> = [T, T];
|
|
@@ -137,7 +137,8 @@ export type CategoryPropType =
|
|
|
137
137
|
};
|
|
138
138
|
|
|
139
139
|
export type DataGetterPropType = ValueOrAccessor<
|
|
140
|
-
string | string[] | number | number[]
|
|
140
|
+
string | string[] | number | number[],
|
|
141
|
+
any // The arg will be the `datum`, which can have any type
|
|
141
142
|
>;
|
|
142
143
|
|
|
143
144
|
export type InterpolationPropType =
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Syntax sugar for `React.cloneElement`, so that we can use JSX instead
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* // Before:
|
|
8
|
+
* const children = React.cloneElement(props.groupComponent, { prop2 }, props.children);
|
|
9
|
+
* return React.cloneElement(props.containerComponent, { prop1 }, children);
|
|
10
|
+
*
|
|
11
|
+
* // After:
|
|
12
|
+
* return (
|
|
13
|
+
* <Clone element={props.containerComponent} prop1={prop1}>
|
|
14
|
+
* <Clone element={props.groupComponent} prop2={prop2}>
|
|
15
|
+
* {props.children}
|
|
16
|
+
* </Clone>
|
|
17
|
+
* </Clone>
|
|
18
|
+
* );
|
|
19
|
+
*/
|
|
20
|
+
export const Clone = <TProps,>(
|
|
21
|
+
props: React.PropsWithChildren<
|
|
22
|
+
{
|
|
23
|
+
element: React.ReactElement<TProps>;
|
|
24
|
+
children?: React.ReactNode | React.ReactNode[];
|
|
25
|
+
} & TProps
|
|
26
|
+
>,
|
|
27
|
+
) => {
|
|
28
|
+
const { children, element, ...rest } = props;
|
|
29
|
+
return React.cloneElement(element, rest as unknown as TProps, children);
|
|
30
|
+
};
|
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AxisType, Datum, DomainValue } from "
|
|
2
|
-
import { isKeyValueObject } from "
|
|
1
|
+
import { AxisType, Datum, DomainValue } from "../../../types/prop-types";
|
|
2
|
+
import { isKeyValueObject } from "../../../victory-util/type-helpers";
|
|
3
3
|
|
|
4
4
|
export function getAxisData(data: Datum[], axis: AxisType) {
|
|
5
5
|
return data.reduce((acc, datum) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { get, isNil, orderBy } from "lodash";
|
|
2
1
|
import * as React from "react";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { get, isNil, orderBy } from "lodash";
|
|
3
|
+
import { Datum, DatumValue } from "../../../types/prop-types";
|
|
4
|
+
import { isKeyValueObject } from "../../../victory-util/type-helpers";
|
|
5
5
|
import { VictoryProviderProps } from "../types";
|
|
6
6
|
|
|
7
7
|
type DataProps = Pick<
|
|
@@ -4,14 +4,14 @@ import {
|
|
|
4
4
|
getValueForAxis,
|
|
5
5
|
isDate,
|
|
6
6
|
isTuple,
|
|
7
|
-
} from "
|
|
7
|
+
} from "../../../victory-util/type-helpers";
|
|
8
8
|
import { VictoryProviderProps } from "../types";
|
|
9
9
|
import {
|
|
10
10
|
Tuple,
|
|
11
11
|
AxisType,
|
|
12
12
|
DomainTuple,
|
|
13
13
|
DomainValue,
|
|
14
|
-
} from "
|
|
14
|
+
} from "../../../types/prop-types";
|
|
15
15
|
|
|
16
16
|
type DomainProps = Pick<
|
|
17
17
|
VictoryProviderProps,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AxisType, Padding, RangeTuple } from "
|
|
2
|
-
import { getPadding } from "
|
|
3
|
-
import { getValueForAxis, isTuple } from "
|
|
1
|
+
import { AxisType, Padding, RangeTuple } from "../../../types/prop-types";
|
|
2
|
+
import { getPadding } from "../../../victory-util/helpers";
|
|
3
|
+
import { getValueForAxis, isTuple } from "../../../victory-util/type-helpers";
|
|
4
4
|
import { VictoryProviderProps } from "../types";
|
|
5
5
|
|
|
6
6
|
type RangeProps = Pick<
|
|
@@ -4,9 +4,12 @@ import {
|
|
|
4
4
|
scaleLog,
|
|
5
5
|
scaleSqrt,
|
|
6
6
|
} from "victory-vendor/d3-scale";
|
|
7
|
-
import { AxisType, D3ScaleFn, ScalePropType } from "
|
|
8
|
-
import * as Collection from "
|
|
9
|
-
import {
|
|
7
|
+
import { AxisType, D3ScaleFn, ScalePropType } from "../../../types/prop-types";
|
|
8
|
+
import * as Collection from "../../../victory-util/collection";
|
|
9
|
+
import {
|
|
10
|
+
getValueForAxis,
|
|
11
|
+
isFunction,
|
|
12
|
+
} from "../../../victory-util/type-helpers";
|
|
10
13
|
import { VictoryProviderProps } from "../types";
|
|
11
14
|
import { getAxisData } from "./get-axis-data";
|
|
12
15
|
|
|
@@ -5,8 +5,8 @@ import {
|
|
|
5
5
|
RangeTuple,
|
|
6
6
|
ScalePropType,
|
|
7
7
|
ValueOrAxes,
|
|
8
|
-
} from "
|
|
9
|
-
import { PaddingProps } from "
|
|
8
|
+
} from "../../types/prop-types";
|
|
9
|
+
import { PaddingProps } from "../../victory-theme/types";
|
|
10
10
|
|
|
11
11
|
// These are all the props that are used to calculate data, domain, range, and scale
|
|
12
12
|
export interface VictoryCalculatedStateProps {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { createContext, useContext } from "react";
|
|
3
|
-
import { D3ScaleFn, DomainTuple, ForAxes } from "
|
|
3
|
+
import { D3ScaleFn, DomainTuple, ForAxes } from "../../types/prop-types";
|
|
4
4
|
import { FormattedDatum, getData } from "./helpers/get-data";
|
|
5
5
|
import { getDomain } from "./helpers/get-domain";
|
|
6
6
|
import { getRange } from "./helpers/get-range";
|
|
@@ -14,27 +14,42 @@ export interface ContextType {
|
|
|
14
14
|
data: FormattedDatum[];
|
|
15
15
|
scale: ScaleType;
|
|
16
16
|
domain: DomainType;
|
|
17
|
-
|
|
17
|
+
updateChildProps: (id: symbol, props: VictoryProviderProps | null) => void;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
const VictoryContext = createContext<ContextType | null>(null);
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
children,
|
|
24
|
-
...initialProps
|
|
25
|
-
}: VictoryProviderProps) {
|
|
26
|
-
// We need to store the props in state so they can be overwritten by child components
|
|
27
|
-
const [props, setProps] = React.useState(initialProps);
|
|
22
|
+
type CollectedProps = { [id: symbol]: VictoryCalculatedStateProps };
|
|
28
23
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
function useNormalizedProps(): ContextType {
|
|
25
|
+
const [collectedProps, setCollectedProps] = React.useState<CollectedProps>(
|
|
26
|
+
{},
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const updateChildProps = React.useCallback(
|
|
30
|
+
(id: symbol, newProps: VictoryCalculatedStateProps | null) => {
|
|
31
|
+
setCollectedProps((prev) => {
|
|
32
|
+
const result = { ...prev };
|
|
33
|
+
if (newProps === null) {
|
|
34
|
+
delete result[id];
|
|
35
|
+
} else {
|
|
36
|
+
result[id] = newProps;
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
33
39
|
});
|
|
34
40
|
},
|
|
35
41
|
[],
|
|
36
42
|
);
|
|
37
43
|
|
|
44
|
+
// TEMP: combine all props into a single result:
|
|
45
|
+
// TODO: instead, we should intelligently aggregate all these props
|
|
46
|
+
const props = Object.values(
|
|
47
|
+
collectedProps,
|
|
48
|
+
).reduce<VictoryCalculatedStateProps>(
|
|
49
|
+
(result, childProps) => Object.assign(result, childProps),
|
|
50
|
+
{},
|
|
51
|
+
);
|
|
52
|
+
|
|
38
53
|
const data = React.useMemo(() => {
|
|
39
54
|
return getData(props);
|
|
40
55
|
}, [props]);
|
|
@@ -69,18 +84,39 @@ export function VictoryProvider({
|
|
|
69
84
|
};
|
|
70
85
|
}, [props, domain, range]);
|
|
71
86
|
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
87
|
+
const normalizedProps = React.useMemo(
|
|
88
|
+
() => ({
|
|
89
|
+
scale,
|
|
90
|
+
data,
|
|
91
|
+
domain,
|
|
92
|
+
updateChildProps,
|
|
93
|
+
}),
|
|
94
|
+
[scale, data, domain, updateChildProps],
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
return normalizedProps;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function VictoryProvider({
|
|
101
|
+
children,
|
|
102
|
+
...providerProps
|
|
103
|
+
}: VictoryProviderProps) {
|
|
104
|
+
const value = useNormalizedProps();
|
|
105
|
+
|
|
106
|
+
// TODO: sync the providerProps
|
|
78
107
|
|
|
79
108
|
return (
|
|
80
109
|
<VictoryContext.Provider value={value}>{children}</VictoryContext.Provider>
|
|
81
110
|
);
|
|
82
111
|
}
|
|
83
112
|
|
|
113
|
+
export function useVictoryContextMaybe<T>(
|
|
114
|
+
selector: (value: ContextType | null) => T,
|
|
115
|
+
): T {
|
|
116
|
+
const context = useContext(VictoryContext);
|
|
117
|
+
return selector(context);
|
|
118
|
+
}
|
|
119
|
+
|
|
84
120
|
export function useVictoryContext<T>(selector: (value: ContextType) => T): T {
|
|
85
121
|
const context = useContext(VictoryContext);
|
|
86
122
|
if (!context) {
|
|
@@ -102,15 +138,13 @@ export function useDomain() {
|
|
|
102
138
|
}
|
|
103
139
|
|
|
104
140
|
// This function keeps props in sync betwen the VictoryProvider and child components
|
|
105
|
-
export function useVictoryProviderSync(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
)
|
|
109
|
-
|
|
141
|
+
export function useVictoryProviderSync(props: VictoryCalculatedStateProps) {
|
|
142
|
+
const updateChildProps = useVictoryContext((value) => value.updateChildProps);
|
|
143
|
+
const [myId] = React.useState(() =>
|
|
144
|
+
Symbol("UniqueIdFor(VictoryProviderChild)"),
|
|
145
|
+
);
|
|
110
146
|
|
|
111
147
|
React.useEffect(() => {
|
|
112
|
-
|
|
113
|
-
}, []);
|
|
114
|
-
|
|
115
|
-
return props;
|
|
148
|
+
updateChildProps(myId, props);
|
|
149
|
+
}, [updateChildProps, props]);
|
|
116
150
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useVictoryContextMaybe, VictoryProvider } from "./victory-provider";
|
|
3
|
+
import { VictoryCommonProps } from "../../victory-util/common-props";
|
|
4
|
+
import { Clone } from "../clone";
|
|
5
|
+
import { VictoryProviderProps } from "./types";
|
|
6
|
+
|
|
7
|
+
/* eslint-disable react/prop-types */
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Ensures the component is wrapped by a VictoryProvider, if not already.
|
|
11
|
+
*/
|
|
12
|
+
export function withVictoryProvider<
|
|
13
|
+
TComp extends React.FC<TProps>,
|
|
14
|
+
TProps extends React.PropsWithChildren<VictoryCommonProps>,
|
|
15
|
+
>(Comp: TComp): TComp {
|
|
16
|
+
const WithVictoryProvider = React.memo((props: TProps) => {
|
|
17
|
+
const updateChildProps = useVictoryContextMaybe(
|
|
18
|
+
(value) => value?.updateChildProps,
|
|
19
|
+
);
|
|
20
|
+
const hasParentProvider = !!updateChildProps;
|
|
21
|
+
|
|
22
|
+
React.useEffect(() => {
|
|
23
|
+
if (!hasParentProvider) return;
|
|
24
|
+
|
|
25
|
+
const id = Symbol("WithVictoryProvider");
|
|
26
|
+
updateChildProps(id, props as VictoryProviderProps);
|
|
27
|
+
// eslint-disable-next-line consistent-return
|
|
28
|
+
return () => updateChildProps(id, null);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// @ts-expect-error "TProps not assignable to LibraryManagedAttributes"
|
|
32
|
+
let result = <Comp {...props}>{props.children}</Comp>;
|
|
33
|
+
|
|
34
|
+
if (!hasParentProvider) {
|
|
35
|
+
// Wrap with a parent Provider:
|
|
36
|
+
result = (
|
|
37
|
+
<VictoryProvider>
|
|
38
|
+
<Clone element={props.containerComponent} {...props}>
|
|
39
|
+
{result}
|
|
40
|
+
</Clone>
|
|
41
|
+
</VictoryProvider>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
});
|
|
46
|
+
const name = Comp.displayName || Comp.name;
|
|
47
|
+
WithVictoryProvider.displayName = name
|
|
48
|
+
? `WithVictoryProvider(${name})`
|
|
49
|
+
: "WithVictoryProvider";
|
|
50
|
+
|
|
51
|
+
// @ts-expect-error "WithVictoryProvider does not overlap with TComp"
|
|
52
|
+
return WithVictoryProvider as TComp;
|
|
53
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { VictoryProvider, VictoryProviderProps } from "
|
|
2
|
+
import { VictoryProvider, VictoryProviderProps } from "./victory-state";
|
|
3
3
|
import { VictoryContainer } from "../victory-container/victory-container";
|
|
4
|
-
import { VictoryCommonProps } from "
|
|
4
|
+
import { VictoryCommonProps } from "../victory-util/common-props";
|
|
5
5
|
|
|
6
6
|
const defaultProviderProps = {
|
|
7
7
|
width: 450,
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { VictoryCommonProps } from "../victory-util/common-props";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import {
|
|
4
|
+
useVictoryContext,
|
|
5
|
+
VictoryProviderProps,
|
|
6
|
+
withVictoryProvider,
|
|
7
|
+
} from "./victory-state";
|
|
8
|
+
|
|
9
|
+
type FC<TProps> = (props: TProps) => JSX.Element;
|
|
10
|
+
|
|
11
|
+
export function withNormalizedProps<
|
|
12
|
+
TProps extends React.PropsWithChildren<VictoryCommonProps>,
|
|
13
|
+
TDefaultPropKeys extends keyof TProps,
|
|
14
|
+
>(
|
|
15
|
+
config: {
|
|
16
|
+
displayName: string;
|
|
17
|
+
propTypes?: React.WeakValidationMap<Omit<TProps, keyof VictoryCommonProps>>;
|
|
18
|
+
defaultProps: Pick<TProps, TDefaultPropKeys>;
|
|
19
|
+
/** @deprecated */
|
|
20
|
+
initialProviderProps?: Partial<VictoryProviderProps>;
|
|
21
|
+
},
|
|
22
|
+
WrappedComponent: React.FC<TProps>,
|
|
23
|
+
) {
|
|
24
|
+
WrappedComponent.displayName = config.displayName;
|
|
25
|
+
const WithNormalizedProps: FC<TProps> = withVictoryProvider<
|
|
26
|
+
FC<TProps>,
|
|
27
|
+
TProps
|
|
28
|
+
>((props: TProps) => {
|
|
29
|
+
const normalizedProps = useVictoryContext((v) => v);
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<WrappedComponent {...props} {...normalizedProps}>
|
|
33
|
+
{props.children}
|
|
34
|
+
</WrappedComponent>
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return Object.assign(WithNormalizedProps, {
|
|
39
|
+
displayName: `WithNormalizedProps(${config.displayName}`,
|
|
40
|
+
defaultProps: config.defaultProps,
|
|
41
|
+
propTypes: config.propTypes,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -17,8 +17,8 @@ import {
|
|
|
17
17
|
NumberOrCallback,
|
|
18
18
|
StringOrCallback,
|
|
19
19
|
StringOrNumberOrCallback,
|
|
20
|
-
ValueOrCallback,
|
|
21
20
|
} from "../types/callbacks";
|
|
21
|
+
import { ValueOrAccessor } from "../types/prop-types";
|
|
22
22
|
import {
|
|
23
23
|
PaddingProps,
|
|
24
24
|
VerticalAnchorType,
|
|
@@ -56,11 +56,11 @@ export interface VictoryLabelProps {
|
|
|
56
56
|
tabIndex?: NumberOrCallback;
|
|
57
57
|
text?: string[] | StringOrNumberOrCallback;
|
|
58
58
|
textComponent?: React.ReactElement;
|
|
59
|
-
textAnchor?:
|
|
59
|
+
textAnchor?: ValueOrAccessor<TextAnchorType>;
|
|
60
60
|
title?: string;
|
|
61
|
-
transform?:
|
|
61
|
+
transform?: ValueOrAccessor<string | object>;
|
|
62
62
|
tspanComponent?: React.ReactElement;
|
|
63
|
-
verticalAnchor?:
|
|
63
|
+
verticalAnchor?: ValueOrAccessor<VerticalAnchorType>;
|
|
64
64
|
x?: number;
|
|
65
65
|
y?: number;
|
|
66
66
|
dx?: StringOrNumberOrCallback;
|
package/src/victory-util/data.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/* eslint-disable no-use-before-define */
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { defaults, isFunction, property, pick, assign, keys } from "lodash";
|
|
4
|
-
import { CallbackArgs
|
|
4
|
+
import { CallbackArgs } from "../types/callbacks";
|
|
5
|
+
import { ValueOrAccessor } from "../types/prop-types";
|
|
5
6
|
|
|
6
7
|
// Private Functions
|
|
7
8
|
|
|
@@ -128,7 +129,7 @@ export function getStyles(style, defaultStyles) {
|
|
|
128
129
|
}
|
|
129
130
|
|
|
130
131
|
export function evaluateProp<TValue>(
|
|
131
|
-
prop:
|
|
132
|
+
prop: ValueOrAccessor<TValue, CallbackArgs>,
|
|
132
133
|
props: CallbackArgs,
|
|
133
134
|
): TValue {
|
|
134
135
|
return isFunction(prop) ? prop(props) : prop;
|