@netdata/charts
Version:
Netdata frontend SDK and chart utilities
97 lines (96 loc) • 5.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _helpers = require("./helpers");
var _excluded = ["attrs"];
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); }
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 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); }
var wildcardArray = ["*"];
var getPayload = function getPayload(chart) {
var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var _chart$getAttributes$ = _objectSpread(_objectSpread({}, chart.getAttributes()), attrs),
selectedContexts = _chart$getAttributes$.selectedContexts,
context = _chart$getAttributes$.context,
nodesScope = _chart$getAttributes$.nodesScope,
contextScope = _chart$getAttributes$.contextScope,
selectedInstances = _chart$getAttributes$.selectedInstances,
selectedDimensions = _chart$getAttributes$.selectedDimensions,
selectedLabels = _chart$getAttributes$.selectedLabels,
aggregationMethod = _chart$getAttributes$.aggregationMethod,
groupBy = _chart$getAttributes$.groupBy,
groupByLabel = _chart$getAttributes$.groupByLabel,
postGroupBy = _chart$getAttributes$.postGroupBy,
postGroupByLabel = _chart$getAttributes$.postGroupByLabel,
postAggregationMethod = _chart$getAttributes$.postAggregationMethod,
showPostAggregations = _chart$getAttributes$.showPostAggregations;
var selectedNodes = chart.getFilteredNodeIds();
var options = (0, _helpers.getChartURLOptions)(chart);
var _getChartPayload = (0, _helpers.getChartPayload)(chart, attrs),
after = _getChartPayload.after,
before = _getChartPayload.before,
points = _getChartPayload.points,
time_group = _getChartPayload.time_group,
time_resampling = _getChartPayload.time_resampling,
format = _getChartPayload.format;
return {
format: format,
options: options,
scope: {
contexts: Array.isArray(contextScope) && contextScope.length ? contextScope : wildcardArray,
nodes: Array.isArray(nodesScope) && nodesScope.length ? nodesScope : []
},
selectors: {
contexts: Array.isArray(selectedContexts) && selectedContexts.length ? selectedContexts : context ? [context] : wildcardArray,
nodes: Array.isArray(selectedNodes) && selectedNodes.length ? selectedNodes : wildcardArray,
instances: Array.isArray(selectedInstances) && selectedInstances.length ? selectedInstances : wildcardArray,
dimensions: Array.isArray(selectedDimensions) && selectedDimensions.length ? selectedDimensions : wildcardArray,
labels: Array.isArray(selectedLabels) && selectedLabels.length ? selectedLabels : wildcardArray
},
aggregations: {
metrics: [{
group_by: groupBy,
group_by_label: groupByLabel,
aggregation: aggregationMethod
}, showPostAggregations && !!postGroupBy.length && {
group_by: postGroupBy,
group_by_label: postGroupByLabel,
aggregation: postAggregationMethod
}].filter(Boolean),
time: {
time_group: time_group,
// time_group_options: "",
time_resampling: time_resampling
}
},
window: _objectSpread(_objectSpread({
after: after
}, after > 0 && {
before: before
}), {}, {
points: points
// tier: 0
})
};
};
var _default = exports["default"] = function _default(chart) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
attrs = _ref.attrs,
options = _objectWithoutProperties(_ref, _excluded);
var _chart$getAttributes = chart.getAttributes(),
host = _chart$getAttributes.host;
var payload = getPayload(chart, attrs);
return fetch("".concat(host, "/data"), _objectSpread({
method: "POST",
body: JSON.stringify(payload)
}, options)).then(function (response) {
return response.json();
});
};