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