GraphNG: update uPlot v1.5.0 (#29763)

This commit is contained in:
Leon Sorokin
2020-12-11 13:01:55 -06:00
committed by GitHub
parent 7dd387ce57
commit 77d6100b44
13 changed files with 57 additions and 484 deletions

View File

@ -8,7 +8,7 @@ import {
FieldMatcherID,
} from '@grafana/data';
import { AlignedFrameWithGapTest } from '../uPlot/types';
import uPlot, { AlignedData, AlignedDataWithGapTest } from 'uplot';
import uPlot, { AlignedData } from 'uplot';
import { XYFieldMatchers } from './GraphNG';
// the results ofter passing though data
@ -103,7 +103,7 @@ export function alignDataFrames(frames: DataFrame[], fields?: XYFieldMatchers):
}
// do the actual alignment (outerJoin on the first arrays)
let { data: alignedData, isGap } = outerJoinValues(valuesFromFrames, skipGaps);
let { data: alignedData, isGap } = uPlot.join(valuesFromFrames, skipGaps);
if (alignedData!.length !== sourceFields.length) {
throw new Error('outerJoinValues lost a field?');
@ -121,76 +121,3 @@ export function alignDataFrames(frames: DataFrame[], fields?: XYFieldMatchers):
isGap,
};
}
// skipGaps is a tables-matched bool array indicating which series can skip storing indices of original nulls
export function outerJoinValues(tables: AlignedData[], skipGaps?: boolean[][]): AlignedDataWithGapTest {
if (tables.length === 1) {
return {
data: tables[0],
isGap: skipGaps ? (u: uPlot, seriesIdx: number, dataIdx: number) => !skipGaps[0][seriesIdx] : () => true,
};
}
let xVals: Set<number> = new Set();
let xNulls: Array<Set<number>> = [new Set()];
for (let ti = 0; ti < tables.length; ti++) {
let t = tables[ti];
let xs = t[0];
let len = xs.length;
let nulls: Set<number> = new Set();
for (let i = 0; i < len; i++) {
xVals.add(xs[i]);
}
for (let j = 1; j < t.length; j++) {
if (skipGaps == null || !skipGaps[ti][j]) {
let ys = t[j];
for (let i = 0; i < len; i++) {
if (ys[i] == null) {
nulls.add(xs[i]);
}
}
}
}
xNulls.push(nulls);
}
let data: AlignedData = [Array.from(xVals).sort((a, b) => a - b)];
let alignedLen = data[0].length;
let xIdxs = new Map();
for (let i = 0; i < alignedLen; i++) {
xIdxs.set(data[0][i], i);
}
for (const t of tables) {
let xs = t[0];
for (let j = 1; j < t.length; j++) {
let ys = t[j];
let yVals = Array(alignedLen).fill(null);
for (let i = 0; i < ys.length; i++) {
yVals[xIdxs.get(xs[i])] = ys[i];
}
data.push(yVals);
}
}
return {
data: data,
isGap(u: uPlot, seriesIdx: number, dataIdx: number) {
// u.data has to be AlignedDate
let xVal = u.data[0][dataIdx];
return xNulls[seriesIdx].has(xVal!);
},
};
}