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/data.js
CHANGED
|
@@ -14,241 +14,195 @@ exports.getStringsFromAxes = getStringsFromAxes;
|
|
|
14
14
|
exports.getStringsFromCategories = getStringsFromCategories;
|
|
15
15
|
exports.getStringsFromData = getStringsFromData;
|
|
16
16
|
exports.isDataComponent = isDataComponent;
|
|
17
|
-
|
|
18
17
|
var _omitBy2 = _interopRequireDefault(require("lodash/omitBy"));
|
|
19
|
-
|
|
20
18
|
var _isUndefined2 = _interopRequireDefault(require("lodash/isUndefined"));
|
|
21
|
-
|
|
22
19
|
var _isEqual2 = _interopRequireDefault(require("lodash/isEqual"));
|
|
23
|
-
|
|
24
20
|
var _isEmpty2 = _interopRequireDefault(require("lodash/isEmpty"));
|
|
25
|
-
|
|
26
21
|
var _orderBy2 = _interopRequireDefault(require("lodash/orderBy"));
|
|
27
|
-
|
|
28
22
|
var _property2 = _interopRequireDefault(require("lodash/property"));
|
|
29
|
-
|
|
30
23
|
var _isPlainObject2 = _interopRequireDefault(require("lodash/isPlainObject"));
|
|
31
|
-
|
|
32
24
|
var _uniq2 = _interopRequireDefault(require("lodash/uniq"));
|
|
33
|
-
|
|
34
25
|
var _react = _interopRequireDefault(require("react"));
|
|
35
|
-
|
|
36
26
|
var Helpers = _interopRequireWildcard(require("./helpers"));
|
|
37
|
-
|
|
38
27
|
var Collection = _interopRequireWildcard(require("./collection"));
|
|
39
|
-
|
|
40
28
|
var Scale = _interopRequireWildcard(require("./scale"));
|
|
41
|
-
|
|
42
29
|
var Immutable = _interopRequireWildcard(require("./immutable"));
|
|
43
|
-
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
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; }
|
|
47
|
-
|
|
30
|
+
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); }
|
|
31
|
+
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; }
|
|
48
32
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
49
|
-
|
|
50
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
51
|
-
|
|
52
|
-
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."); }
|
|
53
|
-
|
|
54
|
-
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); }
|
|
55
|
-
|
|
56
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
57
|
-
|
|
58
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
59
|
-
|
|
60
|
-
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; }
|
|
33
|
+
/* eslint-disable no-use-before-define */
|
|
61
34
|
|
|
62
35
|
// Private Functions
|
|
36
|
+
|
|
63
37
|
function parseDatum(datum) {
|
|
64
|
-
|
|
38
|
+
const immutableDatumWhitelist = {
|
|
65
39
|
errorX: true,
|
|
66
40
|
errorY: true
|
|
67
41
|
};
|
|
68
42
|
return Immutable.isImmutable(datum) ? Immutable.shallowToJS(datum, immutableDatumWhitelist) : datum;
|
|
69
43
|
}
|
|
70
|
-
|
|
71
44
|
function getLength(data) {
|
|
72
45
|
return Immutable.isIterable(data) ? data.size : data.length;
|
|
73
|
-
}
|
|
74
|
-
|
|
46
|
+
}
|
|
75
47
|
|
|
48
|
+
// Returns generated data for a given axis based on domain and sample from props
|
|
76
49
|
function generateDataArray(props, axis) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
50
|
+
const propsDomain = (0, _isPlainObject2.default)(props.domain) ? props.domain[axis] : props.domain;
|
|
51
|
+
const domain = propsDomain || Scale.getBaseScale(props, axis).domain();
|
|
52
|
+
const samples = props.samples || 1;
|
|
53
|
+
const domainMax = Math.max(...domain);
|
|
54
|
+
const domainMin = Math.min(...domain);
|
|
55
|
+
const step = (domainMax - domainMin) / samples;
|
|
56
|
+
const values = Helpers.range(domainMin, domainMax, step);
|
|
84
57
|
return values[values.length - 1] === domainMax ? values : values.concat(domainMax);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
function sortData(dataset, sortKey) {
|
|
89
|
-
var sortOrder = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "ascending";
|
|
58
|
+
}
|
|
90
59
|
|
|
60
|
+
// Returns sorted data. If no sort keys are provided, data is returned unaltered.
|
|
61
|
+
function sortData(dataset, sortKey, sortOrder) {
|
|
62
|
+
if (sortOrder === void 0) {
|
|
63
|
+
sortOrder = "ascending";
|
|
64
|
+
}
|
|
91
65
|
if (!sortKey) {
|
|
92
66
|
return dataset;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
var formattedSortKey = sortKey;
|
|
67
|
+
}
|
|
97
68
|
|
|
69
|
+
// Ensures previous VictoryLine api for sortKey prop stays consistent
|
|
70
|
+
let formattedSortKey = sortKey;
|
|
98
71
|
if (sortKey === "x" || sortKey === "y") {
|
|
99
|
-
formattedSortKey =
|
|
72
|
+
formattedSortKey = `_${sortKey}`;
|
|
100
73
|
}
|
|
101
|
-
|
|
102
|
-
var order = sortOrder === "ascending" ? "asc" : "desc";
|
|
74
|
+
const order = sortOrder === "ascending" ? "asc" : "desc";
|
|
103
75
|
return (0, _orderBy2.default)(dataset, formattedSortKey, order);
|
|
104
|
-
}
|
|
105
|
-
|
|
76
|
+
}
|
|
106
77
|
|
|
78
|
+
// This method will remove data points that break certain scales. (log scale only)
|
|
107
79
|
function cleanData(dataset, props) {
|
|
108
|
-
|
|
109
|
-
|
|
80
|
+
const smallNumber = 1 / Number.MAX_SAFE_INTEGER;
|
|
81
|
+
const scaleType = {
|
|
110
82
|
x: Scale.getScaleType(props, "x"),
|
|
111
83
|
y: Scale.getScaleType(props, "y")
|
|
112
84
|
};
|
|
113
|
-
|
|
114
85
|
if (scaleType.x !== "log" && scaleType.y !== "log") {
|
|
115
86
|
return dataset;
|
|
116
87
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return scaleType[axis] === "log" ? datum["_".concat(axis)] !== 0 : true;
|
|
88
|
+
const rules = (datum, axis) => {
|
|
89
|
+
return scaleType[axis] === "log" ? datum[`_${axis}`] !== 0 : true;
|
|
120
90
|
};
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
var _y = rules(datum, "y") ? datum._y : smallNumber;
|
|
126
|
-
|
|
127
|
-
var _y0 = rules(datum, "y0") ? datum._y0 : smallNumber;
|
|
128
|
-
|
|
91
|
+
const sanitize = datum => {
|
|
92
|
+
const _x = rules(datum, "x") ? datum._x : smallNumber;
|
|
93
|
+
const _y = rules(datum, "y") ? datum._y : smallNumber;
|
|
94
|
+
const _y0 = rules(datum, "y0") ? datum._y0 : smallNumber;
|
|
129
95
|
return Object.assign({}, datum, {
|
|
130
|
-
_x
|
|
131
|
-
_y
|
|
132
|
-
_y0
|
|
96
|
+
_x,
|
|
97
|
+
_y,
|
|
98
|
+
_y0
|
|
133
99
|
});
|
|
134
100
|
};
|
|
135
|
-
|
|
136
|
-
return dataset.map(function (datum) {
|
|
101
|
+
return dataset.map(datum => {
|
|
137
102
|
if (rules(datum, "x") && rules(datum, "y") && rules(datum, "y0")) {
|
|
138
103
|
return datum;
|
|
139
104
|
}
|
|
140
|
-
|
|
141
105
|
return sanitize(datum);
|
|
142
106
|
});
|
|
143
|
-
}
|
|
144
|
-
|
|
107
|
+
}
|
|
145
108
|
|
|
109
|
+
// Returns a data accessor given an eventKey prop
|
|
146
110
|
function getEventKey(key) {
|
|
147
111
|
// creates a data accessor function
|
|
148
112
|
// given a property key, path, array index, or null for identity.
|
|
149
113
|
if (Helpers.isFunction(key)) {
|
|
150
114
|
return key;
|
|
151
115
|
} else if (key === null || key === undefined) {
|
|
152
|
-
return
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
} // otherwise, assume it is an array index, property key or path (_.property handles all three)
|
|
156
|
-
|
|
157
|
-
|
|
116
|
+
return () => undefined;
|
|
117
|
+
}
|
|
118
|
+
// otherwise, assume it is an array index, property key or path (_.property handles all three)
|
|
158
119
|
return (0, _property2.default)(key);
|
|
159
|
-
}
|
|
160
|
-
|
|
120
|
+
}
|
|
161
121
|
|
|
122
|
+
// Returns data with an eventKey prop added to each datum
|
|
162
123
|
function addEventKeys(props, data) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
return data.map(
|
|
124
|
+
const hasEventKeyAccessor = !!props.eventKey;
|
|
125
|
+
const eventKeyAccessor = getEventKey(props.eventKey);
|
|
126
|
+
return data.map((datum, index) => {
|
|
166
127
|
if (datum.eventKey !== undefined) {
|
|
167
128
|
return datum;
|
|
168
129
|
} else if (hasEventKeyAccessor) {
|
|
169
|
-
|
|
130
|
+
const eventKey = eventKeyAccessor(datum, index);
|
|
170
131
|
return eventKey !== undefined ? Object.assign({
|
|
171
|
-
eventKey
|
|
132
|
+
eventKey
|
|
172
133
|
}, datum) : datum;
|
|
173
134
|
}
|
|
174
|
-
|
|
175
135
|
return datum;
|
|
176
136
|
});
|
|
177
|
-
}
|
|
178
|
-
// This method will remove data points that fall outside of the desired domain (non-continuous charts only)
|
|
137
|
+
}
|
|
179
138
|
|
|
139
|
+
// Exported Functions
|
|
180
140
|
|
|
141
|
+
// This method will remove data points that fall outside of the desired domain (non-continuous charts only)
|
|
181
142
|
function formatDataFromDomain(dataset, domain, defaultBaseline) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
var isUnderMinY = underMin(minDomainY);
|
|
205
|
-
var isOverMaxX = overMax(maxDomainX);
|
|
206
|
-
var isOverMaxY = overMax(maxDomainY); // eslint-disable-next-line complexity
|
|
207
|
-
|
|
208
|
-
return dataset.map(function (datum) {
|
|
209
|
-
var _x = datum._x,
|
|
210
|
-
_y = datum._y,
|
|
211
|
-
_y0 = datum._y0,
|
|
212
|
-
_y1 = datum._y1; // single x point less than min domain
|
|
213
|
-
|
|
143
|
+
const exists = val => val !== undefined;
|
|
144
|
+
const minDomainX = Collection.getMinValue(domain.x);
|
|
145
|
+
const maxDomainX = Collection.getMaxValue(domain.x);
|
|
146
|
+
const minDomainY = Collection.getMinValue(domain.y);
|
|
147
|
+
const maxDomainY = Collection.getMaxValue(domain.y);
|
|
148
|
+
const underMin = min => val => exists(val) && val < min;
|
|
149
|
+
const overMax = max => val => exists(val) && val > max;
|
|
150
|
+
const isUnderMinX = underMin(minDomainX);
|
|
151
|
+
const isUnderMinY = underMin(minDomainY);
|
|
152
|
+
const isOverMaxX = overMax(maxDomainX);
|
|
153
|
+
const isOverMaxY = overMax(maxDomainY);
|
|
154
|
+
|
|
155
|
+
// eslint-disable-next-line complexity
|
|
156
|
+
return dataset.map(datum => {
|
|
157
|
+
let {
|
|
158
|
+
_x,
|
|
159
|
+
_y,
|
|
160
|
+
_y0,
|
|
161
|
+
_y1
|
|
162
|
+
} = datum;
|
|
163
|
+
|
|
164
|
+
// single x point less than min domain
|
|
214
165
|
if (isUnderMinX(_x) || isOverMaxX(_x)) _x = null;
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
if (!exists(value)) return datum;
|
|
166
|
+
const baseline = exists(_y0) ? _y0 : defaultBaseline;
|
|
167
|
+
const value = exists(_y1) ? _y1 : _y;
|
|
168
|
+
if (!exists(value)) return datum;
|
|
218
169
|
|
|
219
|
-
|
|
170
|
+
// value only and less than min domain or greater than max domain
|
|
171
|
+
if (!exists(baseline) && (isUnderMinY(value) || isOverMaxY(value))) _y = null;
|
|
220
172
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
if (isUnderMinY(baseline) && !isUnderMinY(value)) _y0 = minDomainY; // baseline and value with only baseline above max, set baseline to maxDomainY
|
|
173
|
+
// baseline and value are both less than min domain or both greater than max domain
|
|
174
|
+
if (isUnderMinY(baseline) && isUnderMinY(value) || isOverMaxY(baseline) && isOverMaxY(value)) _y = _y0 = _y1 = null;
|
|
224
175
|
|
|
176
|
+
// baseline and value with only baseline below min, set baseline to minDomainY
|
|
177
|
+
if (isUnderMinY(baseline) && !isUnderMinY(value)) _y0 = minDomainY;
|
|
178
|
+
// baseline and value with only baseline above max, set baseline to maxDomainY
|
|
225
179
|
if (isOverMaxY(baseline) && !isOverMaxY(value)) _y0 = maxDomainY;
|
|
226
180
|
return Object.assign({}, datum, (0, _omitBy2.default)({
|
|
227
|
-
_x
|
|
228
|
-
_y
|
|
229
|
-
_y0
|
|
230
|
-
_y1
|
|
181
|
+
_x,
|
|
182
|
+
_y,
|
|
183
|
+
_y0,
|
|
184
|
+
_y1
|
|
231
185
|
}, _isUndefined2.default));
|
|
232
186
|
});
|
|
233
187
|
}
|
|
188
|
+
|
|
234
189
|
/**
|
|
235
190
|
* Returns an object mapping string data to numeric data
|
|
236
191
|
* @param {Object} props: the props object
|
|
237
192
|
* @param {String} axis: the current axis
|
|
238
193
|
* @returns {Object} an object mapping string data to numeric data
|
|
239
194
|
*/
|
|
240
|
-
|
|
241
|
-
|
|
242
195
|
function createStringMap(props, axis) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
return allStrings.length === 0 ? null : allStrings.reduce(
|
|
196
|
+
const stringsFromAxes = getStringsFromAxes(props, axis);
|
|
197
|
+
const stringsFromCategories = getStringsFromCategories(props, axis);
|
|
198
|
+
const stringsFromData = getStringsFromData(props, axis);
|
|
199
|
+
const allStrings = (0, _uniq2.default)([...stringsFromAxes, ...stringsFromCategories, ...stringsFromData]);
|
|
200
|
+
return allStrings.length === 0 ? null : allStrings.reduce((memo, string, index) => {
|
|
248
201
|
memo[string] = index + 1;
|
|
249
202
|
return memo;
|
|
250
203
|
}, {});
|
|
251
204
|
}
|
|
205
|
+
|
|
252
206
|
/**
|
|
253
207
|
* Reduces the size of a data array, such that it is <= maxPoints.
|
|
254
208
|
* @param {Array} data: an array of data; must be sorted
|
|
@@ -257,25 +211,23 @@ function createStringMap(props, axis) {
|
|
|
257
211
|
assumes `data` param is a subset of larger dataset that has been zoommed
|
|
258
212
|
* @returns {Array} an array of data, a subset of data param
|
|
259
213
|
*/
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
214
|
+
function downsample(data, maxPoints, startingIndex) {
|
|
215
|
+
if (startingIndex === void 0) {
|
|
216
|
+
startingIndex = 0;
|
|
217
|
+
}
|
|
264
218
|
// ensures that the downampling of data while zooming looks good.
|
|
265
|
-
|
|
266
|
-
|
|
219
|
+
const dataLength = getLength(data);
|
|
267
220
|
if (dataLength > maxPoints) {
|
|
268
221
|
// limit k to powers of 2, e.g. 64, 128, 256
|
|
269
222
|
// so that the same points will be chosen reliably, reducing flicker on zoom
|
|
270
|
-
|
|
271
|
-
return data.filter(
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
});
|
|
223
|
+
const k = Math.pow(2, Math.ceil(Math.log2(dataLength / maxPoints)));
|
|
224
|
+
return data.filter(
|
|
225
|
+
// ensure modulo is always calculated from same reference: i + startingIndex
|
|
226
|
+
(d, i) => (i + startingIndex) % k === 0);
|
|
275
227
|
}
|
|
276
|
-
|
|
277
228
|
return data;
|
|
278
229
|
}
|
|
230
|
+
|
|
279
231
|
/**
|
|
280
232
|
* Returns formatted data. Data accessors are applied, and string values are replaced.
|
|
281
233
|
* @param {Array} dataset: the original domain
|
|
@@ -283,32 +235,25 @@ function downsample(data, maxPoints) {
|
|
|
283
235
|
* @param {Array} expectedKeys: an array of expected data keys
|
|
284
236
|
* @returns {Array} the formatted data
|
|
285
237
|
*/
|
|
286
|
-
|
|
287
|
-
|
|
288
238
|
function formatData(dataset, props, expectedKeys) {
|
|
289
|
-
|
|
290
|
-
|
|
239
|
+
const isArrayOrIterable = Array.isArray(dataset) || Immutable.isIterable(dataset);
|
|
291
240
|
if (!isArrayOrIterable || getLength(dataset) < 1) {
|
|
292
241
|
return [];
|
|
293
242
|
}
|
|
294
|
-
|
|
295
|
-
|
|
243
|
+
const defaultKeys = ["x", "y", "y0"];
|
|
244
|
+
// TODO: We shouldn’t mutate the expectedKeys param here,
|
|
296
245
|
// but we need to figure out why changing it causes regressions in tests.
|
|
297
246
|
// eslint-disable-next-line no-param-reassign
|
|
298
|
-
|
|
299
247
|
expectedKeys = Array.isArray(expectedKeys) ? expectedKeys : defaultKeys;
|
|
300
|
-
|
|
301
|
-
var createAccessor = function (name) {
|
|
248
|
+
const createAccessor = name => {
|
|
302
249
|
return Helpers.createAccessor(props[name] !== undefined ? props[name] : name);
|
|
303
250
|
};
|
|
304
|
-
|
|
305
|
-
var accessor = expectedKeys.reduce(function (memo, type) {
|
|
251
|
+
const accessor = expectedKeys.reduce((memo, type) => {
|
|
306
252
|
memo[type] = createAccessor(type);
|
|
307
253
|
return memo;
|
|
308
254
|
}, {});
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
255
|
+
const preformattedData = (0, _isEqual2.default)(expectedKeys, defaultKeys) && props.x === "_x" && props.y === "_y" && props.y0 === "_y0";
|
|
256
|
+
let stringMap;
|
|
312
257
|
if (preformattedData === false) {
|
|
313
258
|
// stringMap is not required if the data is preformatted
|
|
314
259
|
stringMap = {
|
|
@@ -317,181 +262,157 @@ function formatData(dataset, props, expectedKeys) {
|
|
|
317
262
|
y0: expectedKeys.indexOf("y0") !== -1 ? createStringMap(props, "y") : undefined
|
|
318
263
|
};
|
|
319
264
|
}
|
|
320
|
-
|
|
321
|
-
var data = preformattedData ? dataset : dataset.reduce(function (dataArr, datum, index) {
|
|
265
|
+
const data = preformattedData ? dataset : dataset.reduce((dataArr, datum, index) => {
|
|
322
266
|
// eslint-disable-line complexity
|
|
323
|
-
|
|
324
|
-
|
|
267
|
+
const parsedDatum = parseDatum(datum);
|
|
268
|
+
const fallbackValues = {
|
|
325
269
|
x: index,
|
|
326
270
|
y: parsedDatum
|
|
327
271
|
};
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
272
|
+
const processedValues = expectedKeys.reduce((memo, type) => {
|
|
273
|
+
const processedValue = accessor[type](parsedDatum);
|
|
274
|
+
const value = processedValue !== undefined ? processedValue : fallbackValues[type];
|
|
332
275
|
if (value !== undefined) {
|
|
333
276
|
if (typeof value === "string" && stringMap[type]) {
|
|
334
|
-
memo[
|
|
335
|
-
memo[
|
|
277
|
+
memo[`${type}Name`] = value;
|
|
278
|
+
memo[`_${type}`] = stringMap[type][value];
|
|
336
279
|
} else {
|
|
337
|
-
memo[
|
|
280
|
+
memo[`_${type}`] = value;
|
|
338
281
|
}
|
|
339
282
|
}
|
|
340
|
-
|
|
341
283
|
return memo;
|
|
342
284
|
}, {});
|
|
343
|
-
|
|
344
|
-
|
|
285
|
+
const formattedDatum = Object.assign({}, processedValues, parsedDatum);
|
|
345
286
|
if (!(0, _isEmpty2.default)(formattedDatum)) {
|
|
346
287
|
dataArr.push(formattedDatum);
|
|
347
288
|
}
|
|
348
|
-
|
|
349
289
|
return dataArr;
|
|
350
290
|
}, []);
|
|
351
|
-
|
|
352
|
-
|
|
291
|
+
const sortedData = sortData(data, props.sortKey, props.sortOrder);
|
|
292
|
+
const cleanedData = cleanData(sortedData, props);
|
|
353
293
|
return addEventKeys(props, cleanedData);
|
|
354
294
|
}
|
|
295
|
+
|
|
355
296
|
/**
|
|
356
297
|
* Returns generated x and y data based on domain and sample from props
|
|
357
298
|
* @param {Object} props: the props object
|
|
358
299
|
* @returns {Array} an array of data
|
|
359
300
|
*/
|
|
360
|
-
|
|
361
|
-
|
|
362
301
|
function generateData(props) {
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
302
|
+
const xValues = generateDataArray(props, "x");
|
|
303
|
+
const yValues = generateDataArray(props, "y");
|
|
304
|
+
const values = xValues.map((x, i) => {
|
|
366
305
|
return {
|
|
367
|
-
x
|
|
306
|
+
x,
|
|
368
307
|
y: yValues[i]
|
|
369
308
|
};
|
|
370
309
|
});
|
|
371
310
|
return values;
|
|
372
311
|
}
|
|
312
|
+
|
|
373
313
|
/**
|
|
374
314
|
* Returns an array of categories for a given axis
|
|
375
315
|
* @param {Object} props: the props object
|
|
376
316
|
* @param {String} axis: the current axis
|
|
377
317
|
* @returns {Array} an array of categories
|
|
378
318
|
*/
|
|
379
|
-
|
|
380
|
-
|
|
381
319
|
function getCategories(props, axis) {
|
|
382
320
|
return props.categories && !Array.isArray(props.categories) ? props.categories[axis] : props.categories;
|
|
383
321
|
}
|
|
322
|
+
|
|
384
323
|
/**
|
|
385
324
|
* Returns an array of formatted data
|
|
386
325
|
* @param {Object} props: the props object
|
|
387
326
|
* @returns {Array} an array of data
|
|
388
327
|
*/
|
|
389
|
-
|
|
390
|
-
|
|
391
328
|
function getData(props) {
|
|
392
329
|
return props.data ? formatData(props.data, props) : formatData(generateData(props), props);
|
|
393
330
|
}
|
|
331
|
+
|
|
394
332
|
/**
|
|
395
333
|
* Returns an array of strings from axis tickValues for a given axis
|
|
396
334
|
* @param {Object} props: the props object
|
|
397
335
|
* @param {String} axis: the current axis
|
|
398
336
|
* @returns {Array} an array of strings
|
|
399
337
|
*/
|
|
400
|
-
|
|
401
|
-
|
|
402
338
|
function getStringsFromAxes(props, axis) {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
339
|
+
const {
|
|
340
|
+
tickValues,
|
|
341
|
+
tickFormat
|
|
342
|
+
} = props;
|
|
343
|
+
let tickValueArray;
|
|
407
344
|
if (!tickValues || !Array.isArray(tickValues) && !tickValues[axis]) {
|
|
408
345
|
tickValueArray = tickFormat && Array.isArray(tickFormat) ? tickFormat : [];
|
|
409
346
|
} else {
|
|
410
347
|
tickValueArray = tickValues[axis] || tickValues;
|
|
411
348
|
}
|
|
412
|
-
|
|
413
|
-
return tickValueArray.filter(function (val) {
|
|
414
|
-
return typeof val === "string";
|
|
415
|
-
});
|
|
349
|
+
return tickValueArray.filter(val => typeof val === "string");
|
|
416
350
|
}
|
|
351
|
+
|
|
417
352
|
/**
|
|
418
353
|
* Returns an array of strings from categories for a given axis
|
|
419
354
|
* @param {Object} props: the props object
|
|
420
355
|
* @param {String} axis: the current axis
|
|
421
356
|
* @returns {Array} an array of strings
|
|
422
357
|
*/
|
|
423
|
-
|
|
424
|
-
|
|
425
358
|
function getStringsFromCategories(props, axis) {
|
|
426
359
|
if (!props.categories) {
|
|
427
360
|
return [];
|
|
428
361
|
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
var categoryStrings = categories && categories.filter(function (val) {
|
|
432
|
-
return typeof val === "string";
|
|
433
|
-
});
|
|
362
|
+
const categories = getCategories(props, axis);
|
|
363
|
+
const categoryStrings = categories && categories.filter(val => typeof val === "string");
|
|
434
364
|
return categoryStrings ? Collection.removeUndefined(categoryStrings) : [];
|
|
435
365
|
}
|
|
366
|
+
|
|
436
367
|
/**
|
|
437
368
|
* Returns an array of strings from data
|
|
438
369
|
* @param {Object} props: the props object
|
|
439
370
|
* @param {String} axis: the current axis
|
|
440
371
|
* @returns {Array} an array of strings
|
|
441
372
|
*/
|
|
442
|
-
|
|
443
|
-
|
|
444
373
|
function getStringsFromData(props, axis) {
|
|
445
|
-
|
|
446
|
-
|
|
374
|
+
const isArrayOrIterable = Array.isArray(props.data) || Immutable.isIterable(props.data);
|
|
447
375
|
if (!isArrayOrIterable) {
|
|
448
376
|
return [];
|
|
449
377
|
}
|
|
378
|
+
const key = props[axis] === undefined ? axis : props[axis];
|
|
379
|
+
const accessor = Helpers.createAccessor(key);
|
|
450
380
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
var data = props.data.reduce(function (memo, d) {
|
|
381
|
+
// support immutable data
|
|
382
|
+
const data = props.data.reduce((memo, d) => {
|
|
455
383
|
memo.push(parseDatum(d));
|
|
456
384
|
return memo;
|
|
457
385
|
}, []);
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
386
|
+
const sortedData = sortData(data, props.sortKey, props.sortOrder);
|
|
387
|
+
const dataStrings = sortedData.reduce((dataArr, datum) => {
|
|
388
|
+
const parsedDatum = parseDatum(datum);
|
|
461
389
|
dataArr.push(accessor(parsedDatum));
|
|
462
390
|
return dataArr;
|
|
463
|
-
}, []).filter(
|
|
464
|
-
return typeof datum === "string";
|
|
465
|
-
}); // return a unique set of strings
|
|
391
|
+
}, []).filter(datum => typeof datum === "string");
|
|
466
392
|
|
|
467
|
-
return
|
|
393
|
+
// return a unique set of strings
|
|
394
|
+
return dataStrings.reduce((prev, curr) => {
|
|
468
395
|
if (curr !== undefined && curr !== null && prev.indexOf(curr) === -1) {
|
|
469
396
|
prev.push(curr);
|
|
470
397
|
}
|
|
471
|
-
|
|
472
398
|
return prev;
|
|
473
399
|
}, []);
|
|
474
400
|
}
|
|
401
|
+
|
|
475
402
|
/**
|
|
476
403
|
* Checks whether a given component can be used to calculate data
|
|
477
404
|
* @param {Component} component: a React component instance
|
|
478
405
|
* @returns {Boolean} Returns true if the given component has a role included in the whitelist
|
|
479
406
|
*/
|
|
480
|
-
|
|
481
|
-
|
|
482
407
|
function isDataComponent(component) {
|
|
483
|
-
|
|
408
|
+
const getRole = child => {
|
|
484
409
|
return child && child.type ? child.type.role : "";
|
|
485
410
|
};
|
|
486
|
-
|
|
487
|
-
var role = getRole(component);
|
|
488
|
-
|
|
411
|
+
let role = getRole(component);
|
|
489
412
|
if (role === "portal") {
|
|
490
|
-
|
|
491
|
-
|
|
413
|
+
const children = _react.default.Children.toArray(component.props.children);
|
|
492
414
|
role = children.length ? getRole(children[0]) : "";
|
|
493
415
|
}
|
|
494
|
-
|
|
495
|
-
var whitelist = ["area", "bar", "boxplot", "candlestick", "errorbar", "group", "histogram", "line", "pie", "scatter", "stack", "voronoi"];
|
|
416
|
+
const whitelist = ["area", "bar", "boxplot", "candlestick", "errorbar", "group", "histogram", "line", "pie", "scatter", "stack", "voronoi"];
|
|
496
417
|
return whitelist.includes(role);
|
|
497
418
|
}
|