@grafana/ui
Version:
Grafana Components Library
63 lines (60 loc) • 1.69 kB
JavaScript
import { FieldType, isLikelyAscendingVector, sortDataFrame, applyNullInsertThreshold } from '@grafana/data';
;
function preparePlotFrame(sparkline, config) {
var _a, _b, _c;
const length = sparkline.y.values.length;
const yFieldConfig = {
...sparkline.y.config,
...config
};
const xField = (_a = sparkline.x) != null ? _a : {
name: "",
values: [...Array(length).keys()],
type: FieldType.number,
config: {}
};
let frame = {
refId: "sparkline",
fields: [
xField,
{
...sparkline.y,
config: yFieldConfig
}
],
length
};
if (!isLikelyAscendingVector(xField.values)) {
frame = sortDataFrame(frame, 0);
}
return applyNullInsertThreshold({
frame,
refFieldPseudoMin: (_b = sparkline.timeRange) == null ? void 0 : _b.from.valueOf(),
refFieldPseudoMax: (_c = sparkline.timeRange) == null ? void 0 : _c.to.valueOf()
});
}
function getYRange(field, alignedFrame) {
var _a, _b, _c, _d;
let { min, max } = (_a = alignedFrame.fields[1].state) == null ? void 0 : _a.range;
min = Math.max(min, (_b = field.config.min) != null ? _b : -Infinity);
max = Math.min(max, (_c = field.config.max) != null ? _c : Infinity);
const noValue = +((_d = alignedFrame.fields[1].config) == null ? void 0 : _d.noValue);
if (!Number.isNaN(noValue)) {
min = Math.min(min, noValue);
max = Math.max(max, noValue);
}
if (min === max) {
if (min === 0) {
max = 100;
} else if (min < 0) {
max = 0;
min *= 2;
} else {
min = 0;
max *= 2;
}
}
return [min, max];
}
export { getYRange, preparePlotFrame };
//# sourceMappingURL=utils.mjs.map