cleanup
authorBen Pfaff <blp@cs.stanford.edu>
Fri, 2 Jan 2026 03:12:22 +0000 (19:12 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Fri, 2 Jan 2026 03:14:51 +0000 (19:14 -0800)
rust/pspp/src/spv/read/legacy_xml.rs

index 6b59198e432bf5bcfaba190dd6243c43dcfb28e0..6f4acfc0ffb4377cfe04cde0223ac7ef7a2bdf6a 100644 (file)
@@ -217,28 +217,53 @@ pub struct Visualization {
 }
 
 impl Visualization {
-    pub fn decode(
+    pub fn decode_series(
         &self,
         data: IndexMap<String, IndexMap<String, Vec<DataValue>>>,
-        mut look: Look,
         warn: &mut dyn FnMut(LegacyXmlWarning),
-    ) -> Result<PivotTable, super::Error> {
-        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<String, IndexMap<String, Vec<DataValue>>>,
+        mut look: Look,
+        warn: &mut dyn FnMut(LegacyXmlWarning),
+    ) -> Result<PivotTable, super::Error> {
+        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<String>,
     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<bool>,
+    #[serde(other)]
+    Other,
 }
 
 #[derive(Deserialize, Debug)]
@@ -1235,12 +1232,6 @@ struct UserSource {
     missing: Option<Missing>,
 }
 
-#[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<bool>,
 }
-
-#[derive(Deserialize, Debug)]
-#[serde(rename_all = "camelCase")]
-struct LayerController {
-    #[serde(rename = "@target")]
-    target: Option<Ref<Label>>,
-}