UNPKG

@netdata/charts

Version:

Netdata frontend SDK and chart utilities

635 lines 27.9 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 = ["key"], _excluded2 = ["chart", "id"], _excluded3 = ["chart", "id"], _excluded4 = ["chart", "id"]; 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; } 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; } import { useCallback, useLayoutEffect, useContext, useMemo, useReducer, useState } from "react"; import { scaleLinear } from "d3-scale"; import { unregister } from "../../helpers/makeListeners"; import { enums, parts, check, colors } from "../../helpers/annotations"; import { calculatePercentile } from "../../helpers/statistics"; import chartTitleByContextMap from "../helpers/chartTitleByContextMap"; import context from "./context"; export var useChart = function useChart() { return useContext(context); }; var dispatch = function dispatch(s) { return s + 1; }; export var useForceUpdate = function useForceUpdate() { var _useReducer = useReducer(dispatch, 0), _useReducer2 = _slicedToArray(_useReducer, 2), forceUpdate = _useReducer2[1]; return forceUpdate; }; export var useImmediateListener = function useImmediateListener(func, deps) { var off = useMemo(func, deps); useLayoutEffect(function () { return off; }, [off]); }; export var useAttributeValue = function useAttributeValue(name, defaultValue) { var chart = useChart(); var forceUpdate = useForceUpdate(); useImmediateListener(function () { return chart.onAttributeChange(name, forceUpdate); }, [chart]); return chart.getAttribute(name, defaultValue); }; export var useFilteredNodeIds = function useFilteredNodeIds() { var chart = useChart(); var forceUpdate = useForceUpdate(); useImmediateListener(function () { chart.onAttributeChange("selectedNodeLabelsFilter", forceUpdate); chart.onAttributeChange("selectedNodes", forceUpdate); }, [chart]); return chart.getFilteredNodeIds(); }; export var useInitialLoading = function useInitialLoading() { var chart = useChart(); var forceUpdate = useForceUpdate(); useImmediateListener(function () { return chart.onAttributeChange("loaded", forceUpdate); }, [chart]); return !chart.getAttribute("loaded"); }; export var useLoadingColor = function useLoadingColor() { var defaultColor = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "themeNeutralBackground"; var chart = useChart(); var _useState = useState(defaultColor), _useState2 = _slicedToArray(_useState, 2), color = _useState2[0], setColor = _useState2[1]; var fetchStartedAt = useAttributeValue("fetchStartedAt"); var loading = useAttributeValue("loading"); useLayoutEffect(function () { if (!loading) { setColor(defaultColor); return; } var getColor = scaleLinear().domain([0, 1000, 2000, 3000, 100000]).range([chart.getThemeAttribute(defaultColor), chart.getThemeAttribute(defaultColor), chart.getThemeAttribute("themeLoadingStart"), chart.getThemeAttribute("themeNetdata"), chart.getThemeAttribute("themeNetdata")]); var id = setInterval(function () { setColor(getColor(Date.now() - fetchStartedAt)); }, 500); return function () { return clearInterval(id); }; }, [loading, fetchStartedAt, chart]); return color; }; export var useColor = function useColor(name) { var chart = useChart(); var forceUpdate = useForceUpdate(); useImmediateListener(function () { return chart.onAttributeChange("theme", forceUpdate); }, [chart]); return chart.getThemeAttribute(name); }; export var useIsFetching = function useIsFetching() { var chart = useChart(); var forceUpdate = useForceUpdate(); useImmediateListener(function () { return chart.onAttributeChange("loading", forceUpdate); }, [chart]); return chart.getAttribute("loading"); }; export var useEmpty = function useEmpty() { var chart = useChart(); var forceUpdate = useForceUpdate(); useImmediateListener(function () { return chart.on("finishFetch", forceUpdate); }, [chart]); var _chart$getPayload = chart.getPayload(), data = _chart$getPayload.data; return data.length === 0; }; export var useAttribute = function useAttribute(name) { var chart = useChart(); var forceUpdate = useForceUpdate(); var getValue = function getValue() { return chart.getAttribute(name); }; useImmediateListener(function () { return chart.onAttributeChange(name, forceUpdate); }, [chart]); var updateValue = useCallback(function (nextValue) { return chart.updateAttribute(name, typeof nextValue === "function" ? nextValue(getValue()) : nextValue); }, [chart]); return [getValue(), updateValue]; }; export var useTitle = function useTitle() { var title = useAttributeValue("title"); var contextScope = useAttributeValue("contextScope"); if (title) return title; var titleByContext = contextScope.length === 1 && chartTitleByContextMap[contextScope[0]]; if (titleByContext) return titleByContext; return title; }; export var useName = function useName() { var name = useAttributeValue("name"); var contextScope = useAttributeValue("contextScope"); return name || (contextScope && contextScope.length ? contextScope.join(", ") : ""); }; export var useVisibleDimensionId = function useVisibleDimensionId(id) { var chart = useChart(); var forceUpdate = useForceUpdate(); useImmediateListener(function () { return unregister(chart.onAttributeChange("selectedDimensions", forceUpdate), chart.on("visibleDimensionsChanged", forceUpdate)); }, [chart]); return chart.isDimensionVisible(id); }; export var usePayload = function usePayload() { var chart = useChart(); var forceUpdate = useForceUpdate(); useImmediateListener(function () { return chart.on("payloadChanged", forceUpdate); }, [chart]); return chart.getPayload(); }; export var useChartError = function useChartError() { var _useState3 = useState(null), _useState4 = _slicedToArray(_useState3, 2), error = _useState4[0], setError = _useState4[1]; var chart = useChart(); var forceUpdate = useForceUpdate(); useImmediateListener(function () { var handleFetch = function handleFetch(errorMessage) { setError(errorMessage); forceUpdate(); }; return chart.on("successFetch", function () { return handleFetch(chart.getAttribute("error")); }).on("failFetch", function () { return handleFetch(chart.getAttribute("error")); }); }, [chart]); return error; }; export var useFormatTime = function useFormatTime(value) { var chart = useChart(); var forceUpdate = useForceUpdate(); useImmediateListener(function () { return chart.onAttributeChange("timezone", forceUpdate); }, [chart]); return useMemo(function () { return chart.formatTime(value); }, [value, chart.getAttribute("timezone")]); }; export var useFormatDate = function useFormatDate(value) { var chart = useChart(); var forceUpdate = useForceUpdate(); useImmediateListener(function () { return chart.onAttributeChange("timezone", forceUpdate); }, [chart]); return useMemo(function () { return chart.formatDate(value); }, [value, chart.getAttribute("timezone")]); }; export var useOnResize = function useOnResize(uiName) { var chart = useChart(); var _useState5 = useState(1), _useState6 = _slicedToArray(_useState5, 2), invalidated = _useState6[0], invalidate = _useState6[1]; var forceUpdate = useForceUpdate(); useImmediateListener(function () { return unregister(chart.on("mountChartUI", function () { setTimeout(function () { invalidate(function (prev) { return prev + 1; }); forceUpdate(); }, 300); }), chart.getUI(uiName).on("rendered", forceUpdate).on("resize", forceUpdate)); }, [uiName, chart, invalidated]); return { width: chart.getUI(uiName).getChartWidth(), height: chart.getUI(uiName).getChartHeight(), parentWidth: chart.getAttribute("containerWidth") }; }; export var useDimensionIds = function useDimensionIds() { var chart = useChart(); var forceUpdate = useForceUpdate(); useImmediateListener(function () { return chart.on("dimensionChanged", forceUpdate); }, [chart]); return chart.getDimensionIds(); }; export var useUnitSign = function useUnitSign() { var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, _ref$key = _ref.key, key = _ref$key === void 0 ? "units" : _ref$key, options = _objectWithoutProperties(_ref, _excluded); var chart = useChart(); var forceUpdate = useForceUpdate(); useImmediateListener(function () { var offListeners = [chart.onAttributeChange("".concat(key, "ConversionPrefix"), forceUpdate), chart.onAttributeChange("".concat(key, "ConversionBase"), forceUpdate), chart.onAttributeChange("".concat(key, "ByContext"), forceUpdate), chart.onAttributeChange("".concat(key, "ByDimension"), forceUpdate)]; return function () { return offListeners.forEach(function (off) { return off(); }); }; }, [chart, key]); return chart.getUnitSign(_objectSpread({ key: key }, options)); }; export var useUnits = function useUnits() { var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "units"; var chart = useChart(); var forceUpdate = useForceUpdate(); useImmediateListener(function () { return chart.onAttributeChange("".concat(key, "ConversionPrefix"), forceUpdate); }, [chart, key]); return chart.getUnits(key); }; var formatPercentage = function formatPercentage(value, _ref2) { var fractionDigits = _ref2.fractionDigits; return value === 0 ? "-" : (Math.round((value + Number.EPSILON) * 100) / 100).toFixed(fractionDigits || 2); }; var formatPercentageWithSymbol = function formatPercentageWithSymbol(value, _ref3) { var fractionDigits = _ref3.fractionDigits; if (value == null || value === 0) return "-"; return (Math.round((value + Number.EPSILON) * 100) / 100).toFixed(fractionDigits || 1) + "%"; }; var formatInteger = function formatInteger(value) { return Math.round(value).toString(); }; var formatAnomalyParts = function formatAnomalyParts(value) { return parts.reduce(function (h, a) { return check(value, enums[a]) ? _objectSpread(_objectSpread({}, h), {}, _defineProperty({}, a, colors[a])) : h; }, {}); }; var formatByType = { arp: formatPercentage, percent: formatPercentage, cv: formatPercentageWithSymbol, count: formatInteger, points: formatInteger, dimensions: formatInteger, pa: formatAnomalyParts }; export var convert = function convert(chart, value) { var _ref4 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, valueKey = _ref4.valueKey, fractionDigits = _ref4.fractionDigits, dimensionId = _ref4.dimensionId, _ref4$unitsKey = _ref4.unitsKey, unitsKey = _ref4$unitsKey === void 0 ? "units" : _ref4$unitsKey, scaleByValue = _ref4.scaleByValue, unitAttributes = _ref4.unitAttributes; if (value === null || value === "-") return "-"; var formatter = formatByType[valueKey]; if (formatter) { return formatter(value, { fractionDigits: fractionDigits, dimensionId: dimensionId, unitsKey: unitsKey }); } var attrs = unitAttributes || (scaleByValue && typeof value !== "undefined" ? chart.getUnitAttributesForValue(value, { dimensionId: dimensionId, key: unitsKey }) : undefined); return chart.getConvertedValue(value, { fractionDigits: fractionDigits, key: unitsKey, dimensionId: dimensionId, unitAttributes: attrs }); }; export var useValueUnitAttributes = function useValueUnitAttributes(value) { var _ref5 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, valueKey = _ref5.valueKey, dimensionId = _ref5.dimensionId, _ref5$unitsKey = _ref5.unitsKey, unitsKey = _ref5$unitsKey === void 0 ? "units" : _ref5$unitsKey, scaleByValue = _ref5.scaleByValue; var chart = useChart(); var units = useAttributeValue(unitsKey); var desiredUnits = useAttributeValue("desiredUnits"); var secondsAsTime = useAttributeValue("secondsAsTime"); var viewDimensions = useAttributeValue("viewDimensions"); return useMemo(function () { if (!scaleByValue || value === null || value === "-" || typeof value === "undefined") { return undefined; } if (formatByType[valueKey]) return undefined; return chart.getUnitAttributesForValue(value, { dimensionId: dimensionId, key: unitsKey }); }, [chart, value, valueKey, dimensionId, unitsKey, scaleByValue, units, desiredUnits, secondsAsTime, viewDimensions]); }; export var useConverted = function useConverted(value) { var _ref6 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, valueKey = _ref6.valueKey, fractionDigits = _ref6.fractionDigits, dimensionId = _ref6.dimensionId, _ref6$unitsKey = _ref6.unitsKey, unitsKey = _ref6$unitsKey === void 0 ? "units" : _ref6$unitsKey, scaleByValue = _ref6.scaleByValue, unitAttributes = _ref6.unitAttributes; var chart = useChart(); var unitsConversionPrefix = useAttributeValue("".concat(unitsKey, "ConversionPrefix")); var unitsConversionBase = useAttributeValue("".concat(unitsKey, "ConversionBase")); var unitsByContext = useAttributeValue("".concat(unitsKey, "ByContext")); var unitsByDimension = useAttributeValue("".concat(unitsKey, "ByDimension")); var derivedUnitAttributes = useValueUnitAttributes(unitAttributes ? undefined : value, { valueKey: valueKey, dimensionId: dimensionId, unitsKey: unitsKey, scaleByValue: scaleByValue }); var attrs = unitAttributes || derivedUnitAttributes; return useMemo(function () { return convert(chart, value, { valueKey: valueKey, fractionDigits: fractionDigits, dimensionId: dimensionId, unitsKey: unitsKey, scaleByValue: scaleByValue, unitAttributes: attrs }); }, [chart, value, valueKey, fractionDigits, dimensionId, unitsKey, unitsConversionPrefix, unitsConversionBase, unitsByContext, unitsByDimension, scaleByValue, attrs]); }; export var useValueWithUnit = function useValueWithUnit(value) { var _ref7 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, valueKey = _ref7.valueKey, fractionDigits = _ref7.fractionDigits, dimensionId = _ref7.dimensionId, _ref7$unitsKey = _ref7.unitsKey, unitsKey = _ref7$unitsKey === void 0 ? "units" : _ref7$unitsKey, scaleByValue = _ref7.scaleByValue; var unitAttributes = useValueUnitAttributes(value, { valueKey: valueKey, dimensionId: dimensionId, unitsKey: unitsKey, scaleByValue: scaleByValue }); var convertedValue = useConverted(value, { valueKey: valueKey, fractionDigits: fractionDigits, dimensionId: dimensionId, unitsKey: unitsKey, scaleByValue: scaleByValue, unitAttributes: unitAttributes }); var convertedUnit = useUnitSign({ key: unitsKey, dimensionId: dimensionId, unitAttributes: unitAttributes }); return { convertedValue: convertedValue, convertedUnit: convertedUnit, unitAttributes: unitAttributes }; }; export var useLatestRowValue = function useLatestRowValue() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var chart = useChart(); var _useState7 = useState(null), _useState8 = _slicedToArray(_useState7, 2), value = _useState8[0], setState = _useState8[1]; useLayoutEffect(function () { var getValue = function getValue() { var hover = chart.getAttribute("hoverX"); var _chart$getPayload2 = chart.getPayload(), all = _chart$getPayload2.all; if (all.length === 0) return ""; var index = hover ? chart.getClosestRow(hover[0]) : -1; index = index === -1 ? all.length - 1 : index; var dimensionIds = chart.getVisibleDimensionIds(); return dimensionIds.map(function (id) { return { label: id, value: chart.getDimensionValue(id, index, options), color: chart.selectDimensionColor(id) }; }); }; return unregister(chart.onAttributeChange("hoverX", function () { return setState(getValue()); }), chart.on("dimensionChanged", function () { return setState(getValue()); }), chart.on("render", function () { return setState(getValue()); })); }, [chart]); return value; }; var calculateStats = function calculateStats(chart, id, period) { var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; var _chart$getPayload3 = chart.getPayload(), data = _chart$getPayload3.data; if (!(data !== null && data !== void 0 && data.length)) return null; options.abs = typeof options.abs === "boolean" ? options.abs : chart.getAttribute("abs"); var filteredData = data; if (period === "highlight") { var _chart$getAttribute = chart.getAttribute("overlays"), highlight = _chart$getAttribute.highlight; if (!(highlight !== null && highlight !== void 0 && highlight.range)) return null; var _highlight$range = _slicedToArray(highlight.range, 2), start = _highlight$range[0], end = _highlight$range[1]; filteredData = data.filter(function (row) { var timestamp = row[0] / 1000; return timestamp >= start && timestamp <= end; }); } if (!filteredData.length) return null; id = chart.isDimensionVisible(id) ? id : chart.getVisibleDimensionIds()[0]; if (!id) return null; var dimensionIndex = chart.getDimensionIndex(id); if (dimensionIndex === -1) return null; var values = []; for (var i = 0; i < filteredData.length; i++) { var value = chart.getRowDimensionValue(id, filteredData[i], options); if (value !== null && !isNaN(value) && isFinite(value)) { values.push(value); } } if (!values.length) return null; switch (options.valueKey) { case "min": return Math.min.apply(Math, values); case "max": return Math.max.apply(Math, values); case "avg": return values.reduce(function (a, b) { return a + b; }, 0) / values.length; case "value": return values[values.length - 1]; case "arp": return 0; case "median": { var sorted = [].concat(values).sort(function (a, b) { return a - b; }); var mid = Math.floor(sorted.length / 2); return sorted.length % 2 !== 0 ? sorted[mid] : (sorted[mid - 1] + sorted[mid]) / 2; } case "stddev": { var avg = values.reduce(function (a, b) { return a + b; }, 0) / values.length; var variance = values.reduce(function (sum, val) { return sum + Math.pow(val - avg, 2); }, 0) / values.length; return Math.sqrt(variance); } case "cv": { var _avg = values.reduce(function (a, b) { return a + b; }, 0) / values.length; var _variance = values.reduce(function (sum, val) { return sum + Math.pow(val - _avg, 2); }, 0) / values.length; var stddev = Math.sqrt(_variance); return _avg ? stddev / Math.abs(_avg) * 100 : null; } case "count": return values.length; case "volume": return values.reduce(function (sum, val) { return sum + Math.abs(val); }, 0); case "range": return Math.max.apply(Math, values) - Math.min.apply(Math, values); case "p25": return calculatePercentile(values, 25); case "p75": return calculatePercentile(values, 75); case "p95": return calculatePercentile(values, 95); default: return null; } }; export var getValueByPeriod = { latest: function latest(_ref8) { var chart = _ref8.chart, id = _ref8.id, options = _objectWithoutProperties(_ref8, _excluded2); options.abs = typeof options.abs === "boolean" ? options.abs : chart.getAttribute("abs"); var hover = chart.getAttribute("hoverX"); var _chart$getPayload4 = chart.getPayload(), all = _chart$getPayload4.all; if (!all.length) return null; var index = hover ? chart.getClosestRow(hover[0]) : -1; index = index === -1 ? all.length - 1 : index; id = chart.isDimensionVisible(id) ? id : chart.getVisibleDimensionIds()[0]; if (!id) return null; var dimValue = chart.getDimensionValue(id, index, options); return dimValue; }, window: function window(_ref9) { var chart = _ref9.chart, id = _ref9.id, options = _objectWithoutProperties(_ref9, _excluded3); return calculateStats(chart, id, "window", options); }, highlight: function highlight(_ref0) { var chart = _ref0.chart, id = _ref0.id, options = _objectWithoutProperties(_ref0, _excluded4); return calculateStats(chart, id, "highlight", options); } }; export var useValue = function useValue(id) { var period = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "latest"; var _ref1 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, _ref1$valueKey = _ref1.valueKey, valueKey = _ref1$valueKey === void 0 ? "value" : _ref1$valueKey, abs = _ref1.abs, _ref1$unitsKey = _ref1.unitsKey, unitsKey = _ref1$unitsKey === void 0 ? "units" : _ref1$unitsKey, allowNull = _ref1.allowNull; var chart = useChart(); var _useState9 = useState(null), _useState0 = _slicedToArray(_useState9, 2), value = _useState0[0], setState = _useState0[1]; useLayoutEffect(function () { var getValue = function getValue() { return (getValueByPeriod[period] || getValueByPeriod.latest)({ chart: chart, id: id, valueKey: valueKey, abs: abs, allowNull: allowNull }); }; setState(getValue()); return unregister(chart.onAttributeChange("hoverX", function () { return setState(getValue()); }), chart.on("dimensionChanged", function () { return setState(getValue()); }), chart.onAttributeChange("".concat(unitsKey, "Conversion"), function () { return setState(getValue()); }), chart.on("render", function () { return setState(getValue()); })); }, [chart, id, valueKey, period, unitsKey]); return value; }; export var useLatestValue = function useLatestValue(id) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; return useValue(id, "latest", options); }; export var useConvertedValue = function useConvertedValue(id) { var period = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "latest"; var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; var value = useValue(id, period, options); return useConverted(value, _objectSpread(_objectSpread({}, options), {}, { dimensionId: id })); }; export var useLatestConvertedValue = function useLatestConvertedValue(id) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; return useConvertedValue(id, "latest", _objectSpread({ allowNull: true, dimensionId: id }, options)); }; export var useIsMinimal = function useIsMinimal() { return useAttributeValue("designFlavour") === "minimal"; }; export var usePlotArea = function usePlotArea() { var _chart$getUI2, _chart$getUI2$getDygr, _area$x, _area$w; var uiName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "default"; var chart = useChart(); var forceUpdate = useForceUpdate(); useImmediateListener(function () { var _chart$getUI; return unregister(chart.on("mountChartUI", function () { return setTimeout(forceUpdate, 300); }), (_chart$getUI = chart.getUI(uiName)) === null || _chart$getUI === void 0 ? void 0 : _chart$getUI.on("rendered", forceUpdate).on("resize", forceUpdate)); }, [uiName, chart]); var area = (_chart$getUI2 = chart.getUI(uiName)) === null || _chart$getUI2 === void 0 || (_chart$getUI2$getDygr = _chart$getUI2.getDygraph) === null || _chart$getUI2$getDygr === void 0 || (_chart$getUI2$getDygr = _chart$getUI2$getDygr.call(_chart$getUI2)) === null || _chart$getUI2$getDygr === void 0 ? void 0 : _chart$getUI2$getDygr.getArea(); return { left: (_area$x = area === null || area === void 0 ? void 0 : area.x) !== null && _area$x !== void 0 ? _area$x : 0, width: (_area$w = area === null || area === void 0 ? void 0 : area.w) !== null && _area$w !== void 0 ? _area$w : 0 }; };