Skip to content

Commit 159ceb8

Browse files
committed
apply maybeReduce to data channel
1 parent d9ad9fa commit 159ceb8

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/transforms/bin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {bin as binner} from "d3";
22
import {firstof} from "../defined.js";
33
import {valueof, range, identity, maybeLazyChannel, maybeTransform, maybeTuple, maybeColor, maybeValue, mid, labelof} from "../mark.js";
44
import {offset} from "../style.js";
5-
import {maybeGroup, maybeGroupOutputs, reduceIdentity} from "./group.js";
5+
import {maybeGroup, maybeGroupOutputs, maybeReduce, reduceIdentity} from "./group.js";
66

77
// Group on {z, fill, stroke}, then optionally on y, then bin x.
88
export function binX(outputs, {inset, insetLeft, insetRight, ...options} = {}) {
@@ -61,6 +61,7 @@ function binn(
6161
) {
6262
bx = maybeBin(bx);
6363
by = maybeBin(by);
64+
reduceData = maybeReduce(reduceData, identity);
6465
outputs = maybeGroupOutputs(outputs, inputs);
6566

6667
// Produce x1, x2, y1, and y2 output channels as appropriate (when binning).

src/transforms/group.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ export function group(outputs, options = {}) {
3333
function groupn(
3434
x, // optionally group on x
3535
y, // optionally group on y
36-
{data: reduceData = reduceIdentity, ...outputs} = {}, // output channel definitions
36+
{data: reduceData = reduceFirst, ...outputs} = {}, // output channel definitions
3737
inputs = {} // input channels and options
3838
) {
39+
reduceData = maybeReduce(reduceData, identity);
3940
outputs = maybeGroupOutputs(outputs, inputs);
4041

4142
// Produce x and y output channels as appropriate.
@@ -133,7 +134,7 @@ export function maybeGroup(I, X) {
133134
return X ? sort(grouper(I, i => X[i]), first) : [[, I]];
134135
}
135136

136-
function maybeReduce(reduce, value) {
137+
export function maybeReduce(reduce, value) {
137138
if (reduce && typeof reduce.reduce === "function") return reduce;
138139
if (typeof reduce === "function") return reduceFunction(reduce);
139140
switch ((reduce + "").toLowerCase()) {

0 commit comments

Comments
 (0)