@netdata/charts
Version:
Netdata frontend SDK and chart utilities
84 lines (83 loc) • 5.72 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); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _netdataUi = require("@netdata/netdata-ui");
var _provider = require("../../provider");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, 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; }
var ValueRange = function ValueRange() {
var _staticValueRange$, _staticValueRange$2;
var chart = (0, _provider.useChart)();
var staticValueRange = (0, _provider.useAttributeValue)("staticValueRange");
var _useState = (0, _react.useState)((_staticValueRange$ = staticValueRange === null || staticValueRange === void 0 ? void 0 : staticValueRange[0]) !== null && _staticValueRange$ !== void 0 ? _staticValueRange$ : ""),
_useState2 = _slicedToArray(_useState, 2),
minValue = _useState2[0],
setMinValue = _useState2[1];
var _useState3 = (0, _react.useState)((_staticValueRange$2 = staticValueRange === null || staticValueRange === void 0 ? void 0 : staticValueRange[1]) !== null && _staticValueRange$2 !== void 0 ? _staticValueRange$2 : ""),
_useState4 = _slicedToArray(_useState3, 2),
maxValue = _useState4[0],
setMaxValue = _useState4[1];
var units = (0, _provider.useUnitSign)({
withoutConversion: true
});
(0, _react.useEffect)(function () {
var _staticValueRange$3, _staticValueRange$4;
setMinValue((_staticValueRange$3 = staticValueRange === null || staticValueRange === void 0 ? void 0 : staticValueRange[0]) !== null && _staticValueRange$3 !== void 0 ? _staticValueRange$3 : "");
setMaxValue((_staticValueRange$4 = staticValueRange === null || staticValueRange === void 0 ? void 0 : staticValueRange[1]) !== null && _staticValueRange$4 !== void 0 ? _staticValueRange$4 : "");
}, [staticValueRange]);
var commit = function commit(rawMin, rawMax) {
var min = rawMin === "" ? null : Number(rawMin);
var max = rawMax === "" ? null : Number(rawMax);
var next = min === null && max === null ? null : [min, max];
chart.updateAttributes({
staticValueRange: next
});
chart.trigger("yAxisChange");
};
var handleMinChange = function handleMinChange(e) {
var value = e.target.value;
setMinValue(value);
commit(value, maxValue);
};
var handleMaxChange = function handleMaxChange(e) {
var value = e.target.value;
setMaxValue(value);
commit(minValue, value);
};
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_netdataUi.Flex, {
column: true,
gap: 2,
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_netdataUi.TextSmall, {
color: "textNoFocus",
strong: true,
children: "Value range"
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_netdataUi.Flex, {
column: true,
gap: 1,
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_netdataUi.TextInput, {
label: "Min value (".concat(units || "units", ")"),
type: "number",
value: minValue,
onChange: handleMinChange,
placeholder: "Auto"
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_netdataUi.TextInput, {
label: "Max value (".concat(units || "units", ")"),
type: "number",
value: maxValue,
onChange: handleMaxChange,
placeholder: "Auto"
})]
})]
});
};
var _default = exports["default"] = ValueRange;