Skip to content

Commit 8bece3d

Browse files
Filmbostock
andauthored
default outputs for bins (#447)
* default outputs for binX (y:count), binY (x: count), and bin (fill: count) closes #363 Co-authored-by: Mike Bostock <mbostock@gmail.com>
1 parent a82e2fe commit 8bece3d

File tree

6 files changed

+324
-3
lines changed

6 files changed

+324
-3
lines changed

src/transforms/bin.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ import {offset} from "../style.js";
44
import {maybeGroup, maybeOutputs, maybeReduce, maybeSubgroup, reduceIdentity} from "./group.js";
55

66
// Group on {z, fill, stroke}, then optionally on y, then bin x.
7-
export function binX(outputs, {inset, insetLeft, insetRight, ...options} = {}) {
7+
export function binX(outputs = {y: "count"}, {inset, insetLeft, insetRight, ...options} = {}) {
88
let {x, y} = options;
99
x = maybeBinValue(x, options, identity);
1010
([insetLeft, insetRight] = maybeInset(inset, insetLeft, insetRight));
1111
return binn(x, null, null, y, outputs, {inset, insetLeft, insetRight, ...options});
1212
}
1313

1414
// Group on {z, fill, stroke}, then optionally on x, then bin y.
15-
export function binY(outputs, {inset, insetTop, insetBottom, ...options} = {}) {
15+
export function binY(outputs = {x: "count"}, {inset, insetTop, insetBottom, ...options} = {}) {
1616
let {x, y} = options;
1717
y = maybeBinValue(y, options, identity);
1818
([insetTop, insetBottom] = maybeInset(inset, insetTop, insetBottom));
1919
return binn(null, y, x, null, outputs, {inset, insetTop, insetBottom, ...options});
2020
}
2121

2222
// Group on {z, fill, stroke}, then bin on x and y.
23-
export function bin(outputs, {inset, insetTop, insetRight, insetBottom, insetLeft, ...options} = {}) {
23+
export function bin(outputs = {fill: "count"}, {inset, insetTop, insetRight, insetBottom, insetLeft, ...options} = {}) {
2424
const {x, y} = maybeBinValueTuple(options);
2525
([insetTop, insetBottom] = maybeInset(inset, insetTop, insetBottom));
2626
([insetLeft, insetRight] = maybeInset(inset, insetLeft, insetRight));

test/output/randomBins.svg

Lines changed: 74 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)