mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Histogram: filter nulls, bucket-adaptive xAxis decimals (#51773)
This commit is contained in:
parent
1e85a6f4fd
commit
173636aa61
@ -160,13 +160,13 @@ export function buildHistogram(frames: DataFrame[], options?: HistogramTransform
|
|||||||
for (const frame of frames) {
|
for (const frame of frames) {
|
||||||
for (const field of frame.fields) {
|
for (const field of frame.fields) {
|
||||||
if (field.type === FieldType.number) {
|
if (field.type === FieldType.number) {
|
||||||
allValues = allValues.concat(
|
allValues = allValues.concat(field.values.toArray());
|
||||||
field.values.toArray().map((val: number) => Number(val.toFixed(field.config.decimals ?? 0)))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
allValues = allValues.filter((v) => v != null);
|
||||||
|
|
||||||
allValues.sort((a, b) => a - b);
|
allValues.sort((a, b) => a - b);
|
||||||
|
|
||||||
let smallestDelta = Infinity;
|
let smallestDelta = Infinity;
|
||||||
@ -204,6 +204,9 @@ export function buildHistogram(frames: DataFrame[], options?: HistogramTransform
|
|||||||
|
|
||||||
const getBucket = (v: number) => incrRoundDn(v - bucketOffset, bucketSize!) + bucketOffset;
|
const getBucket = (v: number) => incrRoundDn(v - bucketOffset, bucketSize!) + bucketOffset;
|
||||||
|
|
||||||
|
// guess number of decimals
|
||||||
|
let bucketDecimals = (('' + bucketSize).match(/\.\d+$/) ?? ['.'])[0].length - 1;
|
||||||
|
|
||||||
let histograms: AlignedData[] = [];
|
let histograms: AlignedData[] = [];
|
||||||
let counts: Field[] = [];
|
let counts: Field[] = [];
|
||||||
let config: FieldConfig | undefined = undefined;
|
let config: FieldConfig | undefined = undefined;
|
||||||
@ -220,7 +223,7 @@ export function buildHistogram(frames: DataFrame[], options?: HistogramTransform
|
|||||||
unit: undefined,
|
unit: undefined,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (!config && Object.keys(field.config).length) {
|
if (!config && field.config.unit) {
|
||||||
config = field.config;
|
config = field.config;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -251,7 +254,13 @@ export function buildHistogram(frames: DataFrame[], options?: HistogramTransform
|
|||||||
values: new ArrayVector(joinedHists[0]),
|
values: new ArrayVector(joinedHists[0]),
|
||||||
type: FieldType.number,
|
type: FieldType.number,
|
||||||
state: undefined,
|
state: undefined,
|
||||||
config: config ?? {},
|
config:
|
||||||
|
bucketDecimals === 0
|
||||||
|
? config ?? {}
|
||||||
|
: {
|
||||||
|
...config,
|
||||||
|
decimals: bucketDecimals,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
const bucketMax = {
|
const bucketMax = {
|
||||||
...bucketMin,
|
...bucketMin,
|
||||||
|
Loading…
Reference in New Issue
Block a user