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
|
@@ -15,29 +15,24 @@ export function continuousPolarTransitions() {
|
|
|
15
15
|
return {
|
|
16
16
|
onLoad: {
|
|
17
17
|
duration: 2000,
|
|
18
|
-
before:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
_y1: datum._y1,
|
|
29
|
-
_y0: datum._y0
|
|
30
|
-
};
|
|
31
|
-
}
|
|
18
|
+
before: () => ({
|
|
19
|
+
_y: 0,
|
|
20
|
+
_y1: 0,
|
|
21
|
+
_y0: 0
|
|
22
|
+
}),
|
|
23
|
+
after: datum => ({
|
|
24
|
+
_y: datum._y,
|
|
25
|
+
_y1: datum._y1,
|
|
26
|
+
_y0: datum._y0
|
|
27
|
+
})
|
|
32
28
|
},
|
|
33
29
|
onExit: {
|
|
34
30
|
duration: 500,
|
|
35
|
-
before:
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
before: (datum, index, data) => {
|
|
32
|
+
const adjacent = attr => {
|
|
33
|
+
const adj = index === 0 ? data[index + 1] : data[index - 1];
|
|
38
34
|
return adj[attr];
|
|
39
35
|
};
|
|
40
|
-
|
|
41
36
|
return {
|
|
42
37
|
_x: adjacent("_x"),
|
|
43
38
|
_y: adjacent("_y"),
|
|
@@ -47,26 +42,23 @@ export function continuousPolarTransitions() {
|
|
|
47
42
|
},
|
|
48
43
|
onEnter: {
|
|
49
44
|
duration: 500,
|
|
50
|
-
before:
|
|
51
|
-
|
|
52
|
-
|
|
45
|
+
before: (datum, index, data) => {
|
|
46
|
+
const adjacent = attr => {
|
|
47
|
+
const adj = index === 0 ? data[index + 1] : data[index - 1];
|
|
53
48
|
return adj[attr];
|
|
54
49
|
};
|
|
55
|
-
|
|
56
50
|
return {
|
|
57
51
|
_x: adjacent("_x"),
|
|
58
52
|
_y: adjacent("_y"),
|
|
59
53
|
_y0: adjacent("_y0")
|
|
60
54
|
};
|
|
61
55
|
},
|
|
62
|
-
after:
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
};
|
|
69
|
-
}
|
|
56
|
+
after: datum => ({
|
|
57
|
+
_x: datum._x,
|
|
58
|
+
_y: datum._y,
|
|
59
|
+
_y1: datum._y1,
|
|
60
|
+
_y0: datum._y0
|
|
61
|
+
})
|
|
70
62
|
}
|
|
71
63
|
};
|
|
72
64
|
}
|
|
@@ -74,33 +66,23 @@ export function discreteTransitions() {
|
|
|
74
66
|
return {
|
|
75
67
|
onLoad: {
|
|
76
68
|
duration: 2000,
|
|
77
|
-
before:
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
},
|
|
82
|
-
after: function (datum) {
|
|
83
|
-
return datum;
|
|
84
|
-
}
|
|
69
|
+
before: () => ({
|
|
70
|
+
opacity: 0
|
|
71
|
+
}),
|
|
72
|
+
after: datum => datum
|
|
85
73
|
},
|
|
86
74
|
onExit: {
|
|
87
75
|
duration: 600,
|
|
88
|
-
before:
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
};
|
|
92
|
-
}
|
|
76
|
+
before: () => ({
|
|
77
|
+
opacity: 0
|
|
78
|
+
})
|
|
93
79
|
},
|
|
94
80
|
onEnter: {
|
|
95
81
|
duration: 600,
|
|
96
|
-
before:
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
},
|
|
101
|
-
after: function (datum) {
|
|
102
|
-
return datum;
|
|
103
|
-
}
|
|
82
|
+
before: () => ({
|
|
83
|
+
opacity: 0
|
|
84
|
+
}),
|
|
85
|
+
after: datum => datum
|
|
104
86
|
}
|
|
105
87
|
};
|
|
106
88
|
}
|
|
@@ -1,45 +1,30 @@
|
|
|
1
1
|
import _isDate from "lodash/isDate";
|
|
2
2
|
import _sortedUniq from "lodash/sortedUniq";
|
|
3
3
|
import _isPlainObject from "lodash/isPlainObject";
|
|
4
|
-
|
|
5
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
6
|
-
|
|
7
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
8
|
-
|
|
9
|
-
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); }
|
|
10
|
-
|
|
11
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
12
|
-
|
|
13
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
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
4
|
/* eslint-disable no-use-before-define */
|
|
18
5
|
import React from "react";
|
|
19
6
|
import * as Data from "./data";
|
|
20
7
|
import * as Scale from "./scale";
|
|
21
8
|
import * as Helpers from "./helpers";
|
|
22
|
-
import * as Collection from "./collection";
|
|
9
|
+
import * as Collection from "./collection";
|
|
23
10
|
|
|
24
|
-
|
|
25
|
-
var scaleType = Scale.getScaleType(props, axis);
|
|
11
|
+
// Private Methods
|
|
26
12
|
|
|
13
|
+
function cleanDomain(domain, props, axis) {
|
|
14
|
+
const scaleType = Scale.getScaleType(props, axis);
|
|
27
15
|
if (scaleType !== "log") {
|
|
28
16
|
return domain;
|
|
29
17
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
var domainTwo = dom[1] === 0 ? almostZero : dom[1];
|
|
18
|
+
const rules = dom => {
|
|
19
|
+
const almostZero = dom[0] < 0 || dom[1] < 0 ? -1 / Number.MAX_SAFE_INTEGER : 1 / Number.MAX_SAFE_INTEGER;
|
|
20
|
+
const domainOne = dom[0] === 0 ? almostZero : dom[0];
|
|
21
|
+
const domainTwo = dom[1] === 0 ? almostZero : dom[1];
|
|
35
22
|
return [domainOne, domainTwo];
|
|
36
23
|
};
|
|
37
|
-
|
|
38
24
|
return rules(domain);
|
|
39
25
|
}
|
|
40
|
-
|
|
41
26
|
function getDomainPadding(props, axis) {
|
|
42
|
-
|
|
27
|
+
const formatPadding = padding => {
|
|
43
28
|
return Array.isArray(padding) ? {
|
|
44
29
|
left: padding[0],
|
|
45
30
|
right: padding[1]
|
|
@@ -48,105 +33,100 @@ function getDomainPadding(props, axis) {
|
|
|
48
33
|
right: padding
|
|
49
34
|
};
|
|
50
35
|
};
|
|
51
|
-
|
|
52
36
|
return _isPlainObject(props.domainPadding) ? formatPadding(props.domainPadding[axis]) : formatPadding(props.domainPadding);
|
|
53
37
|
}
|
|
54
|
-
|
|
55
38
|
function getFlatData(dataset, axis) {
|
|
56
|
-
|
|
57
|
-
return dataset.flat().map(
|
|
39
|
+
const axisKey = `_${axis}`;
|
|
40
|
+
return dataset.flat().map(datum => {
|
|
58
41
|
return datum[axisKey] && datum[axisKey][1] !== undefined ? datum[axisKey][1] : datum[axisKey];
|
|
59
42
|
});
|
|
60
43
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
var current0 = datum["_".concat(axis, "0")] !== undefined ? datum["_".concat(axis, "0")] : datum["_".concat(axis)];
|
|
73
|
-
var current1 = datum["_".concat(axis, "1")] !== undefined ? datum["_".concat(axis, "1")] : datum["_".concat(axis)];
|
|
74
|
-
var current = getExtreme([current0, current1]);
|
|
44
|
+
function getExtremeFromData(dataset, axis, type) {
|
|
45
|
+
if (type === void 0) {
|
|
46
|
+
type = "min";
|
|
47
|
+
}
|
|
48
|
+
const getExtreme = arr => type === "max" ? Math.max(...arr) : Math.min(...arr);
|
|
49
|
+
const initialValue = type === "max" ? -Infinity : Infinity;
|
|
50
|
+
let containsDate = false;
|
|
51
|
+
const result = dataset.flat().reduce((memo, datum) => {
|
|
52
|
+
const current0 = datum[`_${axis}0`] !== undefined ? datum[`_${axis}0`] : datum[`_${axis}`];
|
|
53
|
+
const current1 = datum[`_${axis}1`] !== undefined ? datum[`_${axis}1`] : datum[`_${axis}`];
|
|
54
|
+
const current = getExtreme([current0, current1]);
|
|
75
55
|
containsDate = containsDate || current0 instanceof Date || current1 instanceof Date;
|
|
76
56
|
return getExtreme([memo, current]);
|
|
77
57
|
}, initialValue);
|
|
78
58
|
return containsDate ? new Date(result) : result;
|
|
79
|
-
}
|
|
80
|
-
|
|
59
|
+
}
|
|
81
60
|
|
|
61
|
+
// eslint-disable-next-line max-statements
|
|
82
62
|
function padDomain(domain, props, axis) {
|
|
83
63
|
if (!props.domainPadding) {
|
|
84
64
|
return domain;
|
|
85
65
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
var padding = getDomainPadding(props, axis);
|
|
90
|
-
|
|
66
|
+
const minDomain = getMinFromProps(props, axis);
|
|
67
|
+
const maxDomain = getMaxFromProps(props, axis);
|
|
68
|
+
const padding = getDomainPadding(props, axis);
|
|
91
69
|
if (!padding.left && !padding.right) {
|
|
92
70
|
return domain;
|
|
93
71
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
var simplePadding = {
|
|
72
|
+
const min = Collection.getMinValue(domain);
|
|
73
|
+
const max = Collection.getMaxValue(domain);
|
|
74
|
+
const currentAxis = Helpers.getCurrentAxis(axis, props.horizontal);
|
|
75
|
+
const range = Helpers.getRange(props, currentAxis);
|
|
76
|
+
const rangeExtent = Math.abs(range[0] - range[1]);
|
|
77
|
+
const paddedRangeExtent = Math.max(rangeExtent - padding.left - padding.right, 1);
|
|
78
|
+
const paddedDomainExtent = Math.abs(max.valueOf() - min.valueOf()) / paddedRangeExtent * rangeExtent;
|
|
79
|
+
const simplePadding = {
|
|
103
80
|
left: paddedDomainExtent * padding.left / rangeExtent,
|
|
104
81
|
right: paddedDomainExtent * padding.right / rangeExtent
|
|
105
82
|
};
|
|
106
|
-
|
|
83
|
+
let paddedDomain = {
|
|
107
84
|
min: min.valueOf() - simplePadding.left,
|
|
108
85
|
max: max.valueOf() + simplePadding.right
|
|
109
86
|
};
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
var coerce = type === "min" && min >= 0 && val <= 0 || type === "max" && max <= 0 && val >= 0;
|
|
87
|
+
const singleQuadrantDomainPadding = _isPlainObject(props.singleQuadrantDomainPadding) ? props.singleQuadrantDomainPadding[axis] : props.singleQuadrantDomainPadding;
|
|
88
|
+
const addsQuadrants = min >= 0 && paddedDomain.min <= 0 || max <= 0 && paddedDomain.max >= 0;
|
|
89
|
+
const adjust = (val, type) => {
|
|
90
|
+
const coerce = type === "min" && min >= 0 && val <= 0 || type === "max" && max <= 0 && val >= 0;
|
|
115
91
|
return coerce ? 0 : val;
|
|
116
92
|
};
|
|
117
|
-
|
|
118
93
|
if (addsQuadrants && singleQuadrantDomainPadding !== false) {
|
|
119
94
|
// Naive initial padding calculation
|
|
120
|
-
|
|
95
|
+
const initialPadding = {
|
|
121
96
|
// @ts-expect-error `max/min` might be dates
|
|
122
97
|
left: Math.abs(max - min) * padding.left / rangeExtent,
|
|
123
98
|
// @ts-expect-error `max/min` might be dates
|
|
124
99
|
right: Math.abs(max - min) * padding.right / rangeExtent
|
|
125
|
-
};
|
|
100
|
+
};
|
|
126
101
|
|
|
127
|
-
|
|
102
|
+
// Adjust the domain by the initial padding
|
|
103
|
+
const adjustedDomain = {
|
|
128
104
|
min: adjust(min.valueOf() - initialPadding.left, "min"),
|
|
129
105
|
max: adjust(max.valueOf() + initialPadding.right, "max")
|
|
130
|
-
};
|
|
106
|
+
};
|
|
131
107
|
|
|
132
|
-
|
|
108
|
+
// re-calculate padding, taking the adjusted domain into account
|
|
109
|
+
const finalPadding = {
|
|
133
110
|
left: Math.abs(adjustedDomain.max - adjustedDomain.min) * padding.left / rangeExtent,
|
|
134
111
|
right: Math.abs(adjustedDomain.max - adjustedDomain.min) * padding.right / rangeExtent
|
|
135
|
-
};
|
|
112
|
+
};
|
|
136
113
|
|
|
114
|
+
// Adjust the domain by the final padding
|
|
137
115
|
paddedDomain = {
|
|
138
116
|
min: adjust(min.valueOf() - finalPadding.left, "min"),
|
|
139
117
|
max: adjust(max.valueOf() + finalPadding.right, "max")
|
|
140
118
|
};
|
|
141
|
-
}
|
|
142
|
-
|
|
119
|
+
}
|
|
143
120
|
|
|
144
|
-
|
|
121
|
+
// default to minDomain / maxDomain if they exist
|
|
122
|
+
const finalDomain = {
|
|
145
123
|
min: minDomain !== undefined ? minDomain : paddedDomain.min,
|
|
146
124
|
max: maxDomain !== undefined ? maxDomain : paddedDomain.max
|
|
147
125
|
};
|
|
148
126
|
return min instanceof Date || max instanceof Date ? getDomainFromMinMax(new Date(finalDomain.min), new Date(finalDomain.max)) : getDomainFromMinMax(finalDomain.min, finalDomain.max);
|
|
149
|
-
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Public Methods
|
|
150
130
|
|
|
151
131
|
/**
|
|
152
132
|
* Returns a getDomain function
|
|
@@ -156,23 +136,20 @@ function padDomain(domain, props, axis) {
|
|
|
156
136
|
* returns a formatted domain
|
|
157
137
|
* @returns {Function} a function that takes props and axis and returns a formatted domain
|
|
158
138
|
*/
|
|
159
|
-
|
|
160
|
-
|
|
161
139
|
export function createDomainFunction(getDomainFromDataFunction, formatDomainFunction) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
return
|
|
165
|
-
|
|
166
|
-
|
|
140
|
+
const getDomainFromDataFn = Helpers.isFunction(getDomainFromDataFunction) ? getDomainFromDataFunction : getDomainFromData;
|
|
141
|
+
const formatDomainFn = Helpers.isFunction(formatDomainFunction) ? formatDomainFunction : formatDomain;
|
|
142
|
+
return (props, axis) => {
|
|
143
|
+
const propsDomain = getDomainFromProps(props, axis);
|
|
167
144
|
if (propsDomain) {
|
|
168
145
|
return formatDomainFn(propsDomain, props, axis);
|
|
169
146
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
var domain = categories ? getDomainFromCategories(props, axis, categories) : getDomainFromDataFn(props, axis);
|
|
147
|
+
const categories = Data.getCategories(props, axis);
|
|
148
|
+
const domain = categories ? getDomainFromCategories(props, axis, categories) : getDomainFromDataFn(props, axis);
|
|
173
149
|
return domain ? formatDomainFn(domain, props, axis) : undefined;
|
|
174
150
|
};
|
|
175
151
|
}
|
|
152
|
+
|
|
176
153
|
/**
|
|
177
154
|
* Returns a formatted domain.
|
|
178
155
|
* @param {Array} domain: a domain in the form of a two element array
|
|
@@ -180,20 +157,20 @@ export function createDomainFunction(getDomainFromDataFunction, formatDomainFunc
|
|
|
180
157
|
* @param {String} axis: the current axis
|
|
181
158
|
* @returns {Array} a domain in the form of a two element array
|
|
182
159
|
*/
|
|
183
|
-
|
|
184
160
|
export function formatDomain(domain, props, axis) {
|
|
185
161
|
return cleanDomain(padDomain(domain, props, axis), props, axis);
|
|
186
162
|
}
|
|
163
|
+
|
|
187
164
|
/**
|
|
188
165
|
* Returns a domain for a given axis based on props, category, or data
|
|
189
166
|
* @param {Object} props: the props object
|
|
190
167
|
* @param {String} axis: the current axis
|
|
191
168
|
* @returns {Array} the domain for the given axis
|
|
192
169
|
*/
|
|
193
|
-
|
|
194
170
|
export function getDomain(props, axis) {
|
|
195
171
|
return createDomainFunction()(props, axis);
|
|
196
172
|
}
|
|
173
|
+
|
|
197
174
|
/**
|
|
198
175
|
* Returns a domain based on categories if they exist
|
|
199
176
|
* @param {Object} props: the props object
|
|
@@ -201,34 +178,30 @@ export function getDomain(props, axis) {
|
|
|
201
178
|
* @param {Array} categories: an array of categories corresponding to a given axis
|
|
202
179
|
* @returns {Array|undefined} returns a domain from categories or undefined
|
|
203
180
|
*/
|
|
204
|
-
|
|
205
181
|
export function getDomainFromCategories(props, axis, categories) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
182
|
+
const categoriesArray = categories || Data.getCategories(props, axis);
|
|
183
|
+
const {
|
|
184
|
+
polar,
|
|
185
|
+
startAngle = 0,
|
|
186
|
+
endAngle = 360
|
|
187
|
+
} = props;
|
|
213
188
|
if (!categoriesArray) {
|
|
214
189
|
return undefined;
|
|
215
190
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
var stringMap = stringArray.length === 0 ? null : stringArray.reduce(function (memo, string, index) {
|
|
191
|
+
const minDomain = getMinFromProps(props, axis);
|
|
192
|
+
const maxDomain = getMaxFromProps(props, axis);
|
|
193
|
+
const stringArray = Collection.containsStrings(categoriesArray) ? Data.getStringsFromCategories(props, axis) : [];
|
|
194
|
+
const stringMap = stringArray.length === 0 ? null : stringArray.reduce((memo, string, index) => {
|
|
221
195
|
memo[string] = index + 1;
|
|
222
196
|
return memo;
|
|
223
197
|
}, {});
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
var max = maxDomain !== undefined ? maxDomain : Collection.getMaxValue(categoryValues);
|
|
229
|
-
var categoryDomain = getDomainFromMinMax(min, max);
|
|
198
|
+
const categoryValues = stringMap ? categoriesArray.map(value => stringMap[value]) : categoriesArray;
|
|
199
|
+
const min = minDomain !== undefined ? minDomain : Collection.getMinValue(categoryValues);
|
|
200
|
+
const max = maxDomain !== undefined ? maxDomain : Collection.getMaxValue(categoryValues);
|
|
201
|
+
const categoryDomain = getDomainFromMinMax(min, max);
|
|
230
202
|
return polar && axis === "x" && Math.abs(startAngle - endAngle) === 360 ? getSymmetricDomain(categoryDomain, categoryValues) : categoryDomain;
|
|
231
203
|
}
|
|
204
|
+
|
|
232
205
|
/**
|
|
233
206
|
* Returns a domain from a dataset for a given axis
|
|
234
207
|
* @param {Object} props: the props object
|
|
@@ -236,57 +209,53 @@ export function getDomainFromCategories(props, axis, categories) {
|
|
|
236
209
|
* @param {Array} dataset: an array of data
|
|
237
210
|
* @returns {Array} the domain based on data
|
|
238
211
|
*/
|
|
239
|
-
|
|
240
212
|
export function getDomainFromData(props, axis, dataset) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
213
|
+
const datasetArray = dataset || Data.getData(props);
|
|
214
|
+
const {
|
|
215
|
+
polar,
|
|
216
|
+
startAngle = 0,
|
|
217
|
+
endAngle = 360
|
|
218
|
+
} = props;
|
|
219
|
+
const minDomain = getMinFromProps(props, axis);
|
|
220
|
+
const maxDomain = getMaxFromProps(props, axis);
|
|
250
221
|
if (datasetArray.length < 1) {
|
|
251
222
|
return minDomain !== undefined && maxDomain !== undefined ? getDomainFromMinMax(minDomain, maxDomain) : undefined;
|
|
252
223
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
var domain = getDomainFromMinMax(min, max);
|
|
224
|
+
const min = minDomain !== undefined ? minDomain : getExtremeFromData(datasetArray, axis, "min");
|
|
225
|
+
const max = maxDomain !== undefined ? maxDomain : getExtremeFromData(datasetArray, axis, "max");
|
|
226
|
+
const domain = getDomainFromMinMax(min, max);
|
|
257
227
|
return polar && axis === "x" && Math.abs(startAngle - endAngle) === 360 ? getSymmetricDomain(domain, getFlatData(datasetArray, axis)) : domain;
|
|
258
228
|
}
|
|
229
|
+
|
|
259
230
|
/**
|
|
260
231
|
* Returns a domain in the form of a two element array given a min and max value.
|
|
261
232
|
* @param {Number|Date} min: the props object
|
|
262
233
|
* @param {Number|Date} max: the current axis
|
|
263
234
|
* @returns {Array} the minDomain based on props
|
|
264
235
|
*/
|
|
265
|
-
|
|
266
236
|
export function getDomainFromMinMax(min, max) {
|
|
267
|
-
|
|
237
|
+
const getSinglePointDomain = val => {
|
|
268
238
|
// d3-scale does not properly resolve very small differences.
|
|
269
|
-
|
|
239
|
+
const verySmallNumber =
|
|
240
|
+
// eslint-disable-next-line no-magic-numbers
|
|
270
241
|
val === 0 ? 2 * Math.pow(10, -10) : Math.pow(10, -10);
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
242
|
+
const verySmallDate = 1;
|
|
243
|
+
const minVal = val instanceof Date ? new Date(Number(val) - verySmallDate) : Number(val) - verySmallNumber;
|
|
244
|
+
const maxVal = val instanceof Date ? new Date(Number(val) + verySmallDate) : Number(val) + verySmallNumber;
|
|
274
245
|
return val === 0 ? [0, maxVal] : [minVal, maxVal];
|
|
275
246
|
};
|
|
276
|
-
|
|
277
247
|
return Number(min) === Number(max) ? getSinglePointDomain(max) : [min, max];
|
|
278
248
|
}
|
|
249
|
+
|
|
279
250
|
/**
|
|
280
251
|
* Returns a the domain for a given axis if domain is given in props
|
|
281
252
|
* @param {Object} props: the props object
|
|
282
253
|
* @param {String} axis: the current axis
|
|
283
254
|
* @returns {Array|undefined} the domain based on props
|
|
284
255
|
*/
|
|
285
|
-
|
|
286
256
|
export function getDomainFromProps(props, axis) {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
257
|
+
const minDomain = getMinFromProps(props, axis);
|
|
258
|
+
const maxDomain = getMaxFromProps(props, axis);
|
|
290
259
|
if (_isPlainObject(props.domain) && props.domain[axis]) {
|
|
291
260
|
return props.domain[axis];
|
|
292
261
|
} else if (Array.isArray(props.domain)) {
|
|
@@ -294,9 +263,9 @@ export function getDomainFromProps(props, axis) {
|
|
|
294
263
|
} else if (minDomain !== undefined && maxDomain !== undefined) {
|
|
295
264
|
return getDomainFromMinMax(minDomain, maxDomain);
|
|
296
265
|
}
|
|
297
|
-
|
|
298
266
|
return undefined;
|
|
299
267
|
}
|
|
268
|
+
|
|
300
269
|
/**
|
|
301
270
|
* Returns a domain for a given axis. This method forces the domain to include
|
|
302
271
|
* zero unless the domain is explicitly specified in props.
|
|
@@ -304,70 +273,59 @@ export function getDomainFromProps(props, axis) {
|
|
|
304
273
|
* @param {String} axis: the current axis
|
|
305
274
|
* @returns {Array} the domain for the given axis
|
|
306
275
|
*/
|
|
307
|
-
|
|
308
276
|
export function getDomainWithZero(props, axis) {
|
|
309
|
-
|
|
310
|
-
|
|
277
|
+
const propsDomain = getDomainFromProps(props, axis);
|
|
311
278
|
if (propsDomain) {
|
|
312
279
|
return propsDomain;
|
|
313
280
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
return datum._y0 < min ? datum._y0 : min;
|
|
318
|
-
}, Infinity);
|
|
319
|
-
|
|
320
|
-
var ensureZero = function (domain) {
|
|
281
|
+
const dataset = Data.getData(props);
|
|
282
|
+
const y0Min = dataset.reduce((min, datum) => datum._y0 < min ? datum._y0 : min, Infinity);
|
|
283
|
+
const ensureZero = domain => {
|
|
321
284
|
if (axis === "x") {
|
|
322
285
|
return domain;
|
|
323
286
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
var min = minDomainProp !== undefined ? minDomainProp : Collection.getMinValue(domain, defaultMin);
|
|
287
|
+
const defaultMin = y0Min !== Infinity ? y0Min : 0;
|
|
288
|
+
const maxDomainProp = getMaxFromProps(props, axis);
|
|
289
|
+
const minDomainProp = getMinFromProps(props, axis);
|
|
290
|
+
const max = maxDomainProp !== undefined ? maxDomainProp : Collection.getMaxValue(domain, defaultMin);
|
|
291
|
+
const min = minDomainProp !== undefined ? minDomainProp : Collection.getMinValue(domain, defaultMin);
|
|
330
292
|
return getDomainFromMinMax(min, max);
|
|
331
293
|
};
|
|
332
|
-
|
|
333
|
-
var getDomainFunction = function () {
|
|
294
|
+
const getDomainFunction = () => {
|
|
334
295
|
return getDomainFromData(props, axis, dataset);
|
|
335
296
|
};
|
|
336
|
-
|
|
337
|
-
var formatDomainFunction = function (domain) {
|
|
297
|
+
const formatDomainFunction = domain => {
|
|
338
298
|
return formatDomain(ensureZero(domain), props, axis);
|
|
339
299
|
};
|
|
340
|
-
|
|
341
300
|
return createDomainFunction(getDomainFunction, formatDomainFunction)(props, axis);
|
|
342
301
|
}
|
|
302
|
+
|
|
343
303
|
/**
|
|
344
304
|
* Returns the maxDomain from props if it exists
|
|
345
305
|
* @param {Object} props: the props object
|
|
346
306
|
* @param {String} axis: the current axis
|
|
347
307
|
* @returns {Number|Date|undefined} the maxDomain based on props
|
|
348
308
|
*/
|
|
349
|
-
|
|
350
309
|
export function getMaxFromProps(props, axis) {
|
|
351
310
|
if (_isPlainObject(props.maxDomain) && props.maxDomain[axis] !== undefined) {
|
|
352
311
|
return props.maxDomain[axis];
|
|
353
312
|
}
|
|
354
|
-
|
|
355
313
|
return typeof props.maxDomain === "number" || _isDate(props.maxDomain) ? props.maxDomain : undefined;
|
|
356
314
|
}
|
|
315
|
+
|
|
357
316
|
/**
|
|
358
317
|
* Returns the minDomain from props if it exists
|
|
359
318
|
* @param {Object} props: the props object
|
|
360
319
|
* @param {String} axis: the current axis
|
|
361
320
|
* @returns {Number|Date|undefined} the minDomain based on props
|
|
362
321
|
*/
|
|
363
|
-
|
|
364
322
|
export function getMinFromProps(props, axis) {
|
|
365
323
|
if (_isPlainObject(props.minDomain) && props.minDomain[axis] !== undefined) {
|
|
366
324
|
return props.minDomain[axis];
|
|
367
325
|
}
|
|
368
|
-
|
|
369
326
|
return typeof props.minDomain === "number" || _isDate(props.minDomain) ? props.minDomain : undefined;
|
|
370
327
|
}
|
|
328
|
+
|
|
371
329
|
/**
|
|
372
330
|
* Returns a symmetrically padded domain for polar charts
|
|
373
331
|
* @param {Array} domain: the original domain
|
|
@@ -375,33 +333,26 @@ export function getMinFromProps(props, axis) {
|
|
|
375
333
|
* for a given dimension i.e. only x values.
|
|
376
334
|
* @returns {Array} the symmetric domain
|
|
377
335
|
*/
|
|
378
|
-
|
|
379
336
|
export function getSymmetricDomain(domain, values) {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
}));
|
|
383
|
-
|
|
384
|
-
var step = processedData[1] - processedData[0];
|
|
337
|
+
const processedData = _sortedUniq(values.sort((a, b) => a - b));
|
|
338
|
+
const step = processedData[1] - processedData[0];
|
|
385
339
|
return [domain[0], domain[1] + step];
|
|
386
340
|
}
|
|
341
|
+
|
|
387
342
|
/**
|
|
388
343
|
* Checks whether a given component can be used to calculate domain
|
|
389
344
|
* @param {Component} component: a React component instance
|
|
390
345
|
* @returns {Boolean} Returns true if the given component has a role included in the whitelist
|
|
391
346
|
*/
|
|
392
|
-
|
|
393
347
|
export function isDomainComponent(component) {
|
|
394
|
-
|
|
348
|
+
const getRole = child => {
|
|
395
349
|
return child && child.type ? child.type.role : "";
|
|
396
350
|
};
|
|
397
|
-
|
|
398
|
-
var role = getRole(component);
|
|
399
|
-
|
|
351
|
+
let role = getRole(component);
|
|
400
352
|
if (role === "portal") {
|
|
401
|
-
|
|
353
|
+
const children = React.Children.toArray(component.props.children);
|
|
402
354
|
role = children.length ? getRole(children[0]) : "";
|
|
403
355
|
}
|
|
404
|
-
|
|
405
|
-
var whitelist = ["area", "axis", "bar", "boxplot", "candlestick", "errorbar", "group", "histogram", "line", "pie", "scatter", "stack", "voronoi"];
|
|
356
|
+
const whitelist = ["area", "axis", "bar", "boxplot", "candlestick", "errorbar", "group", "histogram", "line", "pie", "scatter", "stack", "voronoi"];
|
|
406
357
|
return whitelist.includes(role);
|
|
407
358
|
}
|