docs/api-reference/aggregation-layers/aggregator.md
The Aggregator interface describes a type of class that performs aggregation.
Aggregation is a 2-step process:
An implementation of the Aggregator interface takes the following inputs:
And yields the following outputs:
Consider the task of making a histogram that shows the result of a survey by age distribution.
[20]. A 35-year-old participant is assigned to the bin of age 35-40, with binId [35], and so on.[15, 20, 25, 30, 35, 40][1, 5, 12, 10, 8, 3][1, 12][6, 8.2, 8.5, 7.9, 7.75, 8][6, 8.5]An implementation of Aggregator should expose the following methods:
setProps {#setprops}Set runtime properties of the aggregation.
aggregator.setProps({
pointCount: 10000,
attributes: {...},
operations: ['SUM', 'MEAN'],
binOptions: {groupSize: 5}
});
Arguments:
pointCount (number) - number of data points.attributes (Attribute[]) - the input data.operations (string[]) - How to aggregate the values inside a bin, defined per channel.binOptions (object) - arbitrary settings that affect bin sorting.onUpdate (Function) - callback when a channel has been recalculated. Receives the following arguments:
channel (number) - the channel that just updatedsetNeedsUpdate {#setneedsupdate}Flags a channel to need update. This could be a result of change in the input data or bin options.
aggregator.setNeedsUpdate(0);
Arguments:
channel (number, optional) - mark the given channel as dirty. If not provided, all channels will be updated.update {#update}Called after all props are set and before results are accessed. The aggregator should allocate resources and redo aggregations if needed at this stage.
aggregator.update();
preDraw {#predraw}Called before the result buffers are drawn to screen. Certain types of aggregations are dependent on render time context and this is alternative opportunity to update just-in-time.
aggregator.preDraw();
getBin {#getbin}Get the information of a given bin.
const bin = aggregator.getBin(100);
Arguments:
index (number) - index of the bin to locate it in getBins()Returns:
id (number[]) - Unique bin ID.value (number[]) - Aggregated values by channel.count (number) - Number of data points in this bin.pointIndices (number[] | undefined) - Indices of data points in this bin if available. This field may not be populated when using GPU-based implementations.getBins {#getbins}Get an accessor to all bin IDs.
const binIdsAttribute = aggregator.getBins();
Returns:
update has never been calledgetResult {#getresult}Get an accessor to the aggregated values of a given channel.
const resultAttribute = aggregator.getResult(0);
Arguments:
channel (number) - the channel to retrieve results fromReturns:
update has never been calledgetResultDomain {#getresultdomain}Get the [min, max] of aggregated values of a given channel.
const [min, max] = aggregator.getResultDomain(0);
Arguments:
channel (number) - the channel to retrieve results fromReturns the domain ([number, number]) of the aggregated values of the given channel.
destroy {#destroy}Dispose all allocated resources.
aggregator.destroy();
An implementation of Aggregator should expose the following members:
binCount (number) {#bincount}The number of bins in the aggregated result.
modules/aggregation-layers/src/common/aggregator/aggregator.ts