@netdata/charts
Version:
Netdata frontend SDK and chart utilities
49 lines (48 loc) • 2.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.makeGetUnitAttributesForValue = exports["default"] = void 0;
var _units = require("../../helpers/units");
var _getConversionUnits = require("../../helpers/unitConversion/getConversionUnits");
var _default = exports["default"] = function _default(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 (0, _units.getNormalizedUnitConfig)(unit).name;
return (0, _units.getUnitsString)(unit, prefix, base, _long);
};
};
var makeGetUnitAttributesForValue = exports.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 (0, _getConversionUnits.getConversionAttributes)(chart, unit, {
min: min,
max: max
});
};
};