@@ -177,25 +177,25 @@ export function stack(m: Mark | MarkDef, encoding: Encoding<string>): StackPrope
177
177
const dimensionDef = encoding [ dimensionChannel ] ;
178
178
const dimensionField = isFieldDef ( dimensionDef ) ? vgField ( dimensionDef , { } ) : undefined ;
179
179
const hasSameDimensionAndStackedField = dimensionField && dimensionField === stackedField ;
180
- const isUnbinnedQuant = isUnbinnedQuantitative ( dimensionDef ) ;
180
+ const isDimensionUnbinnedQuant = isUnbinnedQuantitative ( dimensionDef ) ;
181
181
182
182
// Check if both the field channel and dimension channel have unbinned quantitative fields
183
- const isFieldUnbinnedQuant = isUnbinnedQuantitative ( stackedFieldDef ) ;
183
+ const isStackedFieldUnbinnedQuant = isUnbinnedQuantitative ( stackedFieldDef ) ;
184
184
185
- const bothChannelsAreUnbinnedQuantitative = isUnbinnedQuant && isFieldUnbinnedQuant ;
185
+ // Both channels are unbinned quantitative if both the dimension and field channels are unbinned quantitative
186
+ const bothChannelsAreUnbinnedQuantitative = isDimensionUnbinnedQuant && isStackedFieldUnbinnedQuant ;
186
187
187
- // For area charts, we need to ensure we still group by the dimension field
188
- // even if both fields are quantitative (e.g., for cumulative frequency plots)
188
+ // Special case for area charts: they need dimension fields in groupBy even when both fields are quantitative
189
+ // Example use: visualizations like cumulative frequency plots where the area needs to be properly filled
190
+ // Ref STACK_BY_DEFAULT_MARKS and STACKABLE_MARKS
189
191
const isAreaMark = mark === 'area' ;
190
192
191
193
// The core logic: we only add to groupBy when:
192
194
// 1. The dimension field is different from the stacked field (to avoid redundant grouping)
193
195
// 2. AND either:
194
- // a. The dimension field is not an unbinned quantitative field, OR
195
- // b. The field channel is not an unbinned quantitative field, OR
196
- // c. It's an area mark (which needs grouping even with quantitative fields)
197
- const shouldAddToGroupBy =
198
- ! hasSameDimensionAndStackedField && ( ! isUnbinnedQuant || ! bothChannelsAreUnbinnedQuantitative || isAreaMark ) ;
196
+ // a. Not both channels are unbinned quantitative, OR
197
+ // b. It's an area mark (which needs grouping even with quantitative fields)
198
+ const shouldAddToGroupBy = ! hasSameDimensionAndStackedField && ( ! bothChannelsAreUnbinnedQuantitative || isAreaMark ) ;
199
199
200
200
if ( shouldAddToGroupBy ) {
201
201
// avoid grouping by the stacked field
0 commit comments