mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Reducers: minor reducer cleanup (#32656)
This commit is contained in:
parent
948da25c13
commit
8ab223d79f
@ -1,7 +1,7 @@
|
||||
// Libraries
|
||||
import isNumber from 'lodash/isNumber';
|
||||
|
||||
import { NullValueMode, Field, FieldState, FieldCalcs } from '../types/index';
|
||||
import { NullValueMode, Field, FieldState, FieldCalcs, FieldType } from '../types/index';
|
||||
import { Registry, RegistryItem } from '../utils/Registry';
|
||||
|
||||
export enum ReducerID {
|
||||
@ -260,6 +260,8 @@ export function doStandardCalcs(field: Field, ignoreNulls: boolean, nullAsZero:
|
||||
const data = field.values;
|
||||
calcs.count = data.length;
|
||||
|
||||
const isNumberField = field.type === FieldType.number || FieldType.time;
|
||||
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
let currentValue = data.get(i);
|
||||
|
||||
@ -278,13 +280,14 @@ export function doStandardCalcs(field: Field, ignoreNulls: boolean, nullAsZero:
|
||||
}
|
||||
}
|
||||
|
||||
if (currentValue !== null && currentValue !== undefined) {
|
||||
if (currentValue != null) {
|
||||
// null || undefined
|
||||
const isFirst = calcs.firstNotNull === null;
|
||||
if (isFirst) {
|
||||
calcs.firstNotNull = currentValue;
|
||||
}
|
||||
|
||||
if (isNumber(currentValue)) {
|
||||
if (isNumberField) {
|
||||
calcs.sum += currentValue;
|
||||
calcs.allIsNull = false;
|
||||
calcs.nonNullCount++;
|
||||
|
Loading…
Reference in New Issue
Block a user