Skip to content

Commit 6796f6b

Browse files
cpsievertclaude
andcommitted
fix: always add facet variables to stacking group from spec.facet
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>
1 parent 0a634b4 commit 6796f6b

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

src/execute/position.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ pub fn apply_position_adjustments(
5858
#[cfg(test)]
5959
mod tests {
6060
use super::*;
61+
use crate::plot::facet::{Facet, FacetLayout};
6162
use crate::plot::layer::{Geom, Position};
6263
use crate::plot::{AestheticValue, Mappings, ParameterValue, Scale, ScaleType};
6364
use polars::prelude::*;
@@ -375,6 +376,9 @@ mod tests {
375376
let mut spec = Plot::new();
376377
spec.scales.push(make_discrete_scale("pos1"));
377378
spec.scales.push(make_continuous_scale("pos2"));
379+
spec.facet = Some(Facet::new(FacetLayout::Wrap {
380+
variables: vec!["facet_var".to_string()],
381+
}));
378382
let mut data_map = HashMap::new();
379383
data_map.insert("__ggsql_layer_0__".to_string(), df);
380384

src/plot/layer/position/stack.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,10 @@ fn apply_stack(df: DataFrame, layer: &Layer, spec: &Plot, mode: StackMode) -> Re
267267
// Facet columns must be included so stacking resets per facet panel,
268268
// matching ggplot2 where position adjustments are computed per-panel.
269269
let mut over_cols: Vec<Expr> = vec![col(&group_col)];
270-
for partition_col in &layer.partition_by {
271-
if naming::is_aesthetic_column(partition_col) {
272-
if let Some(aes) = naming::extract_aesthetic_name(partition_col) {
273-
if aes.starts_with("facet") {
274-
over_cols.push(col(partition_col));
275-
}
276-
}
270+
if let Some(ref facet) = spec.facet {
271+
for aes in facet.layout.internal_facet_names() {
272+
let facet_col = naming::aesthetic_column(&aes);
273+
over_cols.push(col(&facet_col));
277274
}
278275
}
279276

0 commit comments

Comments
 (0)