Skip to content

Commit 95cd402

Browse files
committed
fix: special case so the groupBy field must be included when using an impute transform
1 parent da0f19c commit 95cd402

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/stack.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,19 @@ 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 didRequestImpute = stackedFieldDef.impute !== null;
177+
176178
if (encoding[dimensionChannel]) {
177179
const dimensionDef = encoding[dimensionChannel];
178180
const dimensionField = isFieldDef(dimensionDef) ? vgField(dimensionDef, {}) : undefined;
179181
const hasSameDimensionAndStackedField = dimensionField && dimensionField === stackedField;
180182

181183
// 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
184+
//1. We're imputing OR
185+
//2a. It's not the same field we're stacking on AND
186+
//2b. It's not a quantitative field used for measurement
184187
const isQuantitativeDimension = isUnbinnedQuantitative(dimensionDef);
185-
const shouldAddGroupBy = !hasSameDimensionAndStackedField && !isQuantitativeDimension;
188+
const shouldAddGroupBy = didRequestImpute || (!hasSameDimensionAndStackedField && !isQuantitativeDimension);
186189

187190
if (shouldAddGroupBy) {
188191
groupbyChannels.push(dimensionChannel);
@@ -275,7 +278,7 @@ export function stack(m: Mark | MarkDef, encoding: Encoding<string>): StackPrope
275278
groupbyChannels,
276279
groupbyFields,
277280
fieldChannel,
278-
impute: stackedFieldDef.impute === null ? false : isPathMark(mark),
281+
impute: didRequestImpute ? false : isPathMark(mark),
279282
stackBy,
280283
offset,
281284
};

0 commit comments

Comments
 (0)