@netdata/charts
Version:
Netdata frontend SDK and chart utilities
185 lines • 7.79 kB
JavaScript
var _excluded = ["id", "visible", "children"],
_excluded2 = ["children", "showFull"];
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 _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; }
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); }
import React from "react";
import styled from "styled-components";
import { Flex } from "@netdata/netdata-ui";
import Color, { ColorBar } from "../dimensions/color";
import Name from "../dimensions/name";
import Units from "../dimensions/units";
import Value, { Value as ValuePart } from "../dimensions/value";
import { useLatestValue, useValueUnitAttributes, useVisibleDimensionId } from "../../provider";
import { labels as annotationLabels } from "../../../helpers/annotations";
import { useIsHeatmap } from "../../../helpers/heatmap";
import { rowFlavours } from "./dimensions";
import { popoverGridColumns } from "./layout";
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
var GridRow = styled(Flex).attrs({
position: "relative",
"data-testid": "chartPopover-dimension",
padding: [1, 0]
}).withConfig({
displayName: "dimension__GridRow",
componentId: "sc-adzl1v-0"
})(["display:contents;"]);
var ColorBackground = styled(ColorBar).attrs({
position: "absolute",
top: 1,
left: 0,
backgroundOpacity: 0.4,
round: 0.5
}).withConfig({
displayName: "dimension__ColorBackground",
componentId: "sc-adzl1v-1"
})([""]);
var DimensionNameCell = styled(Flex).attrs({
"data-testid": "chartPopover-dimensionNameCell",
alignItems: "center",
gap: 1,
position: "relative",
overflow: "hidden",
width: {
min: 0
}
}).withConfig({
displayName: "dimension__DimensionNameCell",
componentId: "sc-adzl1v-2"
})(["min-width:", ";[data-testid=\"chartDimensions-name\"]{min-width:0;max-width:100%;}"], popoverGridColumns.dimensionMin);
var rowValueKeys = {
ANOMALY_RATE: "arp",
"default": "value"
};
var PlainValue = function PlainValue(props) {
return /*#__PURE__*/_jsx(ValuePart, _objectSpread(_objectSpread({}, props), {}, {
textAlign: "right",
whiteSpace: "nowrap"
}));
};
var UnitCell = styled(Flex).attrs({
"data-testid": "chartPopover-dimensionUnitCell",
alignItems: "center",
overflow: "hidden",
width: {
min: 0
},
padding: [0, 0, 0, 2]
}).withConfig({
displayName: "dimension__UnitCell",
componentId: "sc-adzl1v-3"
})(["box-sizing:border-box;"]);
var ValueWithUnits = function ValueWithUnits(_ref) {
var id = _ref.id,
visible = _ref.visible,
children = _ref.children,
rest = _objectWithoutProperties(_ref, _excluded);
var isHeatmap = useIsHeatmap();
var value = useLatestValue(id, {
allowNull: true
});
var unitAttributes = useValueUnitAttributes(value, {
dimensionId: id,
scaleByValue: true
});
return /*#__PURE__*/_jsxs(_Fragment, {
children: [/*#__PURE__*/_jsx(PlainValue, _objectSpread(_objectSpread({}, rest), {}, {
children: children
})), /*#__PURE__*/_jsx(UnitCell, {
children: !isHeatmap && /*#__PURE__*/_jsx(Units, {
visible: visible,
dimensionId: id,
value: value,
unitAttributes: unitAttributes,
scaleByValue: true
})
})]
});
};
var AnnotationsValue = function AnnotationsValue(_ref2) {
var annotations = _ref2.children,
showFull = _ref2.showFull,
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(ValuePart, _objectSpread(_objectSpread({}, rest), {}, {
color: annotations[ann],
children: showFull ? annotationLabels[ann] || ann : ann
}))
}, ann);
})
});
};
var Dimension = function Dimension(_ref3) {
var id = _ref3.id,
strong = _ref3.strong,
rowFlavour = _ref3.rowFlavour;
var visible = useVisibleDimensionId(id);
var isHeatmap = useIsHeatmap();
return /*#__PURE__*/_jsxs(GridRow, {
opacity: visible ? null : "weak",
children: [/*#__PURE__*/_jsxs(DimensionNameCell, {
children: [/*#__PURE__*/_jsx(ColorBackground, {
id: id,
valueKey: rowValueKeys[rowFlavour] || rowValueKeys["default"],
height: "18px",
children: !isHeatmap && /*#__PURE__*/_jsx(Color, {
id: id
})
}), /*#__PURE__*/_jsx(Name, {
padding: [1, 2],
flex: true,
id: id,
strong: strong,
noTooltip: true,
color: strong ? "textFocus" : "text"
})]
}), /*#__PURE__*/_jsx(Value, {
id: id,
strong: strong,
visible: visible,
Component: function Component(props) {
return /*#__PURE__*/_jsx(ValueWithUnits, _objectSpread({
id: id,
visible: visible
}, props));
},
scaleByValue: true,
color: rowFlavour === rowFlavours["default"] ? strong ? "textFocus" : "text" : "textLite"
}), /*#__PURE__*/_jsx(Value, {
id: id,
strong: strong,
visible: visible,
valueKey: "arp",
Component: PlainValue,
fractionDigits: 2,
color: rowFlavour === rowFlavours.ANOMALY_RATE ? "anomalyTextFocus" : "anomalyText"
}), /*#__PURE__*/_jsx(Value, {
textAlign: "right",
id: id,
strong: strong,
visible: visible,
valueKey: "pa",
Component: AnnotationsValue,
color: rowFlavour === rowFlavours.ANNOTATIONS ? strong ? "textFocus" : "text" : "textLite",
showFull: rowFlavour === rowFlavours.ANNOTATIONS
})]
});
};
export default Dimension;