@@ -173,16 +173,20 @@ 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 = ( ! didDisableImpute && shouldAutoImpute ) || ( ! hasSameDimensionAndStackedField && ! isQuantitativeDimension ) ;
186190
187191 if ( shouldAddGroupBy ) {
188192 groupbyChannels . push ( dimensionChannel ) ;
@@ -275,7 +279,7 @@ export function stack(m: Mark | MarkDef, encoding: Encoding<string>): StackPrope
275279 groupbyChannels,
276280 groupbyFields,
277281 fieldChannel,
278- impute : stackedFieldDef . impute === null ? false : isPathMark ( mark ) ,
282+ impute : didDisableImpute ? false : shouldAutoImpute ,
279283 stackBy,
280284 offset,
281285 } ;
0 commit comments