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 field of frame.fields) {
|
||||
if (field.type === FieldType.number) {
|
||||
allValues = allValues.concat(
|
||||
field.values.toArray().map((val: number) => Number(val.toFixed(field.config.decimals ?? 0)))
|
||||
);
|
||||
allValues = allValues.concat(field.values.toArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
allValues = allValues.filter((v) => v != null);
|
||||
|
||||
allValues.sort((a, b) => a - b);
|
||||
|
||||
let smallestDelta = Infinity;
|
||||
@ -204,6 +204,9 @@ export function buildHistogram(frames: DataFrame[], options?: HistogramTransform
|
||||
|
||||
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 counts: Field[] = [];
|
||||
let config: FieldConfig | undefined = undefined;
|
||||
@ -220,7 +223,7 @@ export function buildHistogram(frames: DataFrame[], options?: HistogramTransform
|
||||
unit: undefined,
|
||||
},
|
||||
});
|
||||
if (!config && Object.keys(field.config).length) {
|
||||
if (!config && field.config.unit) {
|
||||
config = field.config;
|
||||
}
|
||||
}
|
||||
@ -251,7 +254,13 @@ export function buildHistogram(frames: DataFrame[], options?: HistogramTransform
|
||||
values: new ArrayVector(joinedHists[0]),
|
||||
type: FieldType.number,
|
||||
state: undefined,
|
||||
config: config ?? {},
|
||||
config:
|
||||
bucketDecimals === 0
|
||||
? config ?? {}
|
||||
: {
|
||||
...config,
|
||||
decimals: bucketDecimals,
|
||||
},
|
||||
};
|
||||
const bucketMax = {
|
||||
...bucketMin,
|
||||
|
Loading…
Reference in New Issue
Block a user