Skip to content

Commit c59b150

Browse files
committed
Also let PreparedData::Single have metadata field
1 parent 1e4de85 commit c59b150

2 files changed

Lines changed: 21 additions & 15 deletions

File tree

src/writer/vegalite/layer.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ pub fn validate_layer_columns(layer: &Layer, data: &DataFrame, layer_idx: usize)
109109
/// Data prepared for a layer - either single dataset or multiple components
110110
pub enum PreparedData {
111111
/// Standard single dataset (most geoms)
112-
Single { values: Vec<Value> },
112+
Single {
113+
values: Vec<Value>,
114+
metadata: Box<dyn Any + Send + Sync>,
115+
},
113116
/// Multiple component datasets (boxplot, violin, errorbar)
114117
Composite {
115118
components: HashMap<String, Vec<Value>>,
@@ -198,7 +201,7 @@ pub trait GeomRenderer: Send + Sync {
198201
} else {
199202
dataframe_to_values_with_bins(df, binned_columns)?
200203
};
201-
Ok(PreparedData::Single { values })
204+
Ok(PreparedData::Single { values, metadata: Box::new(()) })
202205
}
203206

204207
// === Phase 2: Encoding Modifications ===
@@ -478,16 +481,10 @@ impl GeomRenderer for LineRenderer {
478481

479482
let needs_segmentation = !varying_aesthetics.is_empty();
480483

481-
if needs_segmentation {
482-
// Use Composite with empty component name so dataset key = data_key (not data_key + suffix)
483-
// This ensures the source filter works correctly with the unified dataset
484-
Ok(PreparedData::Composite {
485-
components: [("".to_string(), values)].iter().cloned().collect(),
486-
metadata: Box::new(()),
487-
})
488-
} else {
489-
Ok(PreparedData::Single { values })
490-
}
484+
Ok(PreparedData::Single {
485+
values,
486+
metadata: Box::new(needs_segmentation),
487+
})
491488
}
492489

493490
fn modify_encoding(
@@ -512,10 +509,19 @@ impl GeomRenderer for LineRenderer {
512509
_data_key: &str,
513510
prepared: &PreparedData,
514511
) -> Result<Vec<Value>> {
512+
// Check if segmentation is needed via metadata
513+
let PreparedData::Single { metadata, .. } = prepared else {
514+
return Err(GgsqlError::InternalError(
515+
"LineRenderer expects PreparedData::Single".to_string(),
516+
));
517+
};
518+
519+
let needs_segmentation = metadata.downcast_ref::<bool>() == Some(&true);
520+
515521
// Early return for standard line rendering
516-
let PreparedData::Composite { .. } = prepared else {
522+
if !needs_segmentation {
517523
return Ok(vec![layer_spec]);
518-
};
524+
}
519525

520526
// Get position column names
521527
let x_col = naming::aesthetic_column("pos1");

src/writer/vegalite/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ fn prepare_layer_data(
101101

102102
// Add data to individual datasets based on prepared type
103103
match &prepared {
104-
PreparedData::Single { values } => {
104+
PreparedData::Single { values, .. } => {
105105
individual_datasets.insert(data_key.clone(), json!(values));
106106
}
107107
PreparedData::Composite { components, .. } => {

0 commit comments

Comments
 (0)