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

index ad02c37f658d7c9e02272f464ba29d039dd0a7df..f5f39a3449a4639fa04e4cb21e16264bf9be288b 100644 (file)
@@ -433,60 +433,16 @@ impl Visualization {
         data
     }
 
-    pub fn decode(
-        &self,
-        data: IndexMap<String, IndexMap<String, Vec<DataValue>>>,
-        look: Look,
+    fn decode_styles(
+        graph: &Graph,
+        look: &Look,
+        series: &BTreeMap<&str, Series>,
+        dims: &mut [Dim],
+        data: &mut HashMap<Vec<usize>, Value>,
+        footnotes: &pivot::Footnotes,
+        cell_footnotes: Option<&Series>,
         warn: &mut dyn FnMut(LegacyXmlWarning),
-    ) -> Result<PivotTable, super::Error> {
-        let mut graph = None;
-        let mut labels = EnumMap::from_fn(|_| Vec::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
-                        && let Some(purpose) = label.purpose
-                    {
-                        labels[purpose].push(label);
-                    }
-                }
-                VisChild::Container(c) => {
-                    for label_frame in &c.label_frames {
-                        if let Some(label) = &label_frame.label
-                            && let Some(purpose) = label.purpose
-                        {
-                            labels[purpose].push(label);
-                        }
-                    }
-                }
-                VisChild::Style(_)
-                | VisChild::SourceVariable(_)
-                | VisChild::DerivedVariable(_)
-                | VisChild::Other => (),
-            }
-        }
-        let Some(graph) = graph else { todo!() };
-
-        let footnotes = self.decode_footnotes(graph, &labels[Purpose::Footnote]);
-
-        let title = LabelFrame::decode_label(&labels[Purpose::Title], &footnotes);
-        let caption_labels = if !labels[Purpose::SubTitle].is_empty() {
-            &labels[Purpose::SubTitle]
-        } else {
-            &labels[Purpose::Footnote]
-        };
-        let caption = LabelFrame::decode_label(caption_labels, &footnotes);
-
-        let series = self.decode_series(data, warn);
-        let (mut dims, current_layer) = self.decode_dimensions(graph, &series, &footnotes);
-
-        let cell_footnotes = graph
-            .interval
-            .footnotes()
-            .and_then(|footnotes| series.get(footnotes.variable.as_str()));
-        let mut data = self.decode_data(graph, &footnotes, cell_footnotes, &dims, &series, warn);
-
+    ) {
         for scp in graph
             .facet_layout
             .children
@@ -637,8 +593,8 @@ impl Visualization {
                                 intersect,
                                 &look,
                                 &series,
-                                dims.as_mut_slice(),
-                                &mut data,
+                                dims,
+                                data,
                                 &footnotes,
                                 cell_footnotes.is_some(),
                             );
@@ -666,6 +622,72 @@ impl Visualization {
                 }
             }
         }
+    }
+
+    pub fn decode(
+        &self,
+        data: IndexMap<String, IndexMap<String, Vec<DataValue>>>,
+        look: Look,
+        warn: &mut dyn FnMut(LegacyXmlWarning),
+    ) -> Result<PivotTable, super::Error> {
+        let mut graph = None;
+        let mut labels = EnumMap::from_fn(|_| Vec::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
+                        && let Some(purpose) = label.purpose
+                    {
+                        labels[purpose].push(label);
+                    }
+                }
+                VisChild::Container(c) => {
+                    for label_frame in &c.label_frames {
+                        if let Some(label) = &label_frame.label
+                            && let Some(purpose) = label.purpose
+                        {
+                            labels[purpose].push(label);
+                        }
+                    }
+                }
+                VisChild::Style(_)
+                | VisChild::SourceVariable(_)
+                | VisChild::DerivedVariable(_)
+                | VisChild::Other => (),
+            }
+        }
+        let Some(graph) = graph else { todo!() }; //XXX
+
+        let footnotes = self.decode_footnotes(graph, &labels[Purpose::Footnote]);
+
+        let title = LabelFrame::decode_label(&labels[Purpose::Title], &footnotes);
+        let caption_labels = if !labels[Purpose::SubTitle].is_empty() {
+            &labels[Purpose::SubTitle]
+        } else {
+            &labels[Purpose::Footnote]
+        };
+        let caption = LabelFrame::decode_label(caption_labels, &footnotes);
+
+        let series = self.decode_series(data, warn);
+        let (mut dims, current_layer) = self.decode_dimensions(graph, &series, &footnotes);
+
+        let cell_footnotes = graph
+            .interval
+            .footnotes()
+            .and_then(|footnotes| series.get(footnotes.variable.as_str()));
+        let mut data = self.decode_data(graph, &footnotes, cell_footnotes, &dims, &series, warn);
+
+        Self::decode_styles(
+            graph,
+            &look,
+            &series,
+            &mut dims,
+            &mut data,
+            &footnotes,
+            cell_footnotes,
+            warn,
+        );
 
         let dimensions = dims
             .into_iter()