mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Calcs: Fixed calc reducer (#18998)
This commit is contained in:
@@ -52,17 +52,13 @@ describe('Stats Calculators', () => {
|
||||
it('should calculate basic stats', () => {
|
||||
const stats = reduceField({
|
||||
field: basicTable.fields[0],
|
||||
reducers: ['first', 'last', 'mean'],
|
||||
reducers: ['first', 'last', 'mean', 'count'],
|
||||
});
|
||||
|
||||
// First
|
||||
expect(stats.first).toEqual(10);
|
||||
|
||||
// Last
|
||||
expect(stats.last).toEqual(20);
|
||||
|
||||
// Mean
|
||||
expect(stats.mean).toEqual(15);
|
||||
expect(stats.count).toEqual(2);
|
||||
});
|
||||
|
||||
it('should support a single stat also', () => {
|
||||
|
@@ -247,13 +247,17 @@ function doStandardCalcs(field: Field, ignoreNulls: boolean, nullAsZero: boolean
|
||||
// Just used for calcutations -- not exposed as a stat
|
||||
previousDeltaUp: true,
|
||||
} as FieldCalcs;
|
||||
|
||||
const data = field.values;
|
||||
calcs.count = data.length;
|
||||
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
let currentValue = data.get(i);
|
||||
|
||||
if (i === 0) {
|
||||
calcs.first = currentValue;
|
||||
}
|
||||
|
||||
calcs.last = currentValue;
|
||||
|
||||
if (currentValue === null) {
|
||||
|
Reference in New Issue
Block a user