From: Ben Pfaff Date: Fri, 2 Jan 2026 03:12:22 +0000 (-0800) Subject: cleanup X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f00de82da8c634cf00aa9e153b6be731d73ba43f;p=pspp cleanup --- diff --git a/rust/pspp/src/spv/read/legacy_xml.rs b/rust/pspp/src/spv/read/legacy_xml.rs index 6b59198e43..6f4acfc0ff 100644 --- a/rust/pspp/src/spv/read/legacy_xml.rs +++ b/rust/pspp/src/spv/read/legacy_xml.rs @@ -217,28 +217,53 @@ pub struct Visualization { } impl Visualization { - pub fn decode( + pub fn decode_series( &self, data: IndexMap>>, - mut look: Look, warn: &mut dyn FnMut(LegacyXmlWarning), - ) -> Result { - let mut extension = None; + ) -> BTreeMap<&str, Series> { let mut source_variables = Vec::new(); let mut derived_variables = Vec::new(); - let mut graph = None; - let mut labels = EnumMap::from_fn(|_| Vec::new()); - let mut styles = HashMap::new(); - let mut _layer_controller = None; for child in &self.children { match child { - VisChild::Extension(e) => extension = Some(e), - VisChild::UserSource(_) => (), VisChild::SourceVariable(source_variable) => source_variables.push(source_variable), VisChild::DerivedVariable(derived_variable) => { derived_variables.push(derived_variable) } - VisChild::CategoricalDomain(_) => (), + _ => (), + } + } + let mut series = BTreeMap::<&str, Series>::new(); + while let n = source_variables.len() + derived_variables.len() + && n > 0 + { + source_variables.retain(|sv| !sv.decode(&data, &mut series)); + derived_variables.retain(|dv| !dv.decode(&mut series, warn)); + + if n == source_variables.len() + derived_variables.len() { + warn(LegacyXmlWarning::UnresolvedDependencies( + source_variables + .iter() + .map(|sv| sv.variable.clone()) + .chain(derived_variables.iter().map(|dv| dv.id.clone())) + .collect(), + )); + } + } + series + } + + pub fn decode( + &self, + data: IndexMap>>, + mut look: Look, + warn: &mut dyn FnMut(LegacyXmlWarning), + ) -> Result { + let mut graph = None; + let mut labels = EnumMap::from_fn(|_| Vec::new()); + let mut styles = HashMap::new(); + for child in &self.children { + match child { VisChild::Graph(g) => graph = Some(g), VisChild::LabelFrame(label_frame) => { if let Some(label) = &label_frame.label @@ -261,7 +286,7 @@ impl Visualization { styles.insert(id.as_str(), style); } } - VisChild::LayerController(lc) => _layer_controller = Some(lc), + VisChild::SourceVariable(_) | VisChild::DerivedVariable(_) | VisChild::Other => (), } } let Some(graph) = graph else { todo!() }; @@ -338,9 +363,6 @@ impl Visualization { } let caption = LabelFrame::decode_label(&caption_labels, &footnotes); - let _show_grid_lines = extension - .as_ref() - .and_then(|extension| extension.show_gridline); if let Some(style) = styles.get(graph.cell_style.references.as_str()) && let Some(width) = &style.width { @@ -356,23 +378,7 @@ impl Visualization { } } - let mut series = BTreeMap::<&str, Series>::new(); - while let n = source_variables.len() + derived_variables.len() - && n > 0 - { - source_variables.retain(|sv| !sv.decode(&data, &mut series)); - derived_variables.retain(|dv| !dv.decode(&mut series, warn)); - - if n == source_variables.len() + derived_variables.len() { - warn(LegacyXmlWarning::UnresolvedDependencies( - source_variables - .iter() - .map(|sv| sv.variable.clone()) - .chain(derived_variables.iter().map(|dv| dv.id.clone())) - .collect(), - )); - } - } + let series = self.decode_series(data, warn); fn decode_dimension<'a>( variables: &[(&'a Series, usize)], @@ -974,7 +980,7 @@ impl Visualization { } } -struct Series { +pub struct Series { name: String, label: Option, format: crate::format::Format, @@ -1039,23 +1045,14 @@ impl Series { #[derive(Deserialize, Debug)] #[serde(rename_all = "camelCase")] enum VisChild { - Extension(VisualizationExtension), - UserSource(UserSource), SourceVariable(SourceVariable), DerivedVariable(DerivedVariable), - CategoricalDomain(CategoricalDomain), Graph(Graph), LabelFrame(LabelFrame), Container(Container), Style(Style), - LayerController(LayerController), -} - -#[derive(Deserialize, Debug)] -#[serde(rename = "extension", rename_all = "camelCase")] -struct VisualizationExtension { - #[serde(rename = "@showGridline")] - show_gridline: Option, + #[serde(other)] + Other, } #[derive(Deserialize, Debug)] @@ -1235,12 +1232,6 @@ struct UserSource { missing: Option, } -#[derive(Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct CategoricalDomain { - variable_reference: VariableReference, -} - #[derive(Deserialize, Debug)] #[serde(rename_all = "camelCase")] struct VariableReference { @@ -2783,10 +2774,3 @@ struct ContainerExtension { #[serde(rename = "@combinedFootnotes")] combined_footnotes: Option, } - -#[derive(Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct LayerController { - #[serde(rename = "@target")] - target: Option>, -}