@netdata/charts
Version:
Netdata frontend SDK and chart utilities
175 lines • 6.84 kB
JavaScript
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 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 { useTheme } from "styled-components";
import { TextBig, TextSmall, Flex, ProgressBar, getColor } from "@netdata/netdata-ui";
import Color, { Color as ColorContainer } from "../dimensions/color";
import Name, { Name as NameContainer } from "../dimensions/name";
import Value, { Value as ValueContainer } from "../dimensions/value";
import { tooltipStyleProps } from "../../tooltip";
import Units from "../dimensions/units";
import { useVisibleDimensionId, useChart, useLatestValue, useUnitSign, useIsMinimal } from "../../provider";
import Tooltip from "../../tooltip";
import { useIsHeatmap } from "../../../helpers/heatmap";
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
var DimensionContainer = function DimensionContainer(props) {
return /*#__PURE__*/_jsx(Flex, _objectSpread({
width: {
min: 22,
max: 50
},
flex: false,
gap: 0.5,
"data-testid": "chartLegendDimension"
}, props));
};
export var SkeletonDimension = function SkeletonDimension() {
var theme = useTheme();
var isMinimal = useIsMinimal();
return /*#__PURE__*/_jsxs(DimensionContainer, {
children: [/*#__PURE__*/_jsx(ColorContainer, {
bg: getColor("placeholder")({
theme: theme
})
}), !isMinimal && /*#__PURE__*/_jsxs(Flex, {
flex: true,
gap: 1,
column: true,
overflow: "hidden",
"data-testid": "chartLegendDimension-details",
children: [/*#__PURE__*/_jsx(Flex, {
height: "10px",
width: "76px",
background: "borderSecondary",
round: true
}), /*#__PURE__*/_jsx(Flex, {
height: "10px",
width: "34px",
background: "borderSecondary",
round: true,
"data-testid": "chartLegendDimension-valueContainer"
})]
})]
});
};
export var EmptyDimension = function EmptyDimension() {
var theme = useTheme();
var isMinimal = useIsMinimal();
return /*#__PURE__*/_jsxs(DimensionContainer, {
children: [/*#__PURE__*/_jsx(ColorContainer, {
bg: getColor("placeholder")({
theme: theme
})
}), !isMinimal && /*#__PURE__*/_jsxs(Flex, {
flex: true,
gap: 0.5,
column: true,
overflow: "hidden",
"data-testid": "chartLegendDimension-details",
children: [/*#__PURE__*/_jsx(NameContainer, {
children: "No data"
}), /*#__PURE__*/_jsx(ValueContainer, {
children: "-"
})]
})]
});
};
var AnomalyProgressBar = function AnomalyProgressBar(_ref) {
var id = _ref.id;
var value = useLatestValue(id, {
valueKey: "arp"
});
return /*#__PURE__*/_jsx(ProgressBar, {
height: 0.5,
color: "anomalyText",
width: "".concat(Math.abs(value), "%")
});
};
var TooltipContent = function TooltipContent(props) {
return /*#__PURE__*/_jsx(Flex, _objectSpread(_objectSpread(_objectSpread({}, tooltipStyleProps), props), {}, {
column: true,
gap: 1
}));
};
var TooltipValue = function TooltipValue(_ref2) {
var id = _ref2.id,
name = _ref2.name;
var units = useUnitSign({
"long": true,
dimensionId: id,
withoutConversion: true
});
var value = useLatestValue(id);
return /*#__PURE__*/_jsxs(_Fragment, {
children: [/*#__PURE__*/_jsx(TextSmall, {
strong: true,
wordBreak: "break-word",
children: name
}), /*#__PURE__*/_jsxs(TextSmall, {
whiteSpace: "nowrap",
children: [value, " ", units]
})]
});
};
var Dimension = function Dimension(_ref3) {
var id = _ref3.id,
ref = _ref3.ref;
var visible = useVisibleDimensionId(id);
var chart = useChart();
var name = chart.getDimensionName(id);
var onClick = function onClick(e) {
var merge = e.shiftKey || e.ctrlKey || e.metaKey;
chart.toggleDimensionId(id, {
merge: merge
});
};
var isHeatmap = useIsHeatmap();
var isMinimal = useIsMinimal();
return /*#__PURE__*/_jsxs(DimensionContainer, {
ref: ref,
opacity: visible ? null : "weak",
cursor: "pointer",
onClick: onClick,
"data-track": chart.track("dimension-".concat(name)),
children: [!isHeatmap && /*#__PURE__*/_jsx(Color, {
id: id
}), /*#__PURE__*/_jsx(Tooltip, {
Content: TooltipContent,
content: visible ? /*#__PURE__*/_jsx(TooltipValue, {
id: id,
name: name
}) : null,
children: /*#__PURE__*/_jsxs(Flex, {
flex: true,
column: true,
overflow: "hidden",
"data-testid": "chartLegendDimension-details",
children: [/*#__PURE__*/_jsx(Name, {
id: id,
noTooltip: true
}), !isMinimal && /*#__PURE__*/_jsx(AnomalyProgressBar, {
id: id
}), !isMinimal && /*#__PURE__*/_jsxs(Flex, {
gap: 1,
alignItems: "end",
"data-testid": "chartLegendDimension-valueContainer",
flex: true,
children: [/*#__PURE__*/_jsx(Value, {
id: id,
strong: true,
visible: visible,
Component: TextBig
}), /*#__PURE__*/_jsx(Units, {
visible: visible,
dimensionId: id
})]
})]
})
})]
});
};
export default Dimension;