UNPKG

@netdata/charts

Version:

Netdata frontend SDK and chart utilities

165 lines 8.59 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); } var _excluded = ["children", "fractionDigits"], _excluded2 = ["children"]; 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 _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _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 _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } 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(r) { if (Array.isArray(r)) return r; } 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; } import React from "react"; import styled from "styled-components"; import { Flex } from "@netdata/netdata-ui"; import Color, { ColorBar } from "../line/dimensions/color"; import Name from "../line/dimensions/name"; import Value, { Value as ValuePart } from "../line/dimensions/value"; import { useChart, useVisibleDimensionId } from "../provider"; import { labels as annotationLabels } from "../../helpers/annotations"; import Tooltip from "../tooltip"; import { rowFlavours } from "./dimensions"; import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; var GridRow = styled(Flex).attrs({ position: "relative", "data-testid": "chartPopover-dimension", padding: [1, 0] }).withConfig({ displayName: "dimension__GridRow", componentId: "sc-wluvip-0" })(["display:contents;"]); var ColorBackground = styled(ColorBar).attrs({ position: "absolute", top: 0, left: 0, backgroundOpacity: 0.4, round: 0.5 }).withConfig({ displayName: "dimension__ColorBackground", componentId: "sc-wluvip-1" })([""]); var rowValueKeys = { ANOMALY_RATE: "arp", "default": "value" }; var ValueOnDot = function ValueOnDot(_ref) { var children = _ref.children, _ref$fractionDigits = _ref.fractionDigits, fractionDigits = _ref$fractionDigits === void 0 ? 0 : _ref$fractionDigits, rest = _objectWithoutProperties(_ref, _excluded); var _children$toString$sp = children.toString().split("."), _children$toString$sp2 = _slicedToArray(_children$toString$sp, 2), first = _children$toString$sp2[0], last = _children$toString$sp2[1]; return /*#__PURE__*/_jsxs(Flex, { alignItems: "center", justifyContent: "end", padding: [0, 0.5], children: [/*#__PURE__*/_jsx(ValuePart, _objectSpread(_objectSpread({}, rest), {}, { textAlign: "right", children: first })), typeof last !== "undefined" && /*#__PURE__*/_jsx(ValuePart, _objectSpread(_objectSpread({}, rest), {}, { children: "." })), /*#__PURE__*/_jsx(ValuePart, _objectSpread(_objectSpread({ as: Flex, flex: false, width: fractionDigits * 1.8 }, rest), {}, { textAlign: "left", children: last }))] }); }; var AnnotationsValue = function AnnotationsValue(_ref2) { var annotations = _ref2.children, rest = _objectWithoutProperties(_ref2, _excluded2); return /*#__PURE__*/_jsx(Flex, { gap: 1, justifyContent: "end", children: Object.keys(annotations).map(function (ann) { return /*#__PURE__*/_jsx(Flex, { border: { size: "1px", side: "all", color: annotations[ann] }, round: true, flex: false, padding: [0, 0.5], children: /*#__PURE__*/_jsx(Tooltip, { content: annotationLabels[ann] || ann, children: /*#__PURE__*/_jsx(ValuePart, _objectSpread(_objectSpread({}, rest), {}, { color: annotations[ann], children: ann })) }) }, ann); }) }); }; var Dimension = function Dimension(_ref3) { var id = _ref3.id, strong = _ref3.strong, rowFlavour = _ref3.rowFlavour, fullCols = _ref3.fullCols; var visible = useVisibleDimensionId(id); var chart = useChart(); var fractionDigits = chart.getAttribute("unitsConversionFractionDigits"); return /*#__PURE__*/_jsxs(GridRow, { opacity: visible ? null : "weak", children: [/*#__PURE__*/_jsxs(Flex, { alignItems: "center", gap: 1, position: "relative", overflow: "hidden", children: [/*#__PURE__*/_jsx(ColorBackground, { id: id, valueKey: rowValueKeys[rowFlavour] || rowValueKeys["default"], height: "100%", children: /*#__PURE__*/_jsx(Color, { id: id }) }), /*#__PURE__*/_jsx(Name, { padding: [0.5, 1.5], flex: true, id: id, strong: strong, fontSize: "1.1em" })] }), /*#__PURE__*/_jsx(Value, { id: id, strong: strong, visible: visible, Component: ValueOnDot, fractionDigits: fractionDigits, color: rowFlavour === rowFlavours["default"] ? "text" : "textLite", fontSize: "1.1em" }), fullCols && /*#__PURE__*/_jsxs(_Fragment, { children: [/*#__PURE__*/_jsx(Value, { id: id, strong: strong, visible: visible, valueKey: "arp", Component: ValueOnDot, fractionDigits: 2, color: rowFlavour === rowFlavours.ANOMALY_RATE ? "anomalyTextFocus" : "anomalyText", fontSize: "1.1em" }), /*#__PURE__*/_jsx(Value, { textAlign: "right", id: id, strong: strong, visible: visible, valueKey: "pa", Component: AnnotationsValue, color: rowFlavour === rowFlavours.ANNOTATIONS ? "text" : "textLite", fontSize: "1.1em" })] })] }); }; export default Dimension;