in src/data.ts [145:189]
export function aggregateDataPointsMap(data: DataPointsMapData, filter: DataPointsFilter = {}): AggregatedData {
const dataPointsMap = data.dataPointsMap;
const aggregatedData = {
dataPointsMap: {},
rangeDataMap: {},
selectedDataPoints: filter.selectedDataPoints,
sparklineXDomain: [],
hasHighlight: !!data.hasHighlight
};
const constructRangeFacetData = (dp: DataPoint) => {
if (!dp.rangeValues) { return; }
dp.rangeValues.forEach((rangeValue: RangeValue) => {
const key = rangeValue.key;
const rangeDataMap = aggregatedData.rangeDataMap[key] || (aggregatedData.rangeDataMap[key] = {});
!rangeDataMap[rangeValue.valueLabel] && (rangeDataMap[rangeValue.valueLabel] = {
facetKey: key,
rows: [],
label: rangeValue.valueLabel,
count: 0,
highlight: 0,
subSelection: 0,
metadata: {
rangeValue: rangeValue.value,
},
});
rangeDataMap[rangeValue.valueLabel].rows.push(...dp.rows);
rangeDataMap[rangeValue.valueLabel].count += dp.instanceCount;
rangeDataMap[rangeValue.valueLabel].highlight += dp.highlight;
const passFilter = (isInSelectedDataPoints(dp, filter.selectedDataPoints) || checkKeywordFilter(filter.contains, dp)) && checkRangeFilter(filter.range, dp.rangeValues);
if (passFilter) {
rangeDataMap[rangeValue.valueLabel].subSelection += dp.instanceCount;
}
});
};
const sparklineXValues = [];
Object.keys(dataPointsMap).forEach((key: string) => {
dataPointsMap[key].forEach(constructRangeFacetData);
const dataPoints: DataPoint[] = aggregateDataPoints(dataPointsMap[key], filter);
dataPoints.length > 0 && (aggregatedData.dataPointsMap[key] = dataPoints);
dataPoints.forEach(dp => sparklineXValues.push(...Object.keys(dp['sparklineData'] || {})));
});
aggregatedData.sparklineXDomain = uniq(sparklineXValues).sort(compareRangeValue);
return aggregatedData;
}