Skip to content

Commit 0e144f8

Browse files
committed
don’t subgroup if output
1 parent 1f70b72 commit 0e144f8

File tree

3 files changed

+14
-1511
lines changed

3 files changed

+14
-1511
lines changed

src/transforms/bin.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import {bin as binner} from "d3";
2-
import {firstof} from "../defined.js";
32
import {valueof, range, identity, maybeLazyChannel, maybeTransform, maybeTuple, maybeColor, maybeValue, mid, labelof} from "../mark.js";
43
import {offset} from "../style.js";
5-
import {maybeGroup, maybeGroupOutputs, maybeReduce, reduceIdentity} from "./group.js";
4+
import {maybeGroup, maybeOutputs, maybeReduce, maybeSubgroup, reduceIdentity} from "./group.js";
65

76
// Group on {z, fill, stroke}, then optionally on y, then bin x.
87
export function binX(outputs, {inset, insetLeft, insetRight, ...options} = {}) {
@@ -62,7 +61,7 @@ function binn(
6261
bx = maybeBin(bx);
6362
by = maybeBin(by);
6463
reduceData = maybeReduce(reduceData, identity);
65-
outputs = maybeGroupOutputs(outputs, inputs);
64+
outputs = maybeOutputs(outputs, inputs);
6665

6766
// Produce x1, x2, y1, and y2 output channels as appropriate (when binning).
6867
const [BX1, setBX1] = maybeLazyChannel(bx);
@@ -98,7 +97,7 @@ function binn(
9897
const Z = valueof(data, z);
9998
const F = valueof(data, vfill);
10099
const S = valueof(data, vstroke);
101-
const G = firstof(Z, F, S);
100+
const G = maybeSubgroup(outputs, Z, F, S);
102101
const groupFacets = [];
103102
const groupData = [];
104103
const GK = K && setGK([]);

src/transforms/group.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function groupn(
3737
inputs = {} // input channels and options
3838
) {
3939
reduceData = maybeReduce(reduceData, identity);
40-
outputs = maybeGroupOutputs(outputs, inputs);
40+
outputs = maybeOutputs(outputs, inputs);
4141

4242
// Produce x and y output channels as appropriate.
4343
const [GX, setGX] = maybeLazyChannel(x);
@@ -67,7 +67,7 @@ function groupn(
6767
const Z = valueof(data, z);
6868
const F = valueof(data, vfill);
6969
const S = valueof(data, vstroke);
70-
const G = firstof(Z, F, S);
70+
const G = maybeSubgroup(outputs, Z, F, S);
7171
const groupFacets = [];
7272
const groupData = [];
7373
const GX = X && setGX([]);
@@ -102,7 +102,7 @@ function groupn(
102102
};
103103
}
104104

105-
export function maybeGroupOutputs(outputs, inputs) {
105+
export function maybeOutputs(outputs, inputs) {
106106
return Object.entries(outputs).map(([name, reduce]) => {
107107
const value = maybeInput(name, inputs);
108108
const reducer = maybeReduce(reduce, value);
@@ -155,6 +155,14 @@ export function maybeReduce(reduce, value) {
155155
throw new Error("invalid reduce");
156156
}
157157

158+
export function maybeSubgroup(outputs, Z, F, S) {
159+
return firstof(
160+
outputs.some(o => o.name === "z") ? undefined : Z,
161+
outputs.some(o => o.name === "fill") ? undefined : F,
162+
outputs.some(o => o.name === "stroke") ? undefined : S
163+
);
164+
}
165+
158166
function reduceFunction(f) {
159167
return {
160168
reduce(I, X) {

0 commit comments

Comments
 (0)