UNPKG

@adaptabletools/adaptable

Version:

Powerful AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements

33 lines (32 loc) 1.3 kB
export const WEIGHTED_AVERAGE_AGG_FN_NAME = 'weightedAvg'; export const ONLY_AGG_FN_NAME = 'only'; export const isWeightedAverageAggFuncName = (aggFunc) => { return aggFunc === WEIGHTED_AVERAGE_AGG_FN_NAME; }; export const isWeightedAverageAggregation = (aggFunc) => { return aggFunc?.type === 'weightedAverage'; }; export const getAggFuncName = (aggFunc) => { if (isWeightedAverageAggregation(aggFunc)) { return WEIGHTED_AVERAGE_AGG_FN_NAME; } else if (typeof aggFunc === 'string') { return aggFunc; } else { return aggFunc; } }; export const isWeightedAverageAggFuncEligible = (column) => { const weightedAverageAllowed = !column.userAllowedAggFuncs?.length || column.userAllowedAggFuncs.includes(WEIGHTED_AVERAGE_AGG_FN_NAME); return column.dataType === 'number' && column.aggregatable && weightedAverageAllowed; }; export const getDisplayAggFuncNames = (column) => { const names = [...new Set(column.availableAggregationFunctions || [])].filter((name) => name !== WEIGHTED_AVERAGE_AGG_FN_NAME); if (isWeightedAverageAggFuncEligible(column)) { const avgIndex = names.indexOf('avg'); names.splice(avgIndex >= 0 ? avgIndex + 1 : names.length, 0, WEIGHTED_AVERAGE_AGG_FN_NAME); } return names; };