Reducers: minor reducer cleanup (#32656)

This commit is contained in:
Ryan McKinley 2021-04-02 16:14:42 -07:00 committed by GitHub
parent 948da25c13
commit 8ab223d79f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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++;