fix: compute position stacking per-facet-panel instead of globally#245
fix: compute position stacking per-facet-panel instead of globally#245
Conversation
|
Can you update this to always add facet variables to the grouping when stacking. It might be that it makes sense to add these to partition_by early so it is there be default for both stat and position handling |
Done in ff2622f— stacking now always reads facet variables from
Claude considered that but went with reading from (Facet columns do already end up in |
) Stacking `.over()` partitions now include facet columns, so cumulative sums reset within each facet panel. Previously, bars in later panels stacked on top of cumulative values from earlier panels. Also applies to Fill and Center stacking modes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Instead of filtering partition_by for facet-prefixed columns, read facet variables directly from spec.facet.layout.internal_facet_names(). This ensures facet variables are always included in the stacking group when a facet exists. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Dodge and jitter used all partition_by columns (including facet columns) when computing group indices via compute_group_indices(). This inflated n_groups — e.g., 2 fill groups across 2 facet panels were seen as 4 composite groups, making bars too narrow and offsets incorrect. Add non_facet_partition_cols() helper that filters facet columns out of partition_by using spec.facet, and use it in both dodge and jitter. Closes #254 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
46da14e to
7c5011d
Compare
|
The latest commit (7c5011d) extends the facet-panel fix to dodge and jitter. The problem: The fix: Added a shared This is the same pattern as the stacking fix (ff2622f) — position adjustments read facet info from |
Summary
Fixes #244.
Position stacking (cumulative sums) was computed globally across all facet panels, causing bars in later panels to "float" above 0 by stacking on top of cumulative values from earlier panels.
Before: Male panel bars start where female panel bars ended:

After: Each panel stacks independently from 0:
Query:
Changes
src/plot/layer/position/stack.rs: The.over()partition forcum_sumandsumnow includes facet columns (extracted fromlayer.partition_by) in addition to the group column. This ensures stacking resets within each facet panel. Applies to all three stacking modes: Normal, Fill, and Center.src/execute/position.rs: New testtest_stack_resets_per_facet_panelverifies that stacking starts from 0 in each facet panel.Root cause
In
apply_stack, the cumulative sum used.over([col(&group_col)])— partitioning only by the x-axis position. Facet columns were not included, so the cumsum accumulated across all panels as if they were one.Test plan
test_stack_resets_per_facet_panelpassespos2end=0🤖 Generated with Claude Code