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

index 5a56934d88cc8b73a22b48ef0e6028dc2dfb082a..51e4480e6759c230e80c101b33ad8bc9bc69530c 100644 (file)
@@ -316,7 +316,6 @@ impl Visualization {
     ) -> 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),
@@ -336,24 +335,14 @@ impl Visualization {
                         }
                     }
                 }
-                VisChild::Style(style) => {
-                    if let Some(id) = &style.id {
-                        styles.insert(id.as_str(), style);
-                    }
-                }
-                VisChild::SourceVariable(_) | VisChild::DerivedVariable(_) | VisChild::Other => (),
+                VisChild::Style(_)
+                | VisChild::SourceVariable(_)
+                | VisChild::DerivedVariable(_)
+                | VisChild::Other => (),
             }
         }
         let Some(graph) = graph else { todo!() };
 
-        let axes = graph
-            .facet_layout
-            .children
-            .iter()
-            .filter_map(|child| child.facet_level())
-            .map(|facet_level| (facet_level.level, &facet_level.axis))
-            .collect::<HashMap<_, _>>();
-
         let footnotes = self.decode_footnotes(graph, &labels[Purpose::Footnote]);
 
         let title = LabelFrame::decode_label(&labels[Purpose::Title], &footnotes);
@@ -562,6 +551,19 @@ impl Visualization {
             coordinate: &'a Series,
         }
 
+        let axes = graph
+            .facet_layout
+            .children
+            .iter()
+            .filter_map(|child| child.facet_level())
+            .map(|facet_level| (facet_level.level, &facet_level.axis))
+            .collect::<HashMap<_, _>>();
+        let styles = self
+            .children
+            .iter()
+            .filter_map(|child| child.style())
+            .filter_map(|style| style.id.as_ref().map(|id| (id.as_str(), style)))
+            .collect::<HashMap<_, _>>();
         let mut dims = Vec::new();
         let mut level_ofs = 1;
         let dim_series = graph.faceting.dimensions().map(|axis, dimension| {
@@ -924,6 +926,15 @@ enum VisChild {
     Other,
 }
 
+impl VisChild {
+    fn style(&self) -> Option<&Style> {
+        match self {
+            Self::Style(style) => Some(style),
+            _ => None,
+        }
+    }
+}
+
 #[derive(Deserialize, Debug)]
 #[serde(rename_all = "camelCase")]
 struct SourceVariable {