TimeSeries: fix spanNulls threshold toggle during panel editing (#34452)

This commit is contained in:
Leon Sorokin
2021-05-20 06:47:49 +02:00
committed by GitHub
parent 9237348076
commit 3ecacc9d1d
@@ -2,38 +2,37 @@ import { XYFieldMatchers } from './types';
import { ArrayVector, DataFrame, FieldType, outerJoinDataFrames } from '@grafana/data';
import { nullToUndefThreshold } from './nullToUndefThreshold';
function applySpanNullsThresholds(frames: DataFrame[]) {
for (const frame of frames) {
let refField = frame.fields.find((field) => field.type === FieldType.time); // this doesnt need to be time, just any numeric/asc join field
let refValues = refField?.values.toArray() as any[];
// will mutate the DataFrame's fields' values
function applySpanNullsThresholds(frame: DataFrame) {
let refField = frame.fields.find((field) => field.type === FieldType.time); // this doesnt need to be time, just any numeric/asc join field
let refValues = refField?.values.toArray() as any[];
for (let i = 0; i < frame.fields.length; i++) {
let field = frame.fields[i];
for (let i = 0; i < frame.fields.length; i++) {
let field = frame.fields[i];
if (field === refField) {
continue;
}
if (field === refField) {
continue;
}
if (field.type === FieldType.number) {
let spanNulls = field.config.custom?.spanNulls;
if (field.type === FieldType.number) {
let spanNulls = field.config.custom?.spanNulls;
if (typeof spanNulls === 'number') {
field.values = new ArrayVector(nullToUndefThreshold(refValues, field.values.toArray(), spanNulls));
}
if (typeof spanNulls === 'number') {
field.values = new ArrayVector(nullToUndefThreshold(refValues, field.values.toArray(), spanNulls));
}
}
}
return frames;
return frame;
}
export function preparePlotFrame(frames: DataFrame[], dimFields: XYFieldMatchers) {
applySpanNullsThresholds(frames);
return outerJoinDataFrames({
let alignedFrame = outerJoinDataFrames({
frames: frames,
joinBy: dimFields.x,
keep: dimFields.y,
keepOriginIndices: true,
});
return alignedFrame && applySpanNullsThresholds(alignedFrame);
}