Skip to content

Commit 490a979

Browse files
committed
fix: special case so the groupBy field must be included when using an impute transform
1 parent 3e8d9b9 commit 490a979

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/stack.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,21 @@ export function stack(m: Mark | MarkDef, encoding: Encoding<string>): StackPrope
173173
const groupbyChannels: StackProperties['groupbyChannels'] = [];
174174
const groupbyFields: Set<FieldName> = new Set();
175175

176+
const didDisableImpute = stackedFieldDef.impute === null;
177+
const shouldAutoImpute = isPathMark(mark);
178+
176179
if (encoding[dimensionChannel]) {
177180
const dimensionDef = encoding[dimensionChannel];
178181
const dimensionField = isFieldDef(dimensionDef) ? vgField(dimensionDef, {}) : undefined;
179182
const hasSameDimensionAndStackedField = dimensionField && dimensionField === stackedField;
180183

181184
// Only add dimension to groupBy if:
182-
// 1. It's not the same field we're stacking on
183-
// 2. It's not a quantitative field being used for measurement
185+
//1. We're imputing OR
186+
//2a. It's not the same field we're stacking on AND
187+
//2b. It's not a quantitative field used for measurement
184188
const isQuantitativeDimension = isUnbinnedQuantitative(dimensionDef);
185-
const shouldAddGroupBy = !hasSameDimensionAndStackedField && !isQuantitativeDimension;
189+
const shouldAddGroupBy =
190+
(!didDisableImpute && shouldAutoImpute) || (!hasSameDimensionAndStackedField && !isQuantitativeDimension);
186191

187192
if (shouldAddGroupBy) {
188193
groupbyChannels.push(dimensionChannel);
@@ -275,7 +280,7 @@ export function stack(m: Mark | MarkDef, encoding: Encoding<string>): StackPrope
275280
groupbyChannels,
276281
groupbyFields,
277282
fieldChannel,
278-
impute: stackedFieldDef.impute === null ? false : isPathMark(mark),
283+
impute: didDisableImpute ? false : shouldAutoImpute,
279284
stackBy,
280285
offset,
281286
};

0 commit comments

Comments
 (0)