|
1 | 1 | import {bin as binner, extent, thresholdFreedmanDiaconis, thresholdScott, thresholdSturges, utcTickInterval} from "d3"; |
2 | 2 | import {valueof, range, identity, maybeLazyChannel, maybeTuple, maybeColor, maybeValue, mid, labelof, isTemporal} from "../mark.js"; |
3 | | -import {offset} from "../style.js"; |
4 | 3 | import {basic} from "./basic.js"; |
5 | 4 | import {maybeEvaluator, maybeGroup, maybeOutput, maybeOutputs, maybeReduce, maybeSort, maybeSubgroup, reduceCount, reduceIdentity} from "./group.js"; |
| 5 | +import {maybeInsetX, maybeInsetY} from "./inset.js"; |
6 | 6 |
|
7 | 7 | // Group on {z, fill, stroke}, then optionally on y, then bin x. |
8 | | -export function binX(outputs = {y: "count"}, {inset, insetLeft, insetRight, ...options} = {}) { |
9 | | - let {x, y} = options; |
10 | | - x = maybeBinValue(x, options, identity); |
11 | | - ([insetLeft, insetRight] = maybeInset(inset, insetLeft, insetRight)); |
12 | | - return binn(x, null, null, y, outputs, {inset, insetLeft, insetRight, ...options}); |
| 8 | +export function binX(outputs = {y: "count"}, options = {}) { |
| 9 | + const {x, y} = options; |
| 10 | + return binn(maybeBinValue(x, options, identity), null, null, y, outputs, maybeInsetX(options)); |
13 | 11 | } |
14 | 12 |
|
15 | 13 | // Group on {z, fill, stroke}, then optionally on x, then bin y. |
16 | | -export function binY(outputs = {x: "count"}, {inset, insetTop, insetBottom, ...options} = {}) { |
17 | | - let {x, y} = options; |
18 | | - y = maybeBinValue(y, options, identity); |
19 | | - ([insetTop, insetBottom] = maybeInset(inset, insetTop, insetBottom)); |
20 | | - return binn(null, y, x, null, outputs, {inset, insetTop, insetBottom, ...options}); |
| 14 | +export function binY(outputs = {x: "count"}, options = {}) { |
| 15 | + const {x, y} = options; |
| 16 | + return binn(null, maybeBinValue(y, options, identity), x, null, outputs, maybeInsetY(options)); |
21 | 17 | } |
22 | 18 |
|
23 | 19 | // Group on {z, fill, stroke}, then bin on x and y. |
24 | | -export function bin(outputs = {fill: "count"}, {inset, insetTop, insetRight, insetBottom, insetLeft, ...options} = {}) { |
| 20 | +export function bin(outputs = {fill: "count"}, options = {}) { |
25 | 21 | const {x, y} = maybeBinValueTuple(options); |
26 | | - ([insetTop, insetBottom] = maybeInset(inset, insetTop, insetBottom)); |
27 | | - ([insetLeft, insetRight] = maybeInset(inset, insetLeft, insetRight)); |
28 | | - return binn(x, y, null, null, outputs, {inset, insetTop, insetRight, insetBottom, insetLeft, ...options}); |
| 22 | + return binn(x, y, null, null, outputs, maybeInsetX(maybeInsetY(options))); |
29 | 23 | } |
30 | 24 |
|
31 | 25 | function binn( |
@@ -252,9 +246,3 @@ function binfilter([{x0, x1}, set]) { |
252 | 246 | function binempty() { |
253 | 247 | return new Uint32Array(0); |
254 | 248 | } |
255 | | - |
256 | | -function maybeInset(inset, inset1, inset2) { |
257 | | - return inset === undefined && inset1 === undefined && inset2 === undefined |
258 | | - ? (offset ? [1, 0] : [0.5, 0.5]) |
259 | | - : [inset1, inset2]; |
260 | | -} |
0 commit comments