victory-core 36.9.2 → 37.0.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 +6 -0
- package/dist/victory-core.js +4371 -5749
- package/dist/victory-core.min.js +1 -1
- package/es/victory-accessible-group/victory-accessible-group.js +9 -15
- package/es/victory-animation/util.js +28 -47
- package/es/victory-animation/victory-animation.js +51 -67
- package/es/victory-clip-container/victory-clip-container.js +153 -229
- package/es/victory-container/victory-container.js +157 -216
- package/es/victory-label/victory-label.js +246 -323
- package/es/victory-portal/portal-context.js +1 -2
- package/es/victory-portal/portal.js +30 -76
- package/es/victory-portal/victory-portal.js +47 -104
- package/es/victory-primitives/arc.js +44 -47
- package/es/victory-primitives/background.js +14 -17
- package/es/victory-primitives/border.js +20 -24
- package/es/victory-primitives/circle.js +13 -27
- package/es/victory-primitives/clip-path.js +3 -7
- package/es/victory-primitives/line-segment.js +20 -24
- package/es/victory-primitives/line.js +13 -27
- package/es/victory-primitives/path.js +13 -27
- package/es/victory-primitives/point.js +36 -40
- package/es/victory-primitives/rect.js +13 -27
- package/es/victory-primitives/text.js +15 -28
- package/es/victory-primitives/tspan.js +13 -26
- package/es/victory-primitives/whisker.js +43 -47
- package/es/victory-theme/grayscale.js +22 -22
- package/es/victory-theme/material.js +46 -46
- package/es/victory-theme/victory-theme.js +3 -3
- package/es/victory-transition/victory-transition.js +126 -206
- package/es/victory-util/add-events.js +263 -374
- package/es/victory-util/axis.js +126 -222
- package/es/victory-util/collection.js +13 -41
- package/es/victory-util/data.js +159 -214
- package/es/victory-util/default-transitions.js +33 -51
- package/es/victory-util/domain.js +122 -171
- package/es/victory-util/events.js +168 -258
- package/es/victory-util/helpers.js +153 -178
- package/es/victory-util/hooks/use-animation-state.js +61 -99
- package/es/victory-util/hooks/use-previous-props.js +2 -2
- package/es/victory-util/immutable.js +6 -8
- package/es/victory-util/label-helpers.js +128 -130
- package/es/victory-util/line-helpers.js +29 -41
- package/es/victory-util/log.js +1 -1
- package/es/victory-util/point-path-helpers.js +89 -49
- package/es/victory-util/scale.js +24 -42
- package/es/victory-util/selection.js +39 -40
- package/es/victory-util/style.js +8 -13
- package/es/victory-util/textsize.js +80 -154
- package/es/victory-util/timer-context.js +2 -2
- package/es/victory-util/timer.js +40 -76
- package/es/victory-util/transitions.js +110 -150
- package/es/victory-util/type-helpers.js +2 -3
- package/es/victory-util/user-props.js +24 -49
- package/es/victory-util/wrapper.js +184 -247
- package/lib/index.js +0 -30
- package/lib/victory-accessible-group/victory-accessible-group.js +9 -19
- package/lib/victory-animation/util.js +28 -63
- package/lib/victory-animation/victory-animation.js +54 -83
- package/lib/victory-clip-container/victory-clip-container.js +156 -243
- package/lib/victory-container/victory-container.js +160 -232
- package/lib/victory-label/victory-label.js +248 -344
- package/lib/victory-portal/portal-context.js +1 -6
- package/lib/victory-portal/portal.js +31 -81
- package/lib/victory-portal/victory-portal.js +50 -116
- package/lib/victory-primitives/arc.js +48 -57
- package/lib/victory-primitives/background.js +16 -28
- package/lib/victory-primitives/border.js +22 -34
- package/lib/victory-primitives/circle.js +16 -36
- package/lib/victory-primitives/clip-path.js +3 -11
- package/lib/victory-primitives/index.js +0 -28
- package/lib/victory-primitives/line-segment.js +22 -34
- package/lib/victory-primitives/line.js +16 -36
- package/lib/victory-primitives/path.js +16 -36
- package/lib/victory-primitives/point.js +38 -52
- package/lib/victory-primitives/rect.js +16 -36
- package/lib/victory-primitives/text.js +15 -33
- package/lib/victory-primitives/tspan.js +13 -31
- package/lib/victory-primitives/whisker.js +45 -57
- package/lib/victory-theme/grayscale.js +23 -24
- package/lib/victory-theme/material.js +47 -48
- package/lib/victory-theme/victory-theme.js +2 -7
- package/lib/victory-transition/victory-transition.js +129 -224
- package/lib/victory-util/add-events.js +263 -380
- package/lib/victory-util/axis.js +128 -241
- package/lib/victory-util/collection.js +13 -50
- package/lib/victory-util/data.js +160 -239
- package/lib/victory-util/default-transitions.js +33 -54
- package/lib/victory-util/domain.js +123 -193
- package/lib/victory-util/events.js +167 -274
- package/lib/victory-util/helpers.js +156 -207
- package/lib/victory-util/hooks/index.js +0 -2
- package/lib/victory-util/hooks/use-animation-state.js +63 -113
- package/lib/victory-util/hooks/use-previous-props.js +2 -7
- package/lib/victory-util/immutable.js +6 -18
- package/lib/victory-util/index.js +2 -51
- package/lib/victory-util/label-helpers.js +130 -141
- package/lib/victory-util/line-helpers.js +31 -49
- package/lib/victory-util/log.js +1 -2
- package/lib/victory-util/point-path-helpers.js +91 -63
- package/lib/victory-util/scale.js +26 -57
- package/lib/victory-util/selection.js +41 -49
- package/lib/victory-util/style.js +8 -16
- package/lib/victory-util/textsize.js +80 -157
- package/lib/victory-util/timer-context.js +2 -8
- package/lib/victory-util/timer.js +40 -76
- package/lib/victory-util/transitions.js +110 -152
- package/lib/victory-util/type-helpers.js +2 -9
- package/lib/victory-util/user-props.js +25 -59
- package/lib/victory-util/wrapper.js +186 -281
- package/package.json +2 -2
|
@@ -1,137 +1,99 @@
|
|
|
1
1
|
import _defaults from "lodash/defaults";
|
|
2
|
-
|
|
3
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
-
|
|
5
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
|
-
|
|
7
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
|
-
|
|
9
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
10
|
-
|
|
11
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
12
|
-
|
|
13
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
14
|
-
|
|
15
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
16
|
-
|
|
17
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
18
|
-
|
|
19
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
20
|
-
|
|
21
2
|
import React from "react";
|
|
22
3
|
import * as Collection from "../collection";
|
|
23
4
|
import * as Transitions from "../transitions";
|
|
24
|
-
|
|
5
|
+
const INITIAL_STATE = {
|
|
25
6
|
nodesShouldLoad: false,
|
|
26
7
|
nodesDoneLoad: false,
|
|
27
8
|
animating: true
|
|
28
9
|
};
|
|
29
|
-
export
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (!
|
|
10
|
+
export const useAnimationState = function (initialState) {
|
|
11
|
+
if (initialState === void 0) {
|
|
12
|
+
initialState = INITIAL_STATE;
|
|
13
|
+
}
|
|
14
|
+
const [state, _setState] = React.useState(initialState);
|
|
15
|
+
|
|
16
|
+
// This allows us to use a state object and maintain the same API as this.setState
|
|
17
|
+
const setState = React.useCallback(newState => {
|
|
18
|
+
_setState(oldState => ({
|
|
19
|
+
...oldState,
|
|
20
|
+
...newState
|
|
21
|
+
}));
|
|
22
|
+
}, [_setState]);
|
|
23
|
+
|
|
24
|
+
// This is a copy of Wrapper.getAnimationProps
|
|
25
|
+
const getAnimationProps = React.useCallback((props, child, index) => {
|
|
26
|
+
if (!props?.animate) {
|
|
46
27
|
return child.props.animate;
|
|
47
28
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
var childrenTransitions = state && state.childrenTransitions;
|
|
29
|
+
const getFilteredState = () => {
|
|
30
|
+
let childrenTransitions = state && state.childrenTransitions;
|
|
51
31
|
childrenTransitions = Collection.isArrayOfArrays(childrenTransitions) ? childrenTransitions[index] : childrenTransitions;
|
|
52
32
|
return _defaults({
|
|
53
|
-
childrenTransitions
|
|
33
|
+
childrenTransitions
|
|
54
34
|
}, state);
|
|
55
35
|
};
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
var parentState = props.animate && props.animate.parentState || filteredState;
|
|
60
|
-
|
|
36
|
+
let getTransitions = props.animate && props.animate.getTransitions;
|
|
37
|
+
const filteredState = getFilteredState();
|
|
38
|
+
const parentState = props.animate && props.animate.parentState || filteredState;
|
|
61
39
|
if (!getTransitions) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
getTransitions = function (childComponent) {
|
|
67
|
-
return getTransitionProps(childComponent, index);
|
|
68
|
-
};
|
|
40
|
+
const getTransitionProps = Transitions.getTransitionPropsFactory(props, filteredState, newState => setState(newState));
|
|
41
|
+
getTransitions = childComponent => getTransitionProps(childComponent, index);
|
|
69
42
|
}
|
|
70
|
-
|
|
71
43
|
return _defaults({
|
|
72
|
-
getTransitions
|
|
73
|
-
parentState
|
|
44
|
+
getTransitions,
|
|
45
|
+
parentState
|
|
74
46
|
}, props.animate, child.props.animate);
|
|
75
|
-
}, [state, setState]);
|
|
47
|
+
}, [state, setState]);
|
|
76
48
|
|
|
77
|
-
|
|
78
|
-
|
|
49
|
+
// This is a copy of Wrapper.setAnimationState
|
|
50
|
+
const setAnimationState = React.useCallback((props, nextProps) => {
|
|
51
|
+
if (!props?.animate) {
|
|
79
52
|
return;
|
|
80
53
|
}
|
|
81
|
-
|
|
82
54
|
if (props.animate.parentState) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
nextProps: nextProps
|
|
55
|
+
const nodesWillExit = props.animate.parentState.nodesWillExit;
|
|
56
|
+
const oldProps = nodesWillExit ? props : null;
|
|
57
|
+
const newState = _defaults({
|
|
58
|
+
oldProps,
|
|
59
|
+
nextProps
|
|
89
60
|
}, props.animate.parentState);
|
|
90
|
-
|
|
91
61
|
setState(newState);
|
|
92
62
|
} else {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
var check = function (c) {
|
|
98
|
-
return c.type && c.type.continuous;
|
|
99
|
-
};
|
|
100
|
-
|
|
63
|
+
const oldChildren = React.Children.toArray(props.children);
|
|
64
|
+
const nextChildren = React.Children.toArray(nextProps.children);
|
|
65
|
+
const isContinuous = child => {
|
|
66
|
+
const check = c => c.type && c.type.continuous;
|
|
101
67
|
return Array.isArray(child) ? child.some(check) : check(child);
|
|
102
68
|
};
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
var _child$props;
|
|
106
|
-
|
|
107
|
-
return isContinuous(child) || (child === null || child === void 0 ? void 0 : (_child$props = child.props) === null || _child$props === void 0 ? void 0 : _child$props.children) && isContinuous(child.props.children);
|
|
69
|
+
const continuous = !props.polar && oldChildren.some(child => {
|
|
70
|
+
return isContinuous(child) || child?.props?.children && isContinuous(child.props.children);
|
|
108
71
|
});
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
72
|
+
const {
|
|
73
|
+
nodesWillExit,
|
|
74
|
+
nodesWillEnter,
|
|
75
|
+
childrenTransitions,
|
|
76
|
+
nodesShouldEnter
|
|
77
|
+
} = Transitions.getInitialTransitionState(oldChildren, nextChildren);
|
|
116
78
|
setState({
|
|
117
|
-
nodesWillExit
|
|
118
|
-
nodesWillEnter
|
|
119
|
-
nodesShouldEnter
|
|
79
|
+
nodesWillExit,
|
|
80
|
+
nodesWillEnter,
|
|
81
|
+
nodesShouldEnter,
|
|
120
82
|
childrenTransitions: Collection.isArrayOfArrays(childrenTransitions) ? childrenTransitions[0] : childrenTransitions,
|
|
121
|
-
oldProps:
|
|
122
|
-
nextProps
|
|
123
|
-
continuous
|
|
83
|
+
oldProps: nodesWillExit ? props : undefined,
|
|
84
|
+
nextProps,
|
|
85
|
+
continuous
|
|
124
86
|
});
|
|
125
87
|
}
|
|
126
88
|
}, [setState]);
|
|
127
|
-
|
|
89
|
+
const getProps = React.useCallback(initialProps => {
|
|
128
90
|
return state && state.nodesWillExit ? state.oldProps || initialProps : initialProps;
|
|
129
91
|
}, [state]);
|
|
130
92
|
return {
|
|
131
|
-
state
|
|
132
|
-
setState
|
|
133
|
-
getAnimationProps
|
|
134
|
-
setAnimationState
|
|
135
|
-
getProps
|
|
93
|
+
state,
|
|
94
|
+
setState,
|
|
95
|
+
getAnimationProps,
|
|
96
|
+
setAnimationState,
|
|
97
|
+
getProps
|
|
136
98
|
};
|
|
137
99
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
1
|
+
export const IMMUTABLE_ITERABLE = "@@__IMMUTABLE_ITERABLE__@@";
|
|
2
|
+
export const IMMUTABLE_RECORD = "@@__IMMUTABLE_RECORD__@@";
|
|
3
|
+
export const IMMUTABLE_LIST = "@@__IMMUTABLE_LIST__@@";
|
|
4
|
+
export const IMMUTABLE_MAP = "@@__IMMUTABLE_MAP__@@";
|
|
5
5
|
export function isIterable(x) {
|
|
6
6
|
return !!(x && x[IMMUTABLE_ITERABLE]);
|
|
7
7
|
}
|
|
@@ -18,13 +18,11 @@ export function isMap(x) {
|
|
|
18
18
|
return !!(x && x[IMMUTABLE_MAP]);
|
|
19
19
|
}
|
|
20
20
|
export function shallowToJS(x, whitelist) {
|
|
21
|
-
return isIterable(x) ? x.reduce(
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
return isIterable(x) ? x.reduce((result, curr, key) => {
|
|
22
|
+
let newCurr = curr;
|
|
24
23
|
if (whitelist && whitelist[key]) {
|
|
25
24
|
newCurr = shallowToJS(curr);
|
|
26
25
|
}
|
|
27
|
-
|
|
28
26
|
result[key] = newCurr;
|
|
29
27
|
return result;
|
|
30
28
|
}, isList(x) ? [] : {}) : x;
|
|
@@ -1,164 +1,164 @@
|
|
|
1
1
|
import _defaults from "lodash/defaults";
|
|
2
|
+
/* eslint-disable no-use-before-define */
|
|
2
3
|
import * as Helpers from "./helpers";
|
|
3
|
-
|
|
4
4
|
// Private Functions
|
|
5
|
-
function getVerticalAnchor(props) {
|
|
6
|
-
var datum = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
7
|
-
var sign = datum._y >= 0 ? 1 : -1;
|
|
8
|
-
var labelStyle = props.style && props.style.labels || {};
|
|
9
5
|
|
|
6
|
+
function getVerticalAnchor(props, datum) {
|
|
7
|
+
if (datum === void 0) {
|
|
8
|
+
datum = {};
|
|
9
|
+
}
|
|
10
|
+
const sign = datum._y >= 0 ? 1 : -1;
|
|
11
|
+
const labelStyle = props.style && props.style.labels || {};
|
|
10
12
|
if (datum.verticalAnchor || labelStyle.verticalAnchor) {
|
|
11
13
|
return datum.verticalAnchor || labelStyle.verticalAnchor;
|
|
12
14
|
} else if (!props.horizontal) {
|
|
13
15
|
return sign >= 0 ? "end" : "start";
|
|
14
16
|
}
|
|
15
|
-
|
|
16
17
|
return "middle";
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
function getTextAnchor(props, datum) {
|
|
20
|
+
if (datum === void 0) {
|
|
21
|
+
datum = {};
|
|
22
|
+
}
|
|
23
|
+
const {
|
|
24
|
+
style,
|
|
25
|
+
horizontal
|
|
26
|
+
} = props;
|
|
27
|
+
const sign = datum._y >= 0 ? 1 : -1;
|
|
28
|
+
const labelStyle = style && style.labels || {};
|
|
26
29
|
if (datum.verticalAnchor || labelStyle.verticalAnchor) {
|
|
27
30
|
return datum.verticalAnchor || labelStyle.verticalAnchor;
|
|
28
31
|
} else if (!horizontal) {
|
|
29
32
|
return "middle";
|
|
30
33
|
}
|
|
31
|
-
|
|
32
34
|
return sign >= 0 ? "start" : "end";
|
|
33
35
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
function getAngle(props, datum) {
|
|
37
|
+
if (datum === void 0) {
|
|
38
|
+
datum = {};
|
|
39
|
+
}
|
|
40
|
+
const labelStyle = props.style && props.style.labels || {};
|
|
38
41
|
return datum.angle === undefined ? labelStyle.angle : datum.angle;
|
|
39
42
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
function getPadding(props, datum) {
|
|
44
|
+
if (datum === void 0) {
|
|
45
|
+
datum = {};
|
|
46
|
+
}
|
|
47
|
+
const {
|
|
48
|
+
horizontal,
|
|
49
|
+
style
|
|
50
|
+
} = props;
|
|
51
|
+
const labelStyle = style.labels || {};
|
|
52
|
+
const defaultPadding = Helpers.evaluateProp(labelStyle.padding, props) || 0;
|
|
53
|
+
const sign = datum._y < 0 ? -1 : 1;
|
|
48
54
|
return {
|
|
49
55
|
x: horizontal ? sign * defaultPadding : 0,
|
|
50
56
|
y: horizontal ? 0 : -1 * sign * defaultPadding
|
|
51
57
|
};
|
|
52
58
|
}
|
|
53
|
-
|
|
54
59
|
function getOffset(props, datum) {
|
|
55
60
|
if (props.polar) {
|
|
56
61
|
return {};
|
|
57
62
|
}
|
|
58
|
-
|
|
59
|
-
var padding = getPadding(props, datum);
|
|
63
|
+
const padding = getPadding(props, datum);
|
|
60
64
|
return {
|
|
61
65
|
dx: padding.x,
|
|
62
66
|
dy: padding.y
|
|
63
67
|
};
|
|
64
68
|
}
|
|
65
|
-
|
|
66
69
|
function getPosition(props, datum) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
const {
|
|
71
|
+
polar
|
|
72
|
+
} = props;
|
|
73
|
+
const {
|
|
74
|
+
x,
|
|
75
|
+
y
|
|
76
|
+
} = Helpers.scalePoint(props, datum);
|
|
73
77
|
if (!polar) {
|
|
74
78
|
return {
|
|
75
|
-
x
|
|
76
|
-
y
|
|
79
|
+
x,
|
|
80
|
+
y
|
|
77
81
|
};
|
|
78
82
|
}
|
|
79
|
-
|
|
80
|
-
var polarPadding = getPolarPadding(props, datum);
|
|
83
|
+
const polarPadding = getPolarPadding(props, datum);
|
|
81
84
|
return {
|
|
82
85
|
x: x + polarPadding.x,
|
|
83
86
|
y: y + polarPadding.y
|
|
84
87
|
};
|
|
85
88
|
}
|
|
86
|
-
|
|
87
89
|
function getPolarPadding(props, datum) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
const {
|
|
91
|
+
style
|
|
92
|
+
} = props;
|
|
93
|
+
const degrees = getDegrees(props, datum);
|
|
94
|
+
const labelStyle = style.labels || {};
|
|
95
|
+
const padding = Helpers.evaluateProp(labelStyle.padding, props) || 0;
|
|
96
|
+
const angle = Helpers.degreesToRadians(degrees);
|
|
93
97
|
return {
|
|
94
98
|
x: padding * Math.cos(angle),
|
|
95
99
|
y: -padding * Math.sin(angle)
|
|
96
100
|
};
|
|
97
101
|
}
|
|
98
|
-
|
|
99
102
|
function getLabelPlacement(props) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
const {
|
|
104
|
+
labelComponent,
|
|
105
|
+
labelPlacement,
|
|
106
|
+
polar
|
|
107
|
+
} = props;
|
|
108
|
+
const defaultLabelPlacement = polar ? "perpendicular" : "vertical";
|
|
104
109
|
return labelPlacement ? labelPlacement : labelComponent.props && labelComponent.props.labelPlacement || defaultLabelPlacement;
|
|
105
110
|
}
|
|
106
|
-
|
|
107
111
|
function getPolarOrientation(degrees) {
|
|
108
112
|
// eslint-disable-next-line no-magic-numbers
|
|
109
113
|
if (degrees < 45 || degrees > 315) {
|
|
110
|
-
return "right";
|
|
114
|
+
return "right";
|
|
115
|
+
// eslint-disable-next-line no-magic-numbers
|
|
111
116
|
} else if (degrees >= 45 && degrees <= 135) {
|
|
112
|
-
return "top";
|
|
117
|
+
return "top";
|
|
118
|
+
// eslint-disable-next-line no-magic-numbers
|
|
113
119
|
} else if (degrees > 135 && degrees < 225) {
|
|
114
120
|
return "left";
|
|
115
121
|
}
|
|
116
|
-
|
|
117
122
|
return "bottom";
|
|
118
|
-
}
|
|
119
|
-
|
|
123
|
+
}
|
|
120
124
|
|
|
121
|
-
|
|
122
|
-
var datum = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
123
|
-
var index = arguments.length > 2 ? arguments[2] : undefined;
|
|
125
|
+
// Exported Functions
|
|
124
126
|
|
|
127
|
+
export function getText(props, datum, index) {
|
|
128
|
+
if (datum === void 0) {
|
|
129
|
+
datum = {};
|
|
130
|
+
}
|
|
125
131
|
if (datum.label !== undefined) {
|
|
126
132
|
return datum.label;
|
|
127
133
|
}
|
|
128
|
-
|
|
129
134
|
return Array.isArray(props.labels) ? props.labels[index] : props.labels;
|
|
130
135
|
}
|
|
131
136
|
export function getPolarTextAnchor(props, degrees) {
|
|
132
|
-
|
|
133
|
-
|
|
137
|
+
const labelPlacement = getLabelPlacement(props);
|
|
134
138
|
if (labelPlacement === "perpendicular" || labelPlacement === "vertical" && (degrees === 90 || degrees === 270)) {
|
|
135
139
|
return "middle";
|
|
136
140
|
}
|
|
137
|
-
|
|
138
141
|
return degrees <= 90 || degrees > 270 ? "start" : "end";
|
|
139
142
|
}
|
|
140
143
|
export function getPolarVerticalAnchor(props, degrees) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
+
const labelPlacement = getLabelPlacement(props);
|
|
145
|
+
const orientation = getPolarOrientation(degrees);
|
|
144
146
|
if (labelPlacement === "parallel" || orientation === "left" || orientation === "right") {
|
|
145
147
|
return "middle";
|
|
146
148
|
}
|
|
147
|
-
|
|
148
149
|
return orientation === "top" ? "end" : "start";
|
|
149
150
|
}
|
|
150
151
|
export function getPolarAngle(props, baseAngle) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
const {
|
|
153
|
+
labelPlacement,
|
|
154
|
+
datum
|
|
155
|
+
} = props;
|
|
154
156
|
if (!labelPlacement || labelPlacement === "vertical") {
|
|
155
157
|
return 0;
|
|
156
158
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
var angle = 0;
|
|
161
|
-
|
|
159
|
+
const degrees = baseAngle !== undefined ? baseAngle % 360 : getDegrees(props, datum);
|
|
160
|
+
const sign = degrees > 90 && degrees < 180 || degrees > 270 ? 1 : -1;
|
|
161
|
+
let angle = 0;
|
|
162
162
|
if (degrees === 0 || degrees === 180) {
|
|
163
163
|
angle = 90;
|
|
164
164
|
} else if (degrees > 0 && degrees < 180) {
|
|
@@ -166,69 +166,67 @@ export function getPolarAngle(props, baseAngle) {
|
|
|
166
166
|
} else if (degrees > 180 && degrees < 360) {
|
|
167
167
|
angle = 270 - degrees;
|
|
168
168
|
}
|
|
169
|
-
|
|
170
|
-
var labelRotation = labelPlacement === "perpendicular" ? 0 : 90;
|
|
169
|
+
const labelRotation = labelPlacement === "perpendicular" ? 0 : 90;
|
|
171
170
|
return angle + sign * labelRotation;
|
|
172
171
|
}
|
|
173
172
|
export function getDegrees(props, datum) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
173
|
+
const {
|
|
174
|
+
x
|
|
175
|
+
} = Helpers.getPoint(datum);
|
|
177
176
|
return Helpers.radiansToDegrees(props.scale.x(x)) % 360;
|
|
178
177
|
}
|
|
179
178
|
export function getProps(props, index) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
179
|
+
const {
|
|
180
|
+
scale,
|
|
181
|
+
data,
|
|
182
|
+
style,
|
|
183
|
+
horizontal,
|
|
184
|
+
polar,
|
|
185
|
+
width,
|
|
186
|
+
height,
|
|
187
|
+
theme,
|
|
188
|
+
labelComponent,
|
|
189
|
+
disableInlineStyles
|
|
190
|
+
} = props;
|
|
191
|
+
const datum = data[index];
|
|
192
|
+
const degrees = getDegrees(props, datum);
|
|
193
|
+
const textAnchor = polar ? getPolarTextAnchor(props, degrees) : getTextAnchor(props, datum);
|
|
194
|
+
const verticalAnchor = polar ? getPolarVerticalAnchor(props, degrees) : getVerticalAnchor(props, datum);
|
|
195
|
+
const angle = getAngle(props, datum);
|
|
196
|
+
const text = getText(props, datum, index);
|
|
197
|
+
const labelPlacement = getLabelPlacement(props);
|
|
198
|
+
const {
|
|
199
|
+
x,
|
|
200
|
+
y
|
|
201
|
+
} = getPosition(props, datum);
|
|
202
|
+
const {
|
|
203
|
+
dx,
|
|
204
|
+
dy
|
|
205
|
+
} = getOffset(props, datum);
|
|
206
|
+
const labelProps = {
|
|
207
|
+
angle,
|
|
208
|
+
data,
|
|
209
|
+
datum,
|
|
210
|
+
disableInlineStyles,
|
|
211
|
+
horizontal,
|
|
212
|
+
index,
|
|
213
|
+
polar,
|
|
214
|
+
scale,
|
|
215
|
+
labelPlacement,
|
|
216
|
+
text,
|
|
217
|
+
textAnchor,
|
|
218
|
+
verticalAnchor,
|
|
219
|
+
x,
|
|
220
|
+
y,
|
|
221
|
+
dx,
|
|
222
|
+
dy,
|
|
223
|
+
width,
|
|
224
|
+
height,
|
|
225
225
|
style: style.labels
|
|
226
226
|
};
|
|
227
|
-
|
|
228
227
|
if (!Helpers.isTooltip(labelComponent)) {
|
|
229
228
|
return labelProps;
|
|
230
229
|
}
|
|
231
|
-
|
|
232
|
-
var tooltipTheme = theme && theme.tooltip || {};
|
|
230
|
+
const tooltipTheme = theme && theme.tooltip || {};
|
|
233
231
|
return _defaults({}, labelProps, Helpers.omit(tooltipTheme, ["style"]));
|
|
234
232
|
}
|