From: Ben Pfaff Date: Sun, 4 Jan 2026 00:08:52 +0000 (-0800) Subject: cleanup X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=842ed95b62b16cf9d9d00d18dc94ff2b10f232f7;p=pspp cleanup --- diff --git a/rust/pspp/src/spv/read/legacy_xml.rs b/rust/pspp/src/spv/read/legacy_xml.rs index 4150ab8e21..f669223ca0 100644 --- a/rust/pspp/src/spv/read/legacy_xml.rs +++ b/rust/pspp/src/spv/read/legacy_xml.rs @@ -167,6 +167,42 @@ pub struct Visualization { } impl Visualization { + fn decode_labels(&self, graph: &Graph) -> (Option, Option, pivot::Footnotes) { + let mut labels = EnumMap::from_fn(|_| Vec::new()); + for child in &self.children { + match child { + 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); + } + } + } + _ => (), + } + } + let caption_labels = if !labels[Purpose::SubTitle].is_empty() { + &labels[Purpose::SubTitle] + } else { + &labels[Purpose::Footnote] + }; + + let footnotes = self.decode_footnotes(graph, &labels[Purpose::Footnote]); + ( + LabelFrame::decode_label(&labels[Purpose::Title], &footnotes), + LabelFrame::decode_label(caption_labels, &footnotes), + footnotes, + ) + } fn decode_date(&self) -> Result { NaiveDate::parse_from_str(&self.date, "%Y-%m-%d") .map_err(|_| LegacyXmlWarning::InvalidCreationDate(self.date.clone())) @@ -569,52 +605,24 @@ impl Visualization { } } + pub fn graph(&self) -> Result<&Graph, super::Error> { + for child in &self.children { + match child { + VisChild::Graph(g) => return Ok(g), + _ => (), + } + } + Err(super::Error::LegacyMissingGraph) + } + pub fn decode( &self, binary_data: IndexMap>>>, look: Look, warn: &mut dyn FnMut(LegacyXmlWarning), ) -> Result { - 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 { - return Err(super::Error::LegacyMissingGraph); - }; - - 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 graph = self.graph()?; + let (title, caption, footnotes) = self.decode_labels(graph); let series = self.decode_series(binary_data, warn); let (mut dims, current_layer) = self.decode_dimensions(graph, &series, &footnotes);