UNPKG

@netdata/charts

Version:

Netdata frontend SDK and chart utilities

64 lines (63 loc) 4.47 kB
"use strict"; 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); } Object.defineProperty(exports, "__esModule", { value: true }); exports.getStats = void 0; var _excluded = ["getValue", "getLabel", "getIsSelected"]; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; } function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; } var getValueOrZero = function getValueOrZero(obj, attr) { return obj ? (obj === null || obj === void 0 ? void 0 : obj[attr]) || 0 : 0; }; var getMetricsCount = function getMetricsCount(obj) { if (!obj) return "-"; return getValueOrZero(obj, "qr") + getValueOrZero(obj, "qr") / (getValueOrZero(obj, "ex") + getValueOrZero(obj, "sl")); }; var getAlertsCount = function getAlertsCount(obj) { if (!obj) return "-"; return getValueOrZero(obj, "cr") * 3 + getValueOrZero(obj, "wr") * 2 + getValueOrZero(obj, "cl"); }; var _getStats = exports.getStats = function getStats(chart, obj) { var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, id = _ref.id, key = _ref.key, childrenKey = _ref.childrenKey, _ref$children = _ref.children, children = _ref$children === void 0 ? [] : _ref$children, childProps = _ref.childProps, props = _ref.props; var getValue = props.getValue, getLabel = props.getLabel, getIsSelected = props.getIsSelected, rest = _objectWithoutProperties(props, _excluded); return _objectSpread(_objectSpread({ label: (getLabel === null || getLabel === void 0 ? void 0 : getLabel(obj)) || obj.nm || id || obj.id, value: (getValue === null || getValue === void 0 ? void 0 : getValue(obj)) || id || obj.id, "data-track": chart.track("".concat(key, "-").concat(id || obj.id || obj.nm)), unique: children.length, instances: getMetricsCount(obj.is), metrics: getMetricsCount(obj.ds), contribution: getValueOrZero(obj.sts, "con"), anomalyRate: getValueOrZero(obj.sts, "arp"), min: getValueOrZero(obj.sts, "min"), avg: getValueOrZero(obj.sts, "avg"), max: getValueOrZero(obj.sts, "max"), range: getValueOrZero(obj.sts, "max") - getValueOrZero(obj.sts, "min"), alerts: getAlertsCount(obj.al), info: obj, selected: (getIsSelected === null || getIsSelected === void 0 ? void 0 : getIsSelected(obj)) || false }, rest), {}, { children: children.map(function (dim) { return _getStats(chart, dim, { key: "".concat(key, "-").concat(childrenKey), props: childProps }); }) }); };