@adaptabletools/adaptable
Version:
Powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
33 lines (32 loc) • 1.6 kB
TypeScript
import { DeepMap } from './deepMap';
export type GroupKeyType<T extends any = any> = T;
export type GroupBy<DataType, KeyType> = {
field: keyof DataType & string;
toKey?: (value: any, data: DataType) => GroupKeyType<KeyType>;
};
export type AggregateParams<DataType, KeyType> = {
reducers: Record<string, DataAggregationReducer<DataType, any>>;
groupBy?: GroupBy<DataType, KeyType>[];
defaultToKey?: (value: any, item: DataType) => GroupKeyType<KeyType>;
};
export type DataAggregationReducer<T, AggregationResultType> = {
name?: string;
field?: keyof T & string;
initialValue?: AggregationResultType;
getter?: (data: T) => any;
reducer: string | ((accumulator: any, value: any, data: T, dataIndex: number) => AggregationResultType | any);
done?: (accumulatedValue: AggregationResultType | any, array: T[]) => AggregationResultType;
};
export type DataAggregationResult<DataType, KeyType extends any> = {
deepMap: DeepMap<GroupKeyType<KeyType>, DeepMapAggregationValueType<DataType, KeyType>>;
aggregateParams: AggregateParams<DataType, KeyType>;
initialData: DataType[];
reducerResults?: Record<string, AggregationReducerResult>;
};
export type DeepMapAggregationValueType<DataType, KeyType> = {
items: DataType[];
commonData?: Partial<DataType>;
reducerResults: Record<string, AggregationReducerResult>;
};
export type AggregationReducerResult = number;
export declare function aggregate<DataType, KeyType = any>(aggregateParams: AggregateParams<DataType, KeyType>, data: DataType[]): DataAggregationResult<DataType, KeyType>;