Skip to content

Commit 92735b3

Browse files
authored
document reducer scope (#784)
1 parent d3840cc commit 92735b3

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,9 +1373,9 @@ The following aggregation methods are supported:
13731373
* *y1* - the lower bound of the bin’s *y*-extent (when binning on *y*)
13741374
* *y2* - the upper bound of the bin’s *y*-extent (when binning on *y*)
13751375
* a function to be passed the array of values for each bin and the extent of the bin
1376-
* an object with a *reduce* method
1376+
* an object with a *reduce* method, and optionally a *scope*
13771377

1378-
The *reduce* method is repeatedly passed the index for each bin (an array of integers), the corresponding input channel’s array of values, and the extent of the bin; it must then return the corresponding aggregate value for the bin.
1378+
In the last case, the *reduce* method is repeatedly passed three arguments: the index for each bin (an array of integers), the input channel’s array of values, and the extent of the bin (an object {x1, x2, y1, y2}); it must then return the corresponding aggregate value for the bin. If the reducer object’s *scope* is “data”, then the *reduce* method is first invoked for the full data; the return value of the *reduce* method is then made available as a third argument (making the extent the fourth argument). Similarly if the *scope* is “facet”, then the *reduce* method is invoked for each facet, and the resulting reduce value is made available while reducing the facet’s bins. (This optional *scope* is used by the *proportion* and *proportion-facet* reducers.)
13791379

13801380
Most aggregation methods require binding the output channel to an input channel; for example, if you want the **y** output channel to be a *sum* (not merely a count), there should be a corresponding **y** input channel specifying which values to sum. If there is not, *sum* will be equivalent to *count*.
13811381

@@ -1505,7 +1505,9 @@ The following aggregation methods are supported:
15051505
* *deviation* - the standard deviation
15061506
* *variance* - the variance per [Welford’s algorithm](https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Welford's_online_algorithm)
15071507
* a function - passed the array of values for each group
1508-
* an object with a *reduce* method - passed the index for each group, and all values
1508+
* an object with a *reduce* method, an optionally a *scope*
1509+
1510+
In the last case, the *reduce* method is repeatedly passed two arguments: the index for each group (an array of integers), and the input channel’s array of values; it must then return the corresponding aggregate value for the group. If the reducer object’s *scope* is “data”, then the *reduce* method is first invoked for the full data; the return value of the *reduce* method is then made available as a third argument. Similarly if the *scope* is “facet”, then the *reduce* method is invoked for each facet, and the resulting reduce value is made available while reducing the facet’s groups. (This optional *scope* is used by the *proportion* and *proportion-facet* reducers.)
15091511

15101512
Most aggregation methods require binding the output channel to an input channel; for example, if you want the **y** output channel to be a *sum* (not merely a count), there should be a corresponding **y** input channel specifying which values to sum. If there is not, *sum* will be equivalent to *count*.
15111513

0 commit comments

Comments
 (0)