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
package/es/victory-util/axis.js
CHANGED
|
@@ -2,24 +2,10 @@ import _orderBy from "lodash/orderBy";
|
|
|
2
2
|
import _uniq from "lodash/uniq";
|
|
3
3
|
import _isObject from "lodash/isObject";
|
|
4
4
|
import _defaults from "lodash/defaults";
|
|
5
|
-
|
|
6
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
7
|
-
|
|
8
|
-
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."); }
|
|
9
|
-
|
|
10
|
-
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); }
|
|
11
|
-
|
|
12
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
13
|
-
|
|
14
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
15
|
-
|
|
16
|
-
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; }
|
|
17
|
-
|
|
18
5
|
import React from "react";
|
|
19
6
|
import * as Collection from "./collection";
|
|
20
7
|
import * as Domain from "./domain";
|
|
21
8
|
import * as Helpers from "./helpers";
|
|
22
|
-
|
|
23
9
|
/**
|
|
24
10
|
* Returns the first argument it receives
|
|
25
11
|
* @param value The value to return
|
|
@@ -28,57 +14,55 @@ import * as Helpers from "./helpers";
|
|
|
28
14
|
function identity(value) {
|
|
29
15
|
return value;
|
|
30
16
|
}
|
|
17
|
+
|
|
31
18
|
/**
|
|
32
19
|
* Returns the axis (x or y) of a particular axis component
|
|
33
20
|
* @param {Object} props: the props object.
|
|
34
21
|
* @param {Boolean} horizontal: true for horizontal charts
|
|
35
22
|
* @returns {String} the dimension appropriate for the axis given its props
|
|
36
23
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
24
|
export function getAxis(props) {
|
|
40
|
-
|
|
25
|
+
const {
|
|
26
|
+
dependentAxis
|
|
27
|
+
} = props;
|
|
41
28
|
return dependentAxis ? "y" : "x";
|
|
42
29
|
}
|
|
30
|
+
|
|
43
31
|
/**
|
|
44
32
|
* Returns all axis components that pass a given predicate
|
|
45
33
|
* @param {Array} childComponents: an array of children
|
|
46
34
|
* @param {Function} predicate: a predicate function that will be called with each
|
|
47
35
|
* @returns {Array} all axis components that pass the given predicate or []
|
|
48
36
|
*/
|
|
49
|
-
|
|
50
37
|
export function findAxisComponents(childComponents, predicate) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return children.reduce(function (memo, child) {
|
|
38
|
+
const predicateFunction = predicate || identity;
|
|
39
|
+
const findAxes = children => {
|
|
40
|
+
return children.reduce((memo, child) => {
|
|
55
41
|
if (child.type && child.type.role === "axis" && predicateFunction(child)) {
|
|
56
42
|
return memo.concat(child);
|
|
57
43
|
} else if (child.props && child.props.children) {
|
|
58
44
|
return memo.concat(findAxes(React.Children.toArray(child.props.children)));
|
|
59
45
|
}
|
|
60
|
-
|
|
61
46
|
return memo;
|
|
62
47
|
}, []);
|
|
63
48
|
};
|
|
64
|
-
|
|
65
49
|
return findAxes(childComponents);
|
|
66
50
|
}
|
|
51
|
+
|
|
67
52
|
/**
|
|
68
53
|
* Returns a single axis component of the desired axis type (x or y)
|
|
69
54
|
* @param {Array} childComponents: an array of children
|
|
70
55
|
* @param {String} axis: desired axis either "x" or "y".
|
|
71
56
|
* @returns {ReactComponent} an axis component of the desired axis or undefined
|
|
72
57
|
*/
|
|
73
|
-
|
|
74
58
|
export function getAxisComponent(childComponents, axis) {
|
|
75
|
-
|
|
76
|
-
|
|
59
|
+
const matchesAxis = component => {
|
|
60
|
+
const type = component.type.getAxis(component.props);
|
|
77
61
|
return type === axis;
|
|
78
62
|
};
|
|
79
|
-
|
|
80
63
|
return findAxisComponents(childComponents, matchesAxis)[0];
|
|
81
64
|
}
|
|
65
|
+
|
|
82
66
|
/**
|
|
83
67
|
* Returns all axis components of the desired axis type (x or y) along with any
|
|
84
68
|
* parent components excluding VictoryChart
|
|
@@ -86,54 +70,48 @@ export function getAxisComponent(childComponents, axis) {
|
|
|
86
70
|
* @param {String} type: desired axis either "dependent" or "independent".
|
|
87
71
|
* @returns {ReactComponent} an axis component of the desired type or undefined
|
|
88
72
|
*/
|
|
89
|
-
|
|
90
73
|
export function getAxisComponentsWithParent(childComponents, type) {
|
|
91
|
-
|
|
74
|
+
const matchesType = child => {
|
|
92
75
|
return type === "dependent" ? child.props.dependentAxis : !child.props.dependentAxis;
|
|
93
76
|
};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return children.reduce(function (memo, child) {
|
|
77
|
+
const findComponents = children => {
|
|
78
|
+
return children.reduce((memo, child) => {
|
|
97
79
|
if (child.type && child.type.role === "axis" && matchesType(child)) {
|
|
98
80
|
return memo.concat(child);
|
|
99
81
|
} else if (child.props && child.props.children) {
|
|
100
|
-
|
|
82
|
+
const childAxis = findComponents(React.Children.toArray(child.props.children));
|
|
101
83
|
return childAxis.length > 0 ? memo.concat(child) : memo;
|
|
102
84
|
}
|
|
103
|
-
|
|
104
85
|
return memo;
|
|
105
86
|
}, []);
|
|
106
87
|
};
|
|
107
|
-
|
|
108
88
|
return findComponents(childComponents);
|
|
109
89
|
}
|
|
110
90
|
export function getOrigin(domain) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
91
|
+
const getSingleOrigin = d => {
|
|
92
|
+
const domainMin = Math.min(...d);
|
|
93
|
+
const domainMax = Math.max(...d);
|
|
114
94
|
return domainMax < 0 ? domainMax : Math.max(0, domainMin);
|
|
115
95
|
};
|
|
116
|
-
|
|
117
96
|
return {
|
|
118
|
-
x: Collection.containsDates(domain.x) ? new Date(Math.min
|
|
119
|
-
y: Collection.containsDates(domain.y) ? new Date(Math.min
|
|
97
|
+
x: Collection.containsDates(domain.x) ? new Date(Math.min(...domain.x)) : getSingleOrigin(domain.x),
|
|
98
|
+
y: Collection.containsDates(domain.y) ? new Date(Math.min(...domain.y)) : getSingleOrigin(domain.y)
|
|
120
99
|
};
|
|
121
100
|
}
|
|
122
101
|
export function getOriginSign(origin, domain) {
|
|
123
|
-
|
|
124
|
-
return origin <= 0 && Math.max
|
|
102
|
+
const getSign = () => {
|
|
103
|
+
return origin <= 0 && Math.max(...domain) <= 0 ? "negative" : "positive";
|
|
125
104
|
};
|
|
126
|
-
|
|
127
105
|
return Collection.containsDates(domain) ? "positive" : getSign();
|
|
128
106
|
}
|
|
107
|
+
|
|
129
108
|
/**
|
|
130
109
|
* @param {Object} props: axis component props
|
|
131
110
|
* @returns {Boolean} true when the axis is vertical
|
|
132
111
|
*/
|
|
133
|
-
|
|
134
112
|
export function isVertical(props) {
|
|
135
|
-
|
|
136
|
-
|
|
113
|
+
const orientation = props.orientation || (props.dependentAxis ? "left" : "bottom");
|
|
114
|
+
const vertical = {
|
|
137
115
|
top: false,
|
|
138
116
|
bottom: false,
|
|
139
117
|
left: true,
|
|
@@ -141,207 +119,152 @@ export function isVertical(props) {
|
|
|
141
119
|
};
|
|
142
120
|
return vertical[orientation];
|
|
143
121
|
}
|
|
122
|
+
|
|
144
123
|
/**
|
|
145
124
|
* @param {Object} props: axis component props
|
|
146
125
|
* @returns {Boolean} true when tickValues contain strings
|
|
147
126
|
*/
|
|
148
|
-
|
|
149
127
|
export function stringTicks(props) {
|
|
150
128
|
return props.tickValues !== undefined && Collection.containsStrings(props.tickValues);
|
|
151
129
|
}
|
|
152
|
-
|
|
153
130
|
function getDefaultTickFormat(props) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
131
|
+
const {
|
|
132
|
+
tickValues
|
|
133
|
+
} = props;
|
|
134
|
+
const axis = getAxis(props);
|
|
135
|
+
const stringMap = props.stringMap && props.stringMap[axis];
|
|
136
|
+
const fallbackFormat = tickValues && !Collection.containsDates(tickValues) ? x => x : undefined;
|
|
161
137
|
if (!stringMap) {
|
|
162
|
-
return stringTicks(props) ?
|
|
163
|
-
return tickValues[index];
|
|
164
|
-
} : fallbackFormat;
|
|
138
|
+
return stringTicks(props) ? (x, index) => tickValues[index] : fallbackFormat;
|
|
165
139
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
var dataNames = tickValueArray.map(function (tick) {
|
|
174
|
-
return invertedStringMap[tick];
|
|
175
|
-
}); // string ticks should have one tick of padding at the beginning
|
|
176
|
-
|
|
177
|
-
var dataTicks = [""].concat(_toConsumableArray(dataNames), [""]);
|
|
178
|
-
return function (x) {
|
|
179
|
-
return dataTicks[x];
|
|
180
|
-
};
|
|
140
|
+
const invertedStringMap = stringMap && Helpers.invert(stringMap);
|
|
141
|
+
const tickValueArray = _orderBy(Object.values(stringMap), n => n);
|
|
142
|
+
const dataNames = tickValueArray.map(tick => invertedStringMap[tick]);
|
|
143
|
+
// string ticks should have one tick of padding at the beginning
|
|
144
|
+
const dataTicks = ["", ...dataNames, ""];
|
|
145
|
+
return x => dataTicks[x];
|
|
181
146
|
}
|
|
182
|
-
|
|
183
147
|
function getStringTicks(props) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}) : undefined;
|
|
190
|
-
var ticksFromStringMap = stringMap && Object.values(stringMap);
|
|
148
|
+
const axis = getAxis(props);
|
|
149
|
+
const stringMap = props.stringMap && props.stringMap[axis];
|
|
150
|
+
const categories = Array.isArray(props.categories) ? props.categories : props.categories && props.categories[axis];
|
|
151
|
+
const ticksFromCategories = categories && Collection.containsOnlyStrings(categories) ? categories.map(tick => stringMap[tick]) : undefined;
|
|
152
|
+
const ticksFromStringMap = stringMap && Object.values(stringMap);
|
|
191
153
|
return ticksFromCategories && ticksFromCategories.length !== 0 ? ticksFromCategories : ticksFromStringMap;
|
|
192
154
|
}
|
|
193
|
-
|
|
194
155
|
function getTickArray(props) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
156
|
+
const {
|
|
157
|
+
tickValues,
|
|
158
|
+
tickFormat
|
|
159
|
+
} = props;
|
|
160
|
+
if (tickValues?.length === 0) {
|
|
199
161
|
return [];
|
|
200
162
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
var getTicksFromFormat = function () {
|
|
163
|
+
const axis = getAxis(props);
|
|
164
|
+
const stringMap = props.stringMap && props.stringMap[axis];
|
|
165
|
+
const getTicksFromFormat = () => {
|
|
206
166
|
if (!tickFormat || !Array.isArray(tickFormat)) {
|
|
207
167
|
return undefined;
|
|
208
168
|
}
|
|
209
|
-
|
|
210
|
-
return Collection.containsStrings(tickFormat) ? tickFormat.map(function (t, i) {
|
|
211
|
-
return i;
|
|
212
|
-
}) : tickFormat;
|
|
169
|
+
return Collection.containsStrings(tickFormat) ? tickFormat.map((t, i) => i) : tickFormat;
|
|
213
170
|
};
|
|
214
|
-
|
|
215
|
-
var ticks = tickValues;
|
|
216
|
-
|
|
171
|
+
let ticks = tickValues;
|
|
217
172
|
if (stringMap) {
|
|
218
173
|
ticks = getStringTicks(props);
|
|
219
174
|
}
|
|
220
|
-
|
|
221
175
|
if (tickValues && Collection.containsStrings(tickValues)) {
|
|
222
|
-
ticks = stringMap ? tickValues.map(
|
|
223
|
-
return stringMap[tick];
|
|
224
|
-
}) : Helpers.range(1, tickValues.length + 1);
|
|
176
|
+
ticks = stringMap ? tickValues.map(tick => stringMap[tick]) : Helpers.range(1, tickValues.length + 1);
|
|
225
177
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
var newTickArray = [];
|
|
231
|
-
var domain = props.domain && props.domain[axis] || props.domain;
|
|
232
|
-
|
|
178
|
+
const tickArray = ticks ? _uniq(ticks) : getTicksFromFormat();
|
|
179
|
+
const buildTickArray = arr => {
|
|
180
|
+
const newTickArray = [];
|
|
181
|
+
const domain = props.domain && props.domain[axis] || props.domain;
|
|
233
182
|
if (arr) {
|
|
234
|
-
arr.forEach(
|
|
183
|
+
arr.forEach((t, index) => {
|
|
235
184
|
if (Array.isArray(domain)) {
|
|
236
185
|
if (t >= Collection.getMinValue(domain) && t <= Collection.getMaxValue(domain)) {
|
|
237
186
|
newTickArray.push({
|
|
238
187
|
value: t,
|
|
239
|
-
index
|
|
188
|
+
index
|
|
240
189
|
});
|
|
241
190
|
}
|
|
242
191
|
} else {
|
|
243
192
|
newTickArray.push({
|
|
244
193
|
value: t,
|
|
245
|
-
index
|
|
194
|
+
index
|
|
246
195
|
});
|
|
247
196
|
}
|
|
248
197
|
});
|
|
249
198
|
return newTickArray;
|
|
250
199
|
}
|
|
251
|
-
|
|
252
200
|
return undefined;
|
|
253
201
|
};
|
|
254
|
-
|
|
255
202
|
return Array.isArray(tickArray) && tickArray.length ? buildTickArray(tickArray) : undefined;
|
|
256
203
|
}
|
|
257
|
-
|
|
258
204
|
export function getTickFormat(props, scale) {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
205
|
+
const {
|
|
206
|
+
tickFormat
|
|
207
|
+
} = props;
|
|
208
|
+
const axis = getAxis(props);
|
|
209
|
+
const stringMap = props.stringMap && props.stringMap[axis];
|
|
263
210
|
if (!tickFormat) {
|
|
264
|
-
|
|
211
|
+
const defaultTickFormat = getDefaultTickFormat(props);
|
|
212
|
+
// If there is no user-provided tick format, we use d3's tickFormat function
|
|
265
213
|
// by default. This changed the default formatting for some scale types when
|
|
266
214
|
// we upgraded to d3-scale@4..
|
|
267
|
-
|
|
268
|
-
var scaleTickFormat = scale.tickFormat && Helpers.isFunction(scale.tickFormat) ? scale.tickFormat() : function (x) {
|
|
269
|
-
return x;
|
|
270
|
-
};
|
|
215
|
+
const scaleTickFormat = scale.tickFormat && Helpers.isFunction(scale.tickFormat) ? scale.tickFormat() : x => x;
|
|
271
216
|
return defaultTickFormat || scaleTickFormat;
|
|
272
217
|
} else if (tickFormat && Array.isArray(tickFormat)) {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
var filteredTickFormat = tickFormat.filter(function (t, index) {
|
|
278
|
-
return tickArrayIndices === null || tickArrayIndices === void 0 ? void 0 : tickArrayIndices.includes(index);
|
|
279
|
-
});
|
|
280
|
-
return function (x, index) {
|
|
281
|
-
return filteredTickFormat[index];
|
|
282
|
-
};
|
|
218
|
+
const tickArray = getTickArray(props);
|
|
219
|
+
const tickArrayIndices = tickArray?.map(v => v.index);
|
|
220
|
+
const filteredTickFormat = tickFormat.filter((t, index) => tickArrayIndices?.includes(index));
|
|
221
|
+
return (x, index) => filteredTickFormat[index];
|
|
283
222
|
} else if (tickFormat && Helpers.isFunction(tickFormat)) {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
return invertedStringMap[t];
|
|
288
|
-
});
|
|
223
|
+
const applyStringTicks = (tick, index, ticks) => {
|
|
224
|
+
const invertedStringMap = Helpers.invert(stringMap);
|
|
225
|
+
const stringTickArray = ticks.map(t => invertedStringMap[t]);
|
|
289
226
|
return props.tickFormat(invertedStringMap[tick], index, stringTickArray);
|
|
290
227
|
};
|
|
291
|
-
|
|
292
228
|
return stringMap ? applyStringTicks : tickFormat;
|
|
293
229
|
}
|
|
294
|
-
|
|
295
|
-
return function (x) {
|
|
296
|
-
return x;
|
|
297
|
-
};
|
|
230
|
+
return x => x;
|
|
298
231
|
}
|
|
299
|
-
|
|
300
232
|
function downsampleTicks(ticks, tickCount) {
|
|
301
233
|
if (!tickCount || !Array.isArray(ticks) || ticks.length <= tickCount) {
|
|
302
234
|
return ticks;
|
|
303
235
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
return ticks.filter(function (d, i) {
|
|
307
|
-
return i % k === 0;
|
|
308
|
-
});
|
|
236
|
+
const k = Math.floor(ticks.length / tickCount);
|
|
237
|
+
return ticks.filter((d, i) => i % k === 0);
|
|
309
238
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
239
|
+
export function getTicks(props, scale, filterZero) {
|
|
240
|
+
if (filterZero === void 0) {
|
|
241
|
+
filterZero = false;
|
|
242
|
+
}
|
|
243
|
+
const {
|
|
244
|
+
tickCount
|
|
245
|
+
} = props;
|
|
246
|
+
const tickArray = getTickArray(props);
|
|
247
|
+
if (tickArray?.length === 0) {
|
|
317
248
|
return [""];
|
|
318
249
|
}
|
|
319
|
-
|
|
320
|
-
var tickValues = tickArray ? tickArray.map(function (v) {
|
|
321
|
-
return v.value;
|
|
322
|
-
}) : undefined;
|
|
323
|
-
|
|
250
|
+
const tickValues = tickArray ? tickArray.map(v => v.value) : undefined;
|
|
324
251
|
if (tickValues) {
|
|
325
252
|
return downsampleTicks(tickValues, tickCount);
|
|
326
253
|
} else if (scale.ticks && Helpers.isFunction(scale.ticks)) {
|
|
327
254
|
// eslint-disable-next-line no-magic-numbers
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
255
|
+
const defaultTickCount = tickCount || 5;
|
|
256
|
+
const scaleTicks = scale.ticks(defaultTickCount);
|
|
257
|
+
const scaledTickArray = Array.isArray(scaleTicks) && scaleTicks.length ? scaleTicks : scale.domain();
|
|
258
|
+
const ticks = downsampleTicks(scaledTickArray, tickCount);
|
|
333
259
|
if (filterZero) {
|
|
334
|
-
|
|
335
|
-
return value !== 0;
|
|
336
|
-
});
|
|
260
|
+
const filteredTicks = ticks.filter(value => value !== 0);
|
|
337
261
|
return filteredTicks.length ? filteredTicks : ticks;
|
|
338
262
|
}
|
|
339
|
-
|
|
340
263
|
return ticks;
|
|
341
264
|
}
|
|
342
|
-
|
|
343
265
|
return scale.domain();
|
|
344
266
|
}
|
|
267
|
+
|
|
345
268
|
/**
|
|
346
269
|
* Returns a domain based tickValues
|
|
347
270
|
* @param {Object} props: the props object
|
|
@@ -349,92 +272,73 @@ export function getTicks(props, scale) {
|
|
|
349
272
|
* @returns {Array} returns a domain from tickValues
|
|
350
273
|
*/
|
|
351
274
|
// eslint-disable-next-line max-statements
|
|
352
|
-
|
|
353
275
|
function getDomainFromData(props, axis) {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
return v.value;
|
|
362
|
-
}) : undefined;
|
|
363
|
-
|
|
276
|
+
const {
|
|
277
|
+
polar,
|
|
278
|
+
startAngle = 0,
|
|
279
|
+
endAngle = 360
|
|
280
|
+
} = props;
|
|
281
|
+
const tickArray = getTickArray(props);
|
|
282
|
+
const tickValues = tickArray && tickArray?.length !== 0 ? tickArray.map(v => v.value) : undefined;
|
|
364
283
|
if (!Array.isArray(tickValues)) {
|
|
365
284
|
return undefined;
|
|
366
285
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
var max = maxDomain !== undefined ? maxDomain : defaultMax;
|
|
378
|
-
var initialDomain = Domain.getDomainFromMinMax(min, max);
|
|
379
|
-
var domain = polar && axis === "x" && Math.abs(startAngle - endAngle) === 360 ? Domain.getSymmetricDomain(initialDomain, ticks) : initialDomain;
|
|
380
|
-
|
|
286
|
+
const minDomain = Domain.getMinFromProps(props, axis);
|
|
287
|
+
const maxDomain = Domain.getMaxFromProps(props, axis);
|
|
288
|
+
const tickStrings = stringTicks(props);
|
|
289
|
+
const ticks = tickValues.map(value => Number(value));
|
|
290
|
+
const defaultMin = tickStrings ? 1 : Collection.getMinValue(ticks);
|
|
291
|
+
const defaultMax = tickStrings ? tickValues.length : Collection.getMaxValue(ticks);
|
|
292
|
+
const min = minDomain !== undefined ? minDomain : defaultMin;
|
|
293
|
+
const max = maxDomain !== undefined ? maxDomain : defaultMax;
|
|
294
|
+
const initialDomain = Domain.getDomainFromMinMax(min, max);
|
|
295
|
+
const domain = polar && axis === "x" && Math.abs(startAngle - endAngle) === 360 ? Domain.getSymmetricDomain(initialDomain, ticks) : initialDomain;
|
|
381
296
|
if (isVertical(props) && !polar) {
|
|
382
297
|
domain.reverse();
|
|
383
298
|
}
|
|
384
|
-
|
|
385
299
|
return domain;
|
|
386
|
-
}
|
|
387
|
-
|
|
300
|
+
}
|
|
388
301
|
|
|
302
|
+
// exposed for use by VictoryChart
|
|
389
303
|
export function getDomain(props, axis) {
|
|
390
|
-
|
|
391
|
-
|
|
304
|
+
const inherentAxis = getAxis(props);
|
|
392
305
|
if (axis && axis !== inherentAxis) {
|
|
393
306
|
return undefined;
|
|
394
307
|
}
|
|
395
|
-
|
|
396
308
|
return Domain.createDomainFunction(getDomainFromData)(props, inherentAxis);
|
|
397
309
|
}
|
|
398
310
|
export function getAxisValue(props, axis) {
|
|
399
311
|
if (!props.axisValue) {
|
|
400
312
|
return undefined;
|
|
401
313
|
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
var scale = _isObject(props.scale) && Helpers.isFunction(props.scale[scaleAxis]) ? props.scale[scaleAxis] : undefined;
|
|
405
|
-
|
|
314
|
+
const scaleAxis = axis === "x" ? "y" : "x";
|
|
315
|
+
const scale = _isObject(props.scale) && Helpers.isFunction(props.scale[scaleAxis]) ? props.scale[scaleAxis] : undefined;
|
|
406
316
|
if (!scale) {
|
|
407
317
|
return undefined;
|
|
408
318
|
}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
var axisValue = stringMap && typeof props.axisValue === "string" ? stringMap[props.axisValue] : props.axisValue;
|
|
319
|
+
const stringMapAxis = axis === "x" ? "y" : "x";
|
|
320
|
+
const stringMap = _isObject(props.stringMap) && props.stringMap[stringMapAxis];
|
|
321
|
+
const axisValue = stringMap && typeof props.axisValue === "string" ? stringMap[props.axisValue] : props.axisValue;
|
|
413
322
|
return scale(axisValue);
|
|
414
323
|
}
|
|
415
324
|
export function modifyProps(props, fallbackProps) {
|
|
416
325
|
if (!_isObject(props.theme)) {
|
|
417
326
|
return Helpers.modifyProps(props, fallbackProps, "axis");
|
|
418
327
|
}
|
|
419
|
-
|
|
420
|
-
var role = "axis";
|
|
421
|
-
|
|
328
|
+
let role = "axis";
|
|
422
329
|
if (props.dependentAxis && props.theme.dependentAxis) {
|
|
423
330
|
role = "dependentAxis";
|
|
424
331
|
} else if (!props.dependentAxis && props.theme.independentAxis) {
|
|
425
332
|
role = "independentAxis";
|
|
426
333
|
}
|
|
427
|
-
|
|
428
334
|
if (role === "axis") {
|
|
429
335
|
return Helpers.modifyProps(props, fallbackProps, "axis");
|
|
430
336
|
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
var theme = Object.assign({}, props.theme, {
|
|
337
|
+
const axisTheme = _defaults({}, props.theme[role], props.theme.axis);
|
|
338
|
+
const theme = Object.assign({}, props.theme, {
|
|
435
339
|
axis: axisTheme
|
|
436
340
|
});
|
|
437
341
|
return Helpers.modifyProps(Object.assign({}, props, {
|
|
438
|
-
theme
|
|
342
|
+
theme
|
|
439
343
|
}), fallbackProps, "axis");
|
|
440
344
|
}
|
|
@@ -1,78 +1,50 @@
|
|
|
1
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
|
-
|
|
3
|
-
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."); }
|
|
4
|
-
|
|
5
|
-
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); }
|
|
6
|
-
|
|
7
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
8
|
-
|
|
9
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
10
|
-
|
|
11
|
-
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; }
|
|
12
|
-
|
|
13
1
|
function isNonEmptyArray(collection) {
|
|
14
2
|
return Array.isArray(collection) && collection.length > 0;
|
|
15
3
|
}
|
|
16
|
-
|
|
17
4
|
export function containsStrings(collection) {
|
|
18
|
-
return Array.isArray(collection) && collection.some(
|
|
19
|
-
return typeof value === "string";
|
|
20
|
-
});
|
|
5
|
+
return Array.isArray(collection) && collection.some(value => typeof value === "string");
|
|
21
6
|
}
|
|
22
7
|
export function containsDates(collection) {
|
|
23
|
-
return Array.isArray(collection) && collection.some(
|
|
24
|
-
return value instanceof Date;
|
|
25
|
-
});
|
|
8
|
+
return Array.isArray(collection) && collection.some(value => value instanceof Date);
|
|
26
9
|
}
|
|
27
10
|
export function containsNumbers(collection) {
|
|
28
|
-
return Array.isArray(collection) && collection.some(
|
|
29
|
-
return typeof value === "number";
|
|
30
|
-
});
|
|
11
|
+
return Array.isArray(collection) && collection.some(value => typeof value === "number");
|
|
31
12
|
}
|
|
32
13
|
export function containsOnlyStrings(collection) {
|
|
33
|
-
return isNonEmptyArray(collection) && collection.every(
|
|
34
|
-
return typeof value === "string";
|
|
35
|
-
});
|
|
14
|
+
return isNonEmptyArray(collection) && collection.every(value => typeof value === "string");
|
|
36
15
|
}
|
|
16
|
+
|
|
37
17
|
/**
|
|
38
18
|
* Creates an array of array values not included in the other given arrays
|
|
39
19
|
* @param a The array to inspect
|
|
40
20
|
* @param b The values to exclude
|
|
41
21
|
* @returns The new array of filtered values
|
|
42
22
|
*/
|
|
43
|
-
|
|
44
23
|
export function difference(a, b) {
|
|
45
24
|
if (a && b) {
|
|
46
|
-
return a.filter(
|
|
47
|
-
return !b.includes(value);
|
|
48
|
-
});
|
|
25
|
+
return a.filter(value => !b.includes(value));
|
|
49
26
|
}
|
|
50
|
-
|
|
51
27
|
return [];
|
|
52
28
|
}
|
|
53
29
|
export function isArrayOfArrays(collection) {
|
|
54
30
|
return isNonEmptyArray(collection) && collection.every(Array.isArray);
|
|
55
31
|
}
|
|
56
32
|
export function removeUndefined(arr) {
|
|
57
|
-
return arr.filter(
|
|
58
|
-
return el !== undefined;
|
|
59
|
-
});
|
|
33
|
+
return arr.filter(el => el !== undefined);
|
|
60
34
|
}
|
|
61
35
|
export function getMaxValue(arr) {
|
|
62
36
|
for (var _len = arguments.length, values = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
63
37
|
values[_key - 1] = arguments[_key];
|
|
64
38
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
: Math.max.apply(Math, _toConsumableArray(array));
|
|
39
|
+
const array = arr.concat(values);
|
|
40
|
+
return containsDates(array) ? new Date(Math.max(...array)) // Dates will be coerced to numbers
|
|
41
|
+
: Math.max(...array);
|
|
69
42
|
}
|
|
70
43
|
export function getMinValue(arr) {
|
|
71
44
|
for (var _len2 = arguments.length, values = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
72
45
|
values[_key2 - 1] = arguments[_key2];
|
|
73
46
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
: Math.min.apply(Math, _toConsumableArray(array));
|
|
47
|
+
const array = arr.concat(values);
|
|
48
|
+
return containsDates(array) ? new Date(Math.min(...array)) // Dates will be coerced to numbers
|
|
49
|
+
: Math.min(...array);
|
|
78
50
|
}
|