UNPKG

@netdata/charts

Version:

Netdata frontend SDK and chart utilities

43 lines 1.96 kB
import { getNormalizedUnitConfig, getUnitsString } from "../../helpers/units"; import { getConversionAttributes } from "../../helpers/unitConversion/getConversionUnits"; export default (function (chart) { return chart.getUnitSign = function () { var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, dimensionId = _ref.dimensionId, _ref$long = _ref["long"], _long = _ref$long === void 0 ? false : _ref$long, _ref$key = _ref.key, key = _ref$key === void 0 ? "units" : _ref$key, _ref$withoutConversio = _ref.withoutConversion, withoutConversion = _ref$withoutConversio === void 0 ? false : _ref$withoutConversio, unitAttributes = _ref.unitAttributes, value = _ref.value; var _ref2 = unitAttributes || (typeof value === "undefined" ? chart.getUnitAttributes(dimensionId, key) : chart.getUnitAttributesForValue(value, { dimensionId: dimensionId, key: key })), base = _ref2.base, prefix = _ref2.prefix, unit = _ref2.unit; if (withoutConversion) return getNormalizedUnitConfig(unit).name; return getUnitsString(unit, prefix, base, _long); }; }); export var makeGetUnitAttributesForValue = function makeGetUnitAttributesForValue(chart) { return chart.getUnitAttributesForValue = function (value) { var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, dimensionId = _ref3.dimensionId, _ref3$key = _ref3.key, key = _ref3$key === void 0 ? "units" : _ref3$key, _ref3$min = _ref3.min, min = _ref3$min === void 0 ? value : _ref3$min, _ref3$max = _ref3.max, max = _ref3$max === void 0 ? value : _ref3$max; var units = chart.getAttribute(key); var unit = dimensionId ? chart.getDimensionUnit(dimensionId) : Array.isArray(units) ? units[0] : units; return getConversionAttributes(chart, unit, { min: min, max: max }); }; };