Skip to content

Commit ff2622f

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 3667c7c commit ff2622f

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
@@ -270,13 +270,10 @@ fn apply_stack(df: DataFrame, layer: &Layer, spec: &Plot, mode: StackMode) -> Re
270270
// Facet columns must be included so stacking resets per facet panel,
271271
// matching ggplot2 where position adjustments are computed per-panel.
272272
let mut over_cols: Vec<Expr> = vec![col(&group_col)];
273-
for partition_col in &layer.partition_by {
274-
if naming::is_aesthetic_column(partition_col) {
275-
if let Some(aes) = naming::extract_aesthetic_name(partition_col) {
276-
if aes.starts_with("facet") {
277-
over_cols.push(col(partition_col));
278-
}
279-
}
273+
if let Some(ref facet) = spec.facet {
274+
for aes in facet.layout.internal_facet_names() {
275+
let facet_col = naming::aesthetic_column(&aes);
276+
over_cols.push(col(&facet_col));
280277
}
281278
}
282279

0 commit comments

Comments
 (0)