Skip to content

Commit 079e698

Browse files
committed
add / explain special case for area marks
1 parent 37e6b0f commit 079e698

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

.cursorignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
docs/*.js
2+
node_modules/# Add directories or file patterns to ignore during indexing (e.g. foo/ or *.csv)

src/stack.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -177,25 +177,25 @@ export function stack(m: Mark | MarkDef, encoding: Encoding<string>): StackPrope
177177
const dimensionDef = encoding[dimensionChannel];
178178
const dimensionField = isFieldDef(dimensionDef) ? vgField(dimensionDef, {}) : undefined;
179179
const hasSameDimensionAndStackedField = dimensionField && dimensionField === stackedField;
180-
const isUnbinnedQuant = isUnbinnedQuantitative(dimensionDef);
180+
const isDimensionUnbinnedQuant = isUnbinnedQuantitative(dimensionDef);
181181

182182
// Check if both the field channel and dimension channel have unbinned quantitative fields
183-
const isFieldUnbinnedQuant = isUnbinnedQuantitative(stackedFieldDef);
183+
const isStackedFieldUnbinnedQuant = isUnbinnedQuantitative(stackedFieldDef);
184184

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;
186187

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
189191
const isAreaMark = mark === 'area';
190192

191193
// The core logic: we only add to groupBy when:
192194
// 1. The dimension field is different from the stacked field (to avoid redundant grouping)
193195
// 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);
199199

200200
if (shouldAddToGroupBy) {
201201
// avoid grouping by the stacked field

0 commit comments

Comments
 (0)