UNPKG

@lobehub/charts

Version:

React modern charts components built on recharts

85 lines 5.81 kB
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } 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."); } function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; } 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); } 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; } export var constructCategoryColors = function constructCategoryColors(categories, colors) { var categoryColors = new Map(); var _iterator = _createForOfIteratorHelper(categories.entries()), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { var _step$value = _slicedToArray(_step.value, 2), idx = _step$value[0], category = _step$value[1]; categoryColors.set(category, colors[idx % colors.length]); } } catch (err) { _iterator.e(err); } finally { _iterator.f(); } return categoryColors; }; export var getYAxisDomain = function getYAxisDomain(autoMinValue, minValue, maxValue) { return [autoMinValue ? 'auto' : minValue !== null && minValue !== void 0 ? minValue : 0, maxValue !== null && maxValue !== void 0 ? maxValue : 'auto']; }; export var constructCategories = function constructCategories(data, color) { if (!color) { return []; } var categories = new Set(); var _iterator2 = _createForOfIteratorHelper(data), _step2; try { for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { var datum = _step2.value; categories.add(datum[color]); } } catch (err) { _iterator2.e(err); } finally { _iterator2.f(); } return _toConsumableArray(categories); }; export var deepEqual = function deepEqual(obj1, obj2) { if (obj1 === obj2) return true; if (_typeof(obj1) !== 'object' || _typeof(obj2) !== 'object' || obj1 === null || obj2 === null) return false; var keys1 = Object.keys(obj1); var keys2 = Object.keys(obj2); if (keys1.length !== keys2.length) return false; for (var _i = 0, _keys = keys1; _i < _keys.length; _i++) { var key = _keys[_i]; if (!keys2.includes(key) || !deepEqual(obj1[key], obj2[key])) return false; } return true; }; export var hasOnlyOneValueForThisKey = function hasOnlyOneValueForThisKey(array, keyToCheck) { var val = []; var _iterator3 = _createForOfIteratorHelper(array), _step3; try { for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { var obj = _step3.value; if (Object.prototype.hasOwnProperty.call(obj, keyToCheck)) { val.push(obj[keyToCheck]); if (val.length > 1) { return false; } } } } catch (err) { _iterator3.e(err); } finally { _iterator3.f(); } return true; };