That is correct, if you substitute "bin value" for "groupValue" in what you wrote.
A group is made of an array of bins; each bin is a key-value pair. For every group, all rows of the data supplied to crossfilter will "fall into" one bin or another. The reduce functions determine what happens when a row falls into a bin, or is removed from it because the filters changed.
Crossfilter determines which bin any row falls into by using using the dimension value accessor and the group value function.
When are reduction functions called?
When a crossfilter initializes a new group, it adds all the currently matching rows of the data to all the groups. The group determines a key for each row by using the dimension value accessor and the group value function. Then it looks up the bin using that key, and applies the reduceAdd
function to the previous bin value and the row data to produce the new bin value.
When any filter on any dimension of the crossfilter changes value, some rows will stop matching and some rows will start matching the new set of filters. The rows that stop matching are removed from the matching bin using the reduceRemove
function, and the rows that start matching are added using the reduceAdd
function.
When a row is added, some groups may not already have a bin which matches the key for that row. At that point a new bin must be initialized and at that point the group calls reduceInitial
to get the user-specified blank value for the bins of that group.
Crossfilter's group.reduce compared to Array.reduce
The reduceAdd
and reduceRemove
functions are similar to the functions you would pass to Javascript's Array.reduce function. The first parameter p
takes the previous value of the bin, and the second paramter v
takes the current row data being considered.
In contrast to Array.reduce
, in group.reduce
- values can be removed as well as added
- the initial value is produced by the
reduceInitial
function instead of being passed to reduce
- it doesn't perform the aggregation immediately; instead you are supplying functions that will get called whenever filters change or data is added or removed