victory-core 36.5.1 → 36.6.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.
- package/CHANGELOG.md +18 -0
- package/dist/victory-core.js +5188 -35122
- package/dist/victory-core.min.js +1 -2
- package/es/index.d.ts +1 -0
- package/es/victory-animation/victory-animation.js +1 -1
- package/es/victory-label/victory-label.js +19 -19
- package/es/victory-portal/portal.js +2 -2
- package/es/victory-primitives/arc.js +1 -1
- package/es/victory-primitives/circle.d.ts +1 -0
- package/es/victory-primitives/line.d.ts +1 -0
- package/es/victory-primitives/path.d.ts +1 -0
- package/es/victory-primitives/rect.d.ts +1 -0
- package/es/victory-primitives/tspan.d.ts +1 -0
- package/es/victory-state/victory-provider.d.ts +1 -0
- package/es/victory-state/victory-provider.js +8 -8
- package/es/victory-transition/victory-transition.js +22 -22
- package/es/victory-util/add-events.d.ts +5 -2
- package/es/victory-util/add-events.js +4 -5
- package/es/victory-util/axis.js +22 -20
- package/es/victory-util/collection.d.ts +2 -2
- package/es/victory-util/data.d.ts +1 -1
- package/es/victory-util/data.js +2 -2
- package/es/victory-util/domain.js +4 -4
- package/es/victory-util/events.js +2 -2
- package/es/victory-util/hooks/use-animation-state.d.ts +22 -0
- package/es/victory-util/hooks/use-animation-state.js +3 -3
- package/es/victory-util/label-helpers.js +12 -12
- package/es/victory-util/prop-types.js +2 -2
- package/es/victory-util/scale.js +1 -1
- package/es/victory-util/selection.d.ts +5 -1
- package/es/victory-util/selection.js +15 -15
- package/es/victory-util/style.js +12 -12
- package/es/victory-util/textsize.js +2 -2
- package/es/victory-util/transitions.js +2 -2
- package/es/victory-util/with-container.d.ts +1 -1
- package/es/victory-util/with-container.js +2 -1
- package/es/victory-util/wrapper.js +8 -8
- package/lib/index.d.ts +1 -0
- package/lib/victory-label/victory-label.js +19 -19
- package/lib/victory-portal/portal.js +2 -2
- package/lib/victory-primitives/circle.d.ts +1 -0
- package/lib/victory-primitives/line.d.ts +1 -0
- package/lib/victory-primitives/path.d.ts +1 -0
- package/lib/victory-primitives/rect.d.ts +1 -0
- package/lib/victory-primitives/tspan.d.ts +1 -0
- package/lib/victory-state/victory-provider.d.ts +1 -0
- package/lib/victory-state/victory-provider.js +7 -9
- package/lib/victory-transition/victory-transition.js +21 -21
- package/lib/victory-util/add-events.d.ts +5 -2
- package/lib/victory-util/add-events.js +4 -4
- package/lib/victory-util/axis.js +22 -20
- package/lib/victory-util/collection.d.ts +2 -2
- package/lib/victory-util/data.d.ts +1 -1
- package/lib/victory-util/data.js +2 -2
- package/lib/victory-util/domain.js +4 -4
- package/lib/victory-util/events.js +2 -2
- package/lib/victory-util/hooks/use-animation-state.d.ts +22 -0
- package/lib/victory-util/hooks/use-animation-state.js +3 -3
- package/lib/victory-util/label-helpers.js +12 -12
- package/lib/victory-util/prop-types.js +2 -2
- package/lib/victory-util/scale.js +1 -1
- package/lib/victory-util/selection.d.ts +5 -1
- package/lib/victory-util/selection.js +15 -15
- package/lib/victory-util/style.js +12 -12
- package/lib/victory-util/textsize.js +2 -2
- package/lib/victory-util/transitions.js +2 -2
- package/lib/victory-util/with-container.d.ts +1 -1
- package/lib/victory-util/with-container.js +5 -3
- package/lib/victory-util/wrapper.js +8 -8
- package/package.json +252 -7
- package/src/index.ts +1 -0
- package/src/victory-animation/victory-animation.tsx +1 -1
- package/src/victory-label/victory-label.tsx +20 -25
- package/src/victory-primitives/arc.tsx +1 -1
- package/src/victory-state/victory-provider.tsx +6 -11
- package/src/victory-transition/victory-transition.tsx +24 -26
- package/src/victory-util/add-events.tsx +14 -9
- package/src/victory-util/axis.tsx +12 -13
- package/src/victory-util/collection.tsx +13 -4
- package/src/victory-util/data.ts +2 -3
- package/src/victory-util/domain.ts +6 -6
- package/src/victory-util/events.ts +1 -2
- package/src/victory-util/hooks/{use-animation-state.js → use-animation-state.ts} +24 -9
- package/src/victory-util/label-helpers.ts +8 -12
- package/src/victory-util/point-path-helpers.ts +1 -1
- package/src/victory-util/prop-types.ts +1 -2
- package/src/victory-util/scale.ts +1 -1
- package/src/victory-util/selection.ts +12 -13
- package/src/victory-util/style.ts +10 -11
- package/src/victory-util/textsize.ts +3 -3
- package/src/victory-util/transitions.ts +1 -2
- package/src/victory-util/with-container.tsx +2 -5
- package/src/victory-util/wrapper.tsx +8 -10
- package/dist/victory-core.min.js.LICENSE.txt +0 -19
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { createContext,
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
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";
|
|
@@ -81,17 +81,12 @@ export function VictoryProvider({
|
|
|
81
81
|
);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
type ContextValue = ContextType | null;
|
|
85
|
-
|
|
86
84
|
export function useVictoryContext<T>(selector: (value: ContextType) => T): T {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
return selector(context);
|
|
94
|
-
});
|
|
85
|
+
const context = useContext(VictoryContext);
|
|
86
|
+
if (!context) {
|
|
87
|
+
throw new Error("useVictoryContext must be used within a VictoryProvider");
|
|
88
|
+
}
|
|
89
|
+
return selector(context);
|
|
95
90
|
}
|
|
96
91
|
|
|
97
92
|
export function useScale() {
|
|
@@ -73,7 +73,7 @@ export class VictoryTransition extends React.Component<
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
componentDidMount() {
|
|
76
|
-
this.setState({ nodesShouldLoad: true }); //eslint-disable-line react/no-did-mount-set-state
|
|
76
|
+
this.setState({ nodesShouldLoad: true }); // eslint-disable-line react/no-did-mount-set-state
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
shouldComponentUpdate(nextProps: VictoryTransitionProps) {
|
|
@@ -101,24 +101,23 @@ export class VictoryTransition extends React.Component<
|
|
|
101
101
|
const state = animate.parentState;
|
|
102
102
|
const oldProps = state.nodesWillExit ? props : null;
|
|
103
103
|
return { oldProps, nextProps };
|
|
104
|
-
} else {
|
|
105
|
-
const oldChildren = React.Children.toArray(props.children);
|
|
106
|
-
const nextChildren = React.Children.toArray(nextProps.children);
|
|
107
|
-
const {
|
|
108
|
-
nodesWillExit,
|
|
109
|
-
nodesWillEnter,
|
|
110
|
-
childrenTransitions,
|
|
111
|
-
nodesShouldEnter,
|
|
112
|
-
} = Transitions.getInitialTransitionState(oldChildren, nextChildren);
|
|
113
|
-
return {
|
|
114
|
-
nodesWillExit,
|
|
115
|
-
nodesWillEnter,
|
|
116
|
-
childrenTransitions,
|
|
117
|
-
nodesShouldEnter,
|
|
118
|
-
oldProps: nodesWillExit ? props : null,
|
|
119
|
-
nextProps,
|
|
120
|
-
};
|
|
121
104
|
}
|
|
105
|
+
const oldChildren = React.Children.toArray(props.children);
|
|
106
|
+
const nextChildren = React.Children.toArray(nextProps.children);
|
|
107
|
+
const {
|
|
108
|
+
nodesWillExit,
|
|
109
|
+
nodesWillEnter,
|
|
110
|
+
childrenTransitions,
|
|
111
|
+
nodesShouldEnter,
|
|
112
|
+
} = Transitions.getInitialTransitionState(oldChildren, nextChildren);
|
|
113
|
+
return {
|
|
114
|
+
nodesWillExit,
|
|
115
|
+
nodesWillEnter,
|
|
116
|
+
childrenTransitions,
|
|
117
|
+
nodesShouldEnter,
|
|
118
|
+
oldProps: nodesWillExit ? props : null,
|
|
119
|
+
nextProps,
|
|
120
|
+
};
|
|
122
121
|
}
|
|
123
122
|
|
|
124
123
|
private getDomainFromChildren(
|
|
@@ -149,15 +148,14 @@ export class VictoryTransition extends React.Component<
|
|
|
149
148
|
: childProps.domain && childProps.domain[axis];
|
|
150
149
|
if (!childProps.children && domain) {
|
|
151
150
|
return domain;
|
|
152
|
-
} else {
|
|
153
|
-
const childDomains = getChildDomains([child]);
|
|
154
|
-
return childDomains.length === 0
|
|
155
|
-
? [0, 1]
|
|
156
|
-
: [
|
|
157
|
-
Collection.getMinValue(childDomains),
|
|
158
|
-
Collection.getMaxValue(childDomains),
|
|
159
|
-
];
|
|
160
151
|
}
|
|
152
|
+
const childDomains = getChildDomains([child]);
|
|
153
|
+
return childDomains.length === 0
|
|
154
|
+
? [0, 1]
|
|
155
|
+
: [
|
|
156
|
+
Collection.getMinValue(childDomains),
|
|
157
|
+
Collection.getMaxValue(childDomains),
|
|
158
|
+
];
|
|
161
159
|
}
|
|
162
160
|
|
|
163
161
|
pickProps() {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/*global window:false */
|
|
2
1
|
import React from "react";
|
|
3
2
|
import {
|
|
4
3
|
assign,
|
|
@@ -37,7 +36,7 @@ const defaultComponents: NonNullable<MixinOptions["components"]> = [
|
|
|
37
36
|
export type MixinOptions = {
|
|
38
37
|
components?: Array<{
|
|
39
38
|
name: string;
|
|
40
|
-
index?: string;
|
|
39
|
+
index?: string | number;
|
|
41
40
|
}>;
|
|
42
41
|
};
|
|
43
42
|
|
|
@@ -58,12 +57,19 @@ export interface EventMixinCommonProps
|
|
|
58
57
|
export interface EventsMixinClass<TProps> {
|
|
59
58
|
renderContainer(
|
|
60
59
|
component: React.ReactElement,
|
|
61
|
-
children: React.ReactElement[],
|
|
60
|
+
children: React.ReactElement | React.ReactElement[],
|
|
62
61
|
): React.ReactElement;
|
|
63
62
|
cacheValues<TThis>(this: TThis, obj: Partial<TThis>): void;
|
|
64
63
|
getEventState: typeof Events.getEventState;
|
|
64
|
+
renderData(props: TProps);
|
|
65
65
|
renderContinuousData(props: TProps);
|
|
66
66
|
animateComponent(props: TProps, defaultAnimationWhitelist);
|
|
67
|
+
getComponentProps(
|
|
68
|
+
component: React.ReactElement,
|
|
69
|
+
type: string,
|
|
70
|
+
index: number,
|
|
71
|
+
): TProps;
|
|
72
|
+
dataKeys: string[];
|
|
67
73
|
}
|
|
68
74
|
|
|
69
75
|
/**
|
|
@@ -214,13 +220,12 @@ export function addEvents<
|
|
|
214
220
|
if (!props.standalone && component.name === "parent") {
|
|
215
221
|
// don't check for changes on parent props for non-standalone components
|
|
216
222
|
return undefined;
|
|
217
|
-
} else {
|
|
218
|
-
return component.index !== undefined
|
|
219
|
-
? getState(component.index, component.name)
|
|
220
|
-
: this.dataKeys
|
|
221
|
-
.map((key) => getState(key, component.name))
|
|
222
|
-
.filter(Boolean);
|
|
223
223
|
}
|
|
224
|
+
return component.index !== undefined
|
|
225
|
+
? getState(component.index, component.name)
|
|
226
|
+
: this.dataKeys
|
|
227
|
+
.map((key) => getState(key, component.name))
|
|
228
|
+
.filter(Boolean);
|
|
224
229
|
})
|
|
225
230
|
.filter(Boolean);
|
|
226
231
|
return stateChanges;
|
|
@@ -154,14 +154,13 @@ function getDefaultTickFormat(props) {
|
|
|
154
154
|
return stringTicks(props)
|
|
155
155
|
? (x, index) => tickValues[index]
|
|
156
156
|
: fallbackFormat;
|
|
157
|
-
} else {
|
|
158
|
-
const invertedStringMap = stringMap && invert(stringMap);
|
|
159
|
-
const tickValueArray = orderBy(values(stringMap), (n) => n);
|
|
160
|
-
const dataNames = tickValueArray.map((tick) => invertedStringMap[tick]);
|
|
161
|
-
// string ticks should have one tick of padding at the beginning
|
|
162
|
-
const dataTicks = ["", ...dataNames, ""];
|
|
163
|
-
return (x) => dataTicks[x];
|
|
164
157
|
}
|
|
158
|
+
const invertedStringMap = stringMap && invert(stringMap);
|
|
159
|
+
const tickValueArray = orderBy(values(stringMap), (n) => n);
|
|
160
|
+
const dataNames = tickValueArray.map((tick) => invertedStringMap[tick]);
|
|
161
|
+
// string ticks should have one tick of padding at the beginning
|
|
162
|
+
const dataTicks = ["", ...dataNames, ""];
|
|
163
|
+
return (x) => dataTicks[x];
|
|
165
164
|
}
|
|
166
165
|
|
|
167
166
|
function getStringTicks(props) {
|
|
@@ -207,7 +206,7 @@ function getTickArray(props) {
|
|
|
207
206
|
const newTickArray = [] as Array<{ value: number; index: number }>;
|
|
208
207
|
const domain = (props.domain && props.domain[axis]) || props.domain;
|
|
209
208
|
if (arr) {
|
|
210
|
-
arr.forEach(
|
|
209
|
+
arr.forEach((t, index) => {
|
|
211
210
|
if (Array.isArray(domain)) {
|
|
212
211
|
if (
|
|
213
212
|
t >= Collection.getMinValue(domain) &&
|
|
@@ -226,7 +225,8 @@ function getTickArray(props) {
|
|
|
226
225
|
}
|
|
227
226
|
});
|
|
228
227
|
return newTickArray;
|
|
229
|
-
}
|
|
228
|
+
}
|
|
229
|
+
return undefined;
|
|
230
230
|
};
|
|
231
231
|
return Array.isArray(tickArray) && tickArray.length
|
|
232
232
|
? buildTickArray(tickArray)
|
|
@@ -261,9 +261,8 @@ export function getTickFormat(props, scale) {
|
|
|
261
261
|
return props.tickFormat(invertedStringMap[tick], index, stringTickArray);
|
|
262
262
|
};
|
|
263
263
|
return stringMap ? applyStringTicks : tickFormat;
|
|
264
|
-
} else {
|
|
265
|
-
return (x) => x;
|
|
266
264
|
}
|
|
265
|
+
return (x) => x;
|
|
267
266
|
}
|
|
268
267
|
|
|
269
268
|
function downsampleTicks(ticks: number[], tickCount: number) {
|
|
@@ -304,7 +303,7 @@ export function getTicks(props, scale: D3Scale, filterZero = false) {
|
|
|
304
303
|
* @param {String} axis: either x or y
|
|
305
304
|
* @returns {Array} returns a domain from tickValues
|
|
306
305
|
*/
|
|
307
|
-
//eslint-disable-next-line max-statements
|
|
306
|
+
// eslint-disable-next-line max-statements
|
|
308
307
|
function getDomainFromData(props, axis) {
|
|
309
308
|
const { polar, startAngle = 0, endAngle = 360 } = props;
|
|
310
309
|
const tickArray = getTickArray(props);
|
|
@@ -315,7 +314,7 @@ function getDomainFromData(props, axis) {
|
|
|
315
314
|
const minDomain = Domain.getMinFromProps(props, axis);
|
|
316
315
|
const maxDomain = Domain.getMaxFromProps(props, axis);
|
|
317
316
|
const tickStrings = stringTicks(props);
|
|
318
|
-
const ticks = tickValues.map((value) =>
|
|
317
|
+
const ticks = tickValues.map((value) => Number(value));
|
|
319
318
|
const defaultMin = tickStrings ? 1 : Collection.getMinValue(ticks);
|
|
320
319
|
const defaultMax = tickStrings
|
|
321
320
|
? tickValues.length
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
function isNonEmptyArray(
|
|
1
|
+
function isNonEmptyArray<T>(
|
|
2
|
+
collection: Array<T> | unknown,
|
|
3
|
+
): collection is Array<T> {
|
|
2
4
|
return Array.isArray(collection) && collection.length > 0;
|
|
3
5
|
}
|
|
4
6
|
|
|
@@ -23,15 +25,22 @@ export function containsNumbers(collection) {
|
|
|
23
25
|
);
|
|
24
26
|
}
|
|
25
27
|
|
|
26
|
-
export function containsOnlyStrings(
|
|
28
|
+
export function containsOnlyStrings(
|
|
29
|
+
collection: Array<string> | unknown,
|
|
30
|
+
): collection is Array<string> {
|
|
27
31
|
return (
|
|
28
32
|
isNonEmptyArray(collection) &&
|
|
29
33
|
collection.every((value) => typeof value === "string")
|
|
30
34
|
);
|
|
31
35
|
}
|
|
32
36
|
|
|
33
|
-
export function isArrayOfArrays(
|
|
34
|
-
|
|
37
|
+
export function isArrayOfArrays<T>(
|
|
38
|
+
collection: Array<T> | Array<Array<T>> | unknown,
|
|
39
|
+
): collection is Array<Array<T>> {
|
|
40
|
+
return (
|
|
41
|
+
isNonEmptyArray(collection) &&
|
|
42
|
+
(collection as Array<Array<T>>).every(Array.isArray)
|
|
43
|
+
);
|
|
35
44
|
}
|
|
36
45
|
|
|
37
46
|
export function removeUndefined(arr) {
|
package/src/victory-util/data.ts
CHANGED
|
@@ -117,16 +117,15 @@ function addEventKeys(props, data) {
|
|
|
117
117
|
} else if (hasEventKeyAccessor) {
|
|
118
118
|
const eventKey = eventKeyAccessor(datum, index);
|
|
119
119
|
return eventKey !== undefined ? assign({ eventKey }, datum) : datum;
|
|
120
|
-
} else {
|
|
121
|
-
return datum;
|
|
122
120
|
}
|
|
121
|
+
return datum;
|
|
123
122
|
});
|
|
124
123
|
}
|
|
125
124
|
|
|
126
125
|
// Exported Functions
|
|
127
126
|
|
|
128
127
|
// This method will remove data points that fall outside of the desired domain (non-continuous charts only)
|
|
129
|
-
export function formatDataFromDomain(dataset, domain, defaultBaseline) {
|
|
128
|
+
export function formatDataFromDomain(dataset, domain, defaultBaseline?) {
|
|
130
129
|
const exists = (val) => val !== undefined;
|
|
131
130
|
|
|
132
131
|
const minDomainX = Collection.getMinValue(domain.x);
|
|
@@ -74,7 +74,7 @@ function getExtremeFromData(dataset, axis, type = "min") {
|
|
|
74
74
|
return containsDate ? new Date(result) : result;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
//eslint-disable-next-line max-statements
|
|
77
|
+
// eslint-disable-next-line max-statements
|
|
78
78
|
function padDomain(domain, props, axis) {
|
|
79
79
|
if (!props.domainPadding) {
|
|
80
80
|
return domain;
|
|
@@ -311,15 +311,15 @@ export function getDomainFromMinMax(min, max) {
|
|
|
311
311
|
const verySmallDate = 1;
|
|
312
312
|
const minVal =
|
|
313
313
|
val instanceof Date
|
|
314
|
-
? new Date(
|
|
315
|
-
:
|
|
314
|
+
? new Date(Number(val) - verySmallDate)
|
|
315
|
+
: Number(val) - verySmallNumber;
|
|
316
316
|
const maxVal =
|
|
317
317
|
val instanceof Date
|
|
318
|
-
? new Date(
|
|
319
|
-
:
|
|
318
|
+
? new Date(Number(val) + verySmallDate)
|
|
319
|
+
: Number(val) + verySmallNumber;
|
|
320
320
|
return val === 0 ? [0, maxVal] : [minVal, maxVal];
|
|
321
321
|
};
|
|
322
|
-
return
|
|
322
|
+
return Number(min) === Number(max) ? getSinglePointDomain(max) : [min, max];
|
|
323
323
|
}
|
|
324
324
|
|
|
325
325
|
/**
|
|
@@ -447,9 +447,8 @@ export function getExternalMutation(
|
|
|
447
447
|
// coerce arrays to strings before matching
|
|
448
448
|
const stringArray = mutation[type].map((m) => `${m}`);
|
|
449
449
|
return includes(stringArray, identifier[type]);
|
|
450
|
-
} else {
|
|
451
|
-
return false;
|
|
452
450
|
}
|
|
451
|
+
return false;
|
|
453
452
|
};
|
|
454
453
|
|
|
455
454
|
mutations = Array.isArray(mutations) ? mutations : [mutations];
|
|
@@ -4,18 +4,33 @@ import { defaults, some } from "lodash";
|
|
|
4
4
|
import * as Collection from "../collection";
|
|
5
5
|
import * as Transitions from "../transitions";
|
|
6
6
|
|
|
7
|
-
const INITIAL_STATE = {
|
|
7
|
+
const INITIAL_STATE: AnimationState = {
|
|
8
8
|
nodesShouldLoad: false,
|
|
9
9
|
nodesDoneLoad: false,
|
|
10
10
|
animating: true,
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
+
type AnyObject = Record<string, any>;
|
|
14
|
+
|
|
15
|
+
export type AnimationState = {
|
|
16
|
+
nodesShouldLoad?: boolean;
|
|
17
|
+
nodesDoneLoad?: boolean;
|
|
18
|
+
animating?: boolean;
|
|
19
|
+
childrenTransitions?: any[];
|
|
20
|
+
nodesWillExit?: boolean;
|
|
21
|
+
nodesWillEnter?: boolean;
|
|
22
|
+
nodesShouldEnter?: boolean;
|
|
23
|
+
oldProps?: AnyObject;
|
|
24
|
+
nextProps?: AnyObject;
|
|
25
|
+
continuous?: boolean;
|
|
26
|
+
};
|
|
27
|
+
|
|
13
28
|
export const useAnimationState = (initialState = INITIAL_STATE) => {
|
|
14
29
|
const [state, _setState] = React.useState(initialState);
|
|
15
30
|
|
|
16
31
|
// This allows us to use a state object and maintain the same API as this.setState
|
|
17
32
|
const setState = React.useCallback(
|
|
18
|
-
(newState) => {
|
|
33
|
+
(newState: AnimationState) => {
|
|
19
34
|
_setState((oldState) => ({ ...oldState, ...newState }));
|
|
20
35
|
},
|
|
21
36
|
[_setState],
|
|
@@ -23,8 +38,8 @@ export const useAnimationState = (initialState = INITIAL_STATE) => {
|
|
|
23
38
|
|
|
24
39
|
// This is a copy of Wrapper.getAnimationProps
|
|
25
40
|
const getAnimationProps = React.useCallback(
|
|
26
|
-
(props, child, index) => {
|
|
27
|
-
if (!props
|
|
41
|
+
(props: AnyObject | undefined, child, index) => {
|
|
42
|
+
if (!props?.animate) {
|
|
28
43
|
return child.props.animate;
|
|
29
44
|
}
|
|
30
45
|
const getFilteredState = () => {
|
|
@@ -59,8 +74,8 @@ export const useAnimationState = (initialState = INITIAL_STATE) => {
|
|
|
59
74
|
|
|
60
75
|
// This is a copy of Wrapper.setAnimationState
|
|
61
76
|
const setAnimationState = React.useCallback(
|
|
62
|
-
(props, nextProps) => {
|
|
63
|
-
if (!props
|
|
77
|
+
(props: AnyObject | undefined, nextProps) => {
|
|
78
|
+
if (!props?.animate) {
|
|
64
79
|
return;
|
|
65
80
|
}
|
|
66
81
|
if (props.animate.parentState) {
|
|
@@ -81,7 +96,7 @@ export const useAnimationState = (initialState = INITIAL_STATE) => {
|
|
|
81
96
|
|
|
82
97
|
const continuous =
|
|
83
98
|
!props.polar &&
|
|
84
|
-
some(oldChildren, (child) => {
|
|
99
|
+
some(oldChildren, (child: React.ReactElement) => {
|
|
85
100
|
return (
|
|
86
101
|
isContinuous(child) ||
|
|
87
102
|
(child.props.children && isContinuous(child.props.children))
|
|
@@ -101,7 +116,7 @@ export const useAnimationState = (initialState = INITIAL_STATE) => {
|
|
|
101
116
|
childrenTransitions: Collection.isArrayOfArrays(childrenTransitions)
|
|
102
117
|
? childrenTransitions[0]
|
|
103
118
|
: childrenTransitions,
|
|
104
|
-
oldProps: nodesWillExit ? props :
|
|
119
|
+
oldProps: nodesWillExit ? props : undefined,
|
|
105
120
|
nextProps,
|
|
106
121
|
continuous,
|
|
107
122
|
});
|
|
@@ -111,7 +126,7 @@ export const useAnimationState = (initialState = INITIAL_STATE) => {
|
|
|
111
126
|
);
|
|
112
127
|
|
|
113
128
|
const getProps = React.useCallback(
|
|
114
|
-
(initialProps) => {
|
|
129
|
+
(initialProps: AnyObject) => {
|
|
115
130
|
return state && state.nodesWillExit
|
|
116
131
|
? state.oldProps || initialProps
|
|
117
132
|
: initialProps;
|
|
@@ -12,9 +12,8 @@ function getVerticalAnchor(props, datum) {
|
|
|
12
12
|
return datum.verticalAnchor || labelStyle.verticalAnchor;
|
|
13
13
|
} else if (!props.horizontal) {
|
|
14
14
|
return sign >= 0 ? "end" : "start";
|
|
15
|
-
} else {
|
|
16
|
-
return "middle";
|
|
17
15
|
}
|
|
16
|
+
return "middle";
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
function getTextAnchor(props, datum) {
|
|
@@ -26,9 +25,8 @@ function getTextAnchor(props, datum) {
|
|
|
26
25
|
return datum.verticalAnchor || labelStyle.verticalAnchor;
|
|
27
26
|
} else if (!horizontal) {
|
|
28
27
|
return "middle";
|
|
29
|
-
} else {
|
|
30
|
-
return sign >= 0 ? "start" : "end";
|
|
31
28
|
}
|
|
29
|
+
return sign >= 0 ? "start" : "end";
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
function getAngle(props, datum) {
|
|
@@ -66,13 +64,12 @@ function getPosition(props, datum) {
|
|
|
66
64
|
const { x, y } = Helpers.scalePoint(props, datum);
|
|
67
65
|
if (!polar) {
|
|
68
66
|
return { x, y };
|
|
69
|
-
} else {
|
|
70
|
-
const polarPadding = getPolarPadding(props, datum);
|
|
71
|
-
return {
|
|
72
|
-
x: x + polarPadding.x,
|
|
73
|
-
y: y + polarPadding.y,
|
|
74
|
-
};
|
|
75
67
|
}
|
|
68
|
+
const polarPadding = getPolarPadding(props, datum);
|
|
69
|
+
return {
|
|
70
|
+
x: x + polarPadding.x,
|
|
71
|
+
y: y + polarPadding.y,
|
|
72
|
+
};
|
|
76
73
|
}
|
|
77
74
|
|
|
78
75
|
function getPolarPadding(props, datum) {
|
|
@@ -106,9 +103,8 @@ function getPolarOrientation(degrees) {
|
|
|
106
103
|
// eslint-disable-next-line no-magic-numbers
|
|
107
104
|
} else if (degrees > 135 && degrees < 225) {
|
|
108
105
|
return "left";
|
|
109
|
-
} else {
|
|
110
|
-
return "bottom";
|
|
111
106
|
}
|
|
107
|
+
return "bottom";
|
|
112
108
|
}
|
|
113
109
|
|
|
114
110
|
// Exported Functions
|
|
@@ -50,9 +50,8 @@ export function getParentSVG(
|
|
|
50
50
|
const getParent = (target) => {
|
|
51
51
|
if (target.nodeName === "svg") {
|
|
52
52
|
return target;
|
|
53
|
-
} else {
|
|
54
|
-
return target.parentNode ? getParent(target.parentNode) : target;
|
|
55
53
|
}
|
|
54
|
+
return target.parentNode ? getParent(target.parentNode) : target;
|
|
56
55
|
};
|
|
57
56
|
return getParent(evt.target);
|
|
58
57
|
}
|
|
@@ -83,7 +82,7 @@ export function getSVGEventCoordinates(
|
|
|
83
82
|
export function getDomainCoordinates(
|
|
84
83
|
props: Pick<VictoryCommonProps, "scale" | "horizontal">,
|
|
85
84
|
domain?: DomainPropType,
|
|
86
|
-
)
|
|
85
|
+
) {
|
|
87
86
|
const { horizontal } = props;
|
|
88
87
|
const scale = props.scale as ScaleXYPropType;
|
|
89
88
|
// FIXME: add support for DomainTuple: [number, number]
|
|
@@ -114,17 +113,16 @@ export function getDataCoordinates(
|
|
|
114
113
|
x: horizontal ? scale.x.invert(y) : scale.x.invert(x),
|
|
115
114
|
y: horizontal ? scale.y.invert(x) : scale.y.invert(y),
|
|
116
115
|
};
|
|
117
|
-
} else {
|
|
118
|
-
const origin = props.origin || { x: 0, y: 0 };
|
|
119
|
-
const baseX = x - origin.x;
|
|
120
|
-
const baseY = y - origin.y;
|
|
121
|
-
const radius = Math.abs(baseX * Math.sqrt(1 + Math.pow(-baseY / baseX, 2)));
|
|
122
|
-
const angle = (-Math.atan2(baseY, baseX) + Math.PI * 2) % (Math.PI * 2);
|
|
123
|
-
return {
|
|
124
|
-
x: scale.x.invert(angle),
|
|
125
|
-
y: scale.y.invert(radius),
|
|
126
|
-
};
|
|
127
116
|
}
|
|
117
|
+
const origin = props.origin || { x: 0, y: 0 };
|
|
118
|
+
const baseX = x - origin.x;
|
|
119
|
+
const baseY = y - origin.y;
|
|
120
|
+
const radius = Math.abs(baseX * Math.sqrt(1 + Math.pow(-baseY / baseX, 2)));
|
|
121
|
+
const angle = (-Math.atan2(baseY, baseX) + Math.PI * 2) % (Math.PI * 2);
|
|
122
|
+
return {
|
|
123
|
+
x: scale.x.invert(angle),
|
|
124
|
+
y: scale.y.invert(radius),
|
|
125
|
+
};
|
|
128
126
|
}
|
|
129
127
|
|
|
130
128
|
export function getBounds(props: ComputedCommonProps): SVGCoordinateBounds {
|
|
@@ -155,4 +153,5 @@ type ComputedCommonProps = {
|
|
|
155
153
|
x2: number;
|
|
156
154
|
y1: number;
|
|
157
155
|
y2: number;
|
|
156
|
+
horizontal?: boolean;
|
|
158
157
|
};
|
|
@@ -14,19 +14,18 @@ export const toTransformString = function (obj, ...more) {
|
|
|
14
14
|
return [memo, toTransformString(currentObj)].join(" ");
|
|
15
15
|
}, toTransformString(obj))
|
|
16
16
|
.trim();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
17
|
+
}
|
|
18
|
+
if (obj === undefined || obj === null || typeof obj === "string") {
|
|
19
|
+
return obj;
|
|
20
|
+
}
|
|
21
|
+
const transforms = [] as string[];
|
|
22
|
+
for (const key in obj) {
|
|
23
|
+
if (obj.hasOwnProperty(key)) {
|
|
24
|
+
const value = obj[key];
|
|
25
|
+
transforms.push(`${key}(${value})`);
|
|
27
26
|
}
|
|
28
|
-
return transforms.join(" ").trim();
|
|
29
27
|
}
|
|
28
|
+
return transforms.join(" ").trim();
|
|
30
29
|
};
|
|
31
30
|
|
|
32
31
|
/**
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// http://www.pearsonified.com/2012/01/characters-per-line.php
|
|
2
|
-
/*eslint-disable no-magic-numbers */
|
|
2
|
+
/* eslint-disable no-magic-numbers */
|
|
3
3
|
import { assign, defaults } from "lodash";
|
|
4
4
|
|
|
5
5
|
// Based on measuring specific character widths
|
|
6
6
|
// as in the following example https://bl.ocks.org/tophtucker/62f93a4658387bb61e4510c37e2e97cf
|
|
7
|
-
//prettier-ignore
|
|
7
|
+
// prettier-ignore
|
|
8
8
|
const fonts = {
|
|
9
9
|
"American Typewriter": {
|
|
10
10
|
widths: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.25,0.4203125,0.3296875,0.6,0.6375,0.8015625,0.8203125,0.1875,0.45625,0.45625,0.6375,0.5,0.2734375,0.309375,0.2734375,0.4390625,0.6375,0.6375,0.6375,0.6375,0.6375,0.6375,0.6375,0.6375,0.6375,0.6375,0.2734375,0.2734375,0.5,0.5,0.5,0.6,0.6921875,0.7640625,0.6921875,0.6375,0.728125,0.6734375,0.6203125,0.7109375,0.784375,0.3828125,0.6421875,0.7859375,0.6375,0.9484375,0.7640625,0.65625,0.6375,0.65625,0.7296875,0.6203125,0.6375,0.7109375,0.740625,0.940625,0.784375,0.7578125,0.6203125,0.4375,0.5,0.4375,0.5,0.5,0.4921875,0.5734375,0.5890625,0.5109375,0.6,0.528125,0.43125,0.5578125,0.6375,0.3109375,0.40625,0.6234375,0.309375,0.928125,0.6375,0.546875,0.6,0.58125,0.4921875,0.4921875,0.4,0.6203125,0.625,0.825,0.6375,0.640625,0.528125,0.5,0.5,0.5,0.6671875],
|
|
@@ -112,7 +112,7 @@ const fonts = {
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
//https://developer.mozilla.org/en/docs/Web/CSS/length
|
|
115
|
+
// https://developer.mozilla.org/en/docs/Web/CSS/length
|
|
116
116
|
// Absolute sizes in pixels for obsolete measurement units.
|
|
117
117
|
const absoluteMeasurementUnitsToPixels = {
|
|
118
118
|
mm: 3.8,
|
|
@@ -342,9 +342,8 @@ export function getTransitionPropsFactory(props, state, setState) {
|
|
|
342
342
|
return animationDuration !== undefined
|
|
343
343
|
? animationDuration
|
|
344
344
|
: defaultTransitions[type] && defaultTransitions[type].duration;
|
|
345
|
-
} else {
|
|
346
|
-
return {};
|
|
347
345
|
}
|
|
346
|
+
return {};
|
|
348
347
|
};
|
|
349
348
|
|
|
350
349
|
// eslint-disable-next-line max-statements, complexity, max-len
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
VictoryProviderProps,
|
|
5
|
-
VictoryContainer,
|
|
6
|
-
} from "victory-core";
|
|
2
|
+
import { VictoryProvider, VictoryProviderProps } from "../victory-state";
|
|
3
|
+
import { VictoryContainer } from "../victory-container/victory-container";
|
|
7
4
|
import { VictoryCommonProps } from "./common-props";
|
|
8
5
|
|
|
9
6
|
const defaultProviderProps = {
|
|
@@ -228,9 +228,8 @@ export function getDomainFromChildren(props, axis, childComponents) {
|
|
|
228
228
|
return null;
|
|
229
229
|
} else if (child.type && isFunction(child.type.getDomain)) {
|
|
230
230
|
return child.props && child.type.getDomain(sharedProps, axis);
|
|
231
|
-
} else {
|
|
232
|
-
return Domain.getDomain(sharedProps, axis);
|
|
233
231
|
}
|
|
232
|
+
return Domain.getDomain(sharedProps, axis);
|
|
234
233
|
};
|
|
235
234
|
|
|
236
235
|
const childDomains = Helpers.reduceChildren(children, iteratee, props);
|
|
@@ -360,15 +359,14 @@ export function getStringsFromCategories(childComponents, axis) {
|
|
|
360
359
|
const childProps = child.props || {};
|
|
361
360
|
if (!Domain.isDomainComponent(child) || !childProps.categories) {
|
|
362
361
|
return null;
|
|
363
|
-
} else {
|
|
364
|
-
const categories =
|
|
365
|
-
childProps.categories && !Array.isArray(childProps.categories)
|
|
366
|
-
? childProps.categories[axis]
|
|
367
|
-
: childProps.props.categories;
|
|
368
|
-
const categoryStrings =
|
|
369
|
-
categories && categories.filter((val) => typeof val === "string");
|
|
370
|
-
return categoryStrings ? Collection.removeUndefined(categoryStrings) : [];
|
|
371
362
|
}
|
|
363
|
+
const categories =
|
|
364
|
+
childProps.categories && !Array.isArray(childProps.categories)
|
|
365
|
+
? childProps.categories[axis]
|
|
366
|
+
: childProps.props.categories;
|
|
367
|
+
const categoryStrings =
|
|
368
|
+
categories && categories.filter((val) => typeof val === "string");
|
|
369
|
+
return categoryStrings ? Collection.removeUndefined(categoryStrings) : [];
|
|
372
370
|
};
|
|
373
371
|
return Helpers.reduceChildren(childComponents.slice(0), iteratee);
|
|
374
372
|
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license React
|
|
3
|
-
* react-dom.production.min.js
|
|
4
|
-
*
|
|
5
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
|
-
*
|
|
7
|
-
* This source code is licensed under the MIT license found in the
|
|
8
|
-
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @license React
|
|
13
|
-
* scheduler.production.min.js
|
|
14
|
-
*
|
|
15
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
16
|
-
*
|
|
17
|
-
* This source code is licensed under the MIT license found in the
|
|
18
|
-
* LICENSE file in the root directory of this source tree.
|
|
19
|
-
*/
|