From: Ben Pfaff Date: Sun, 4 Jan 2026 00:48:09 +0000 (-0800) Subject: cleanup X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8b18066a69efeb53841899add9cdb8c9913ef3eb;p=pspp cleanup --- diff --git a/rust/pspp/src/output/pivot.rs b/rust/pspp/src/output/pivot.rs index ad9ccaf1c0..e120066de7 100644 --- a/rust/pspp/src/output/pivot.rs +++ b/rust/pspp/src/output/pivot.rs @@ -194,6 +194,14 @@ impl PivotTable { self } + pub fn with_optional_title(self, title: Option) -> 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) -> 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, diff --git a/rust/pspp/src/spv/read/legacy_xml.rs b/rust/pspp/src/spv/read/legacy_xml.rs index 3778e554d5..08bf53706e 100644 --- a/rust/pspp/src/spv/read/legacy_xml.rs +++ b/rust/pspp/src/spv/read/legacy_xml.rs @@ -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, 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::>(), @@ -659,15 +648,9 @@ impl Visualization { .with_data(data) .with_layer(¤t_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)) } }