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