cleanup
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 4 Jan 2026 00:48:09 +0000 (16:48 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 4 Jan 2026 00:48:09 +0000 (16:48 -0800)
rust/pspp/src/output/pivot.rs
rust/pspp/src/spv/read/legacy_xml.rs

index ad9ccaf1c0edb9a845b1fba05f6868d1e008688b..e120066de7a3f415979e16a5986fa03fc2db8ee9 100644 (file)
@@ -194,6 +194,14 @@ impl PivotTable {
         self
     }
 
+    pub fn with_optional_title(self, title: Option<Value>) -> Self {
+        if let Some(title) = title {
+            self.with_title(title)
+        } else {
+            self
+        }
+    }
+
     /// Returns this pivot table with the given `caption`.
     ///
     /// The caption is displayed below the pivot table.  Captions are optional.
@@ -203,6 +211,14 @@ impl PivotTable {
         self
     }
 
+    pub fn with_optional_caption(self, caption: Option<Value>) -> Self {
+        if let Some(caption) = caption {
+            self.with_caption(caption)
+        } else {
+            self
+        }
+    }
+
     /// Returns this pivot table with the given `corner_text`.
     ///
     /// The corner text is displayed in the top-left corner of the pivot table,
index 3778e554d5dd0e147c18951b2b34fd5848a0fa5b..08bf53706e7a329f3639411f541d4c616326c4ed 100644 (file)
@@ -339,7 +339,6 @@ impl Visualization {
         &self,
         graph: &Graph,
         footnotes: &pivot::Footnotes,
-        cell_footnotes: Option<&Series>,
         dims: &[Dim],
         series: &BTreeMap<&str, Series>,
         warn: &mut dyn FnMut(LegacyXmlWarning),
@@ -367,6 +366,7 @@ impl Visualization {
         let mut data = HashMap::new();
         let mut coords = Vec::with_capacity(dims.len());
         let cell_formats = graph.interval.labeling.decode_format_map(&series);
+        let cell_footnotes = series.get("footnotes");
         'outer: for (i, cell) in cell.values.iter().enumerate() {
             coords.clear();
             for dim in dims {
@@ -426,9 +426,9 @@ impl Visualization {
         dims: &mut [Dim],
         data: &mut HashMap<Vec<usize>, Value>,
         footnotes: &pivot::Footnotes,
-        cell_footnotes: Option<&Series>,
         warn: &mut dyn FnMut(LegacyXmlWarning),
     ) {
+        let has_cell_footnotes = series.contains_key("footnotes");
         for scp in graph
             .facet_layout
             .children
@@ -582,7 +582,7 @@ impl Visualization {
                                 dims,
                                 data,
                                 &footnotes,
-                                cell_footnotes.is_some(),
+                                has_cell_footnotes,
                             );
                         }
                     }
@@ -601,7 +601,7 @@ impl Visualization {
                                 None,
                                 &look.areas[Area::Data(RowParity::Even)],
                                 &footnotes,
-                                cell_footnotes.is_some(),
+                                has_cell_footnotes,
                             );
                         }
                     }
@@ -632,24 +632,13 @@ impl Visualization {
         let series = self.decode_series(binary_data, warn);
         let (mut dims, current_layer) = self.decode_dimensions(graph, &series, &footnotes);
 
-        let cell_footnotes = graph
-            .interval
-            .footnotes(true)
-            .and_then(|footnotes| series.get(footnotes.variable.as_str()));
-        let mut data = self.decode_data(graph, &footnotes, cell_footnotes, &dims, &series, warn);
+        let mut data = self.decode_data(graph, &footnotes, &dims, &series, warn);
 
         Self::decode_styles(
-            graph,
-            &look,
-            &series,
-            &mut dims,
-            &mut data,
-            &footnotes,
-            cell_footnotes,
-            warn,
+            graph, &look, &series, &mut dims, &mut data, &footnotes, warn,
         );
 
-        let mut pivot_table = PivotTable::new(
+        Ok(PivotTable::new(
             dims.into_iter()
                 .map(|dim| (dim.axis, dim.dimension))
                 .collect::<Vec<_>>(),
@@ -659,15 +648,9 @@ impl Visualization {
         .with_data(data)
         .with_layer(&current_layer)
         .with_decimal(Decimal::for_lang(&self.lang))
-        .with_date(self.decode_date(warn));
-
-        if let Some(title) = title {
-            pivot_table = pivot_table.with_title(title);
-        }
-        if let Some(caption) = caption {
-            pivot_table = pivot_table.with_caption(caption);
-        }
-        Ok(pivot_table)
+        .with_date(self.decode_date(warn))
+        .with_optional_title(title)
+        .with_optional_caption(caption))
     }
 }