@netdata/charts
Version:
Netdata frontend SDK and chart utilities
237 lines • 10.1 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); }
var _excluded = ["size"],
_excluded2 = ["children", "customChildren", "hasFilters"],
_excluded3 = ["count", "tile", "height", "width", "children", "hasFilters"];
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; }
import React from "react";
import styled from "styled-components";
import { Box, Flex, Text } from "@netdata/netdata-ui";
import anomalyBadge from "@netdata/netdata-ui/dist/components/icon/assets/anomaly_badge.svg";
import useDebouncedValue from "@netdata/netdata-ui/dist/hooks/useDebouncedValue";
import Icon from "../icon";
import useHover from "../useHover";
import Toolbox from "../toolbox";
import { useChart, useAttributeValue, useTitle, useOnResize, useDimensionIds, useColor, useLatestValue } from "../provider";
import FilterToolbox from "../filterToolbox";
import { ColorBar } from "../line/dimensions/color";
import Tooltip from "../tooltip";
import Details from "../details";
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
var Label = styled(Text).withConfig({
displayName: "withTile__Label",
componentId: "sc-1oake2r-0"
})(["line-height:1;font-size:", ";"], function (_ref) {
var fontSize = _ref.fontSize;
return fontSize;
});
var ChartHeadWrapper = styled(Flex).attrs(function (_ref2) {
var size = _ref2.size,
rest = _objectWithoutProperties(_ref2, _excluded);
return _objectSpread({
background: "panelBg",
round: true,
fontSize: parseInt(size / 3, 10),
height: "100%",
width: "100%",
position: "relative"
}, rest);
}).withConfig({
displayName: "withTile__ChartHeadWrapper",
componentId: "sc-1oake2r-1"
})(["font-size:", "px;"], function (props) {
return props.fontSize > 11 ? 11 : props.fontSize < 8 ? 8 : props.fontSize;
});
export var Title = function Title() {
var chart = useChart();
var title = useTitle();
var onClick = function onClick(event) {
event.preventDefault();
chart.sdk.trigger("goToLink", chart);
};
return /*#__PURE__*/_jsx(Label, {
fontSize: "1em",
textAlign: "center",
color: "sectionDescription",
width: "80%",
onClick: onClick,
cursor: "pointer",
padding: [2, 0, 0],
children: title
});
};
export var HeadWrapper = function HeadWrapper(_ref3) {
var _useDimensionIds;
var children = _ref3.children,
customChildren = _ref3.customChildren,
_ref3$hasFilters = _ref3.hasFilters,
hasFilters = _ref3$hasFilters === void 0 ? true : _ref3$hasFilters,
rest = _objectWithoutProperties(_ref3, _excluded2);
var _useOnResize = useOnResize(),
width = _useOnResize.width;
var focused = useAttributeValue("focused");
var firstDim = (_useDimensionIds = useDimensionIds()) === null || _useDimensionIds === void 0 ? void 0 : _useDimensionIds[0];
var leftHeaderElements = useAttributeValue("leftHeaderElements");
var size = width;
size = size < 20 ? 20 : size > 50 ? 50 : size;
var chart = useChart();
var hoverRef = useHover({
onHover: chart.focus,
onBlur: chart.blur,
isOut: function isOut(node) {
return !node || !node.closest("[data-toolbox=\"".concat(chart.getId(), "\"]")) && !node.closest("[data-chartid=\"".concat(chart.getId(), "\"]"));
}
}, [chart]);
var hasToolbox = useAttributeValue("hasToolbox");
var showAnomalies = useAttributeValue("showAnomalies");
var shadowColor = useColor("themeShadow");
var debouncedFocused = useDebouncedValue(focused, 400);
var value = useLatestValue("selected", {
valueKey: "arp"
}) || 0;
return /*#__PURE__*/_jsxs(ChartHeadWrapper, _objectSpread(_objectSpread({
size: size
}, rest), {}, {
ref: hoverRef,
children: [hasToolbox && focused && debouncedFocused && /*#__PURE__*/_jsx(Toolbox, {
position: "absolute",
top: "-14px",
right: "0",
background: "mainChartHeaderBg",
width: {
min: "100%"
},
padding: [1],
sx: {
boxShadow: "0px 1px 5px 0px ".concat(shadowColor, ";")
},
overflow: "hidden",
children: hasFilters && width > 400 && /*#__PURE__*/_jsx(Box, {
width: "100%",
children: /*#__PURE__*/_jsx(FilterToolbox, {
border: "none",
opacity: focused ? 1 : 0.1,
focused: focused
})
})
}), /*#__PURE__*/_jsxs(Flex, {
column: true,
width: 5,
padding: [1, 0],
children: [leftHeaderElements.map(function (Element, index) {
return /*#__PURE__*/_jsx(Element, {
plain: true
}, index);
}), width < 400 && /*#__PURE__*/_jsx(Flex, {
column: true,
width: 5,
children: /*#__PURE__*/_jsx(FilterToolbox, {
column: true,
border: "none",
justifyContent: "start",
plain: true,
opacity: focused ? 1 : 0.1,
focused: focused
})
})]
}), /*#__PURE__*/_jsxs(Flex, {
column: true,
alignItems: "center",
justifyContent: "center",
padding: [1, 0],
height: "100%",
width: "100%",
position: "relative",
overflow: "hidden",
children: [/*#__PURE__*/_jsx(Title, {}), children]
}), /*#__PURE__*/_jsx(Flex, {
column: true,
width: 5,
alignItems: "center",
padding: [4, 0],
gap: 2,
children: showAnomalies && firstDim === "selected" && /*#__PURE__*/_jsxs(_Fragment, {
children: [/*#__PURE__*/_jsx(Flex, {
column: true,
height: "100%",
width: "2px",
background: "neutralHighlight",
justifyContent: "end",
children: /*#__PURE__*/_jsx(ColorBar, {
id: "selected",
valueKey: "arp",
width: "2px",
styleDimension: "height",
round: 0.5
})
}), /*#__PURE__*/_jsx(Tooltip, {
content: "Anomaly rate for this metric",
children: /*#__PURE__*/_jsx(Icon, {
svg: anomalyBadge,
color: !!value && value > 0 ? "anomalyTextLite" : "neutralHighlight",
size: "14px"
})
})]
})
}), customChildren]
}));
};
export var ChartWrapper = styled(Flex).attrs(function (props) {
return _objectSpread({
column: true,
justifyContent: "center",
alignContent: "center",
gap: 2,
position: "relative",
width: "100%",
height: "100%",
overflow: "hidden"
}, props);
}).withConfig({
displayName: "withTile__ChartWrapper",
componentId: "sc-1oake2r-2"
})([""]);
export default (function (Component) {
return function (_ref4) {
var count = _ref4.count,
_ref4$tile = _ref4.tile,
tile = _ref4$tile === void 0 ? true : _ref4$tile,
_ref4$height = _ref4.height,
height = _ref4$height === void 0 ? "100%" : _ref4$height,
_ref4$width = _ref4.width,
width = _ref4$width === void 0 ? "100%" : _ref4$width,
children = _ref4.children,
_ref4$hasFilters = _ref4.hasFilters,
hasFilters = _ref4$hasFilters === void 0 ? true : _ref4$hasFilters,
rest = _objectWithoutProperties(_ref4, _excluded3);
var showingInfo = useAttributeValue("showingInfo");
var focused = useAttributeValue("focused");
var shadowColor = useColor("themeShadow");
var styles = focused ? {
sx: {
boxShadow: "0px 1px 5px 0px ".concat(shadowColor, ";")
}
} : {};
return tile ? /*#__PURE__*/_jsx(HeadWrapper, _objectSpread(_objectSpread({
count: count,
uiName: rest.uiName,
height: height,
width: width,
customChildren: children,
hasFilters: hasFilters
}, styles), {}, {
children: showingInfo ? /*#__PURE__*/_jsx(Details, {}) : /*#__PURE__*/_jsx(Component, _objectSpread({}, rest))
})) : /*#__PURE__*/_jsxs(ChartHeadWrapper, _objectSpread(_objectSpread({
size: 20,
height: height,
width: width
}, styles), {}, {
children: [showingInfo ? /*#__PURE__*/_jsx(Details, {}) : /*#__PURE__*/_jsx(Component, _objectSpread({}, rest)), children]
}));
};
});