MCPcopy Create free account
hub / github.com/Make-md/makemd / processDataAggregation

Function processDataAggregation

src/core/utils/visualization/visualizationUtils.ts:855–940  ·  view source on GitHub ↗
(
  rows: any[],
  config: {
    xField: string;
    yField: string;
    groupByField?: string;
    groupByAggregation?: AggregationType;
    chartType: string;
    hasYFieldInData: boolean;
    spaceData: any;
    xType?: string;
    yType?: string;
  }
)

Source from the content-addressed store, hash-verified

853 * Processes data aggregation based on chart configuration
854 */
855export const processDataAggregation = (
856 rows: any[],
857 config: {
858 xField: string;
859 yField: string;
860 groupByField?: string;
861 groupByAggregation?: AggregationType;
862 chartType: string;
863 hasYFieldInData: boolean;
864 spaceData: any;
865 xType?: string;
866 yType?: string;
867 }
868): any[] => {
869 const {
870 xField,
871 yField,
872 groupByField,
873 groupByAggregation = 'count',
874 chartType,
875 hasYFieldInData,
876 spaceData,
877 xType,
878 yType
879 } = config;
880
881 // Special handling for pie charts - always aggregate by category field
882 if (chartType === 'pie' && rows.length > 0) {
883 // For pie charts, use color field if available, otherwise use x field as category
884 const categoryField = groupByField || xField;
885 const valueField = yField;
886
887 // Only aggregate if we have at least a category field
888 if (categoryField && valueField) {
889 const aggregationType = groupByField ? groupByAggregation : 'sum';
890 return aggregateForPieChart(rows, categoryField, valueField, aggregationType, hasYFieldInData);
891 } else {
892 // Return data as-is if fields are not properly configured
893 return rows;
894 }
895 } else if (groupByField && xField && yField && rows.length > 0) {
896 return aggregateByGroup(rows, xField, yField, groupByField, groupByAggregation, hasYFieldInData);
897 } else if (xField && yField && (chartType === 'line' || chartType === 'area')) {
898 // Line and area charts ALWAYS need proper bucketing and aggregation
899 const shouldAggregate = shouldAggregateYField(hasYFieldInData, spaceData, yField, rows);
900
901 if (shouldAggregate) {
902 // Y field is non-numeric - use count aggregation
903 return aggregateNonNumericY(rows, xField, yField, hasYFieldInData);
904 } else {
905 // Y field is numeric - use proper line graph bucketing with sum aggregation
906 return aggregateForLineGraph(rows, xField, yField, 'sum');
907 }
908 } else if (xField && yField &&
909 (chartType === 'scatter' || chartType === 'bar')) {
910
911 const shouldAggregate = shouldAggregateYField(hasYFieldInData, spaceData, yField, rows);
912 if (shouldAggregate) {

Callers

nothing calls this directly

Calls 12

aggregateForPieChartFunction · 0.85
aggregateByGroupFunction · 0.85
shouldAggregateYFieldFunction · 0.85
aggregateNonNumericYFunction · 0.85
aggregateForLineGraphFunction · 0.85
fromMethod · 0.80
entriesMethod · 0.80
forEachMethod · 0.45
setMethod · 0.45
getMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected