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

index a8548ed2a683e0efd8579026d9bd688d9b86c952..e45dd21c88fde269ee5df8536030d4358e3adcf9 100644 (file)
@@ -38,10 +38,7 @@ use crate::{
     format::{self, Decimal, F8_0, F40_2, Type, UncheckedFormat},
     output::pivot::{
         self, Axis2, Axis3, Category, CategoryLocator, Dimension, Group, Leaf, Length, PivotTable,
-        look::{
-            self, Area, AreaStyle, CellStyle, Color, HeadingRegion, HorzAlign, Look, RowParity,
-            VertAlign,
-        },
+        look::{self, Area, AreaStyle, CellStyle, Color, HorzAlign, Look, RowParity, VertAlign},
         value::Value,
     },
     spv::read::legacy_bin::DataValue,
@@ -314,7 +311,7 @@ impl Visualization {
     pub fn decode(
         &self,
         data: IndexMap<String, IndexMap<String, Vec<DataValue>>>,
-        mut look: Look,
+        look: Look,
         warn: &mut dyn FnMut(LegacyXmlWarning),
     ) -> Result<PivotTable, super::Error> {
         let mut graph = None;
@@ -349,36 +346,23 @@ impl Visualization {
         }
         let Some(graph) = graph else { todo!() };
 
-        let mut axes = HashMap::new();
-        for child in &graph.facet_layout.children {
-            if let FacetLayoutChild::FacetLevel(facet_level) = child {
-                axes.insert(facet_level.level, &facet_level.axis);
-            }
-        }
+        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);
-        let mut caption_labels = &labels[Purpose::SubTitle];
-        if caption_labels.is_empty() {
-            caption_labels = &labels[Purpose::Footnote];
-        }
-        let caption = LabelFrame::decode_label(&caption_labels, &footnotes);
-
-        if let Some(style) = styles.get(graph.cell_style.references.as_str())
-            && let Some(width) = &style.width
-        {
-            let mut parts = width.split(';');
-            parts.next();
-            if let Some(min_width) = parts.next()
-                && let Some(max_width) = parts.next()
-                && let Ok(min_width) = min_width.parse::<Length>()
-                && let Ok(max_width) = max_width.parse::<Length>()
-            {
-                look.heading_widths[HeadingRegion::Columns] =
-                    min_width.as_pt_f64() as isize..=max_width.as_pt_f64() as isize;
-            }
-        }
+        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);
 
@@ -880,7 +864,7 @@ impl Visualization {
                         for target in &targets {
                             target.decode(
                                 intersect,
-                                &mut look,
+                                &look,
                                 &series,
                                 dims.as_mut_slice(),
                                 &mut data,
@@ -1557,9 +1541,6 @@ struct Style {
     #[serde(rename = "@labelLocationVertical")]
     label_location_vertical: Option<LabelLocation>,
 
-    #[serde(rename = "@width")]
-    width: Option<String>,
-
     #[serde(rename = "@visible")]
     visible: Option<bool>,
 
@@ -1787,9 +1768,6 @@ impl From<LabelLocation> for VertAlign {
 #[derive(Deserialize, Debug)]
 #[serde(rename_all = "camelCase")]
 struct Graph {
-    #[serde(rename = "@cellStyle")]
-    cell_style: Ref<Style>,
-
     faceting: Faceting,
     facet_layout: FacetLayout,
     interval: Interval,
@@ -1901,6 +1879,15 @@ enum FacetLayoutChild {
     Other,
 }
 
+impl FacetLayoutChild {
+    fn facet_level(&self) -> Option<&FacetLevel> {
+        match self {
+            Self::FacetLevel(facet_level) => Some(facet_level),
+            _ => None,
+        }
+    }
+}
+
 #[derive(Deserialize, Debug)]
 #[serde(rename_all = "camelCase")]
 struct SetCellProperties {