From ad6e7d24d7f5fb9d88f9d55d25760521499341ba Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 14 Jul 2026 15:06:01 -0700 Subject: [PATCH] properly fix x-axis labeling --- rust/pspp/src/spv/read/graph.rs | 21 +++++++++---------- .../pspp/src/spv/testdata/graph5.expected.svg | 8 +++---- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/rust/pspp/src/spv/read/graph.rs b/rust/pspp/src/spv/read/graph.rs index 78699f82ff..dabe3ab6c9 100644 --- a/rust/pspp/src/spv/read/graph.rs +++ b/rust/pspp/src/spv/read/graph.rs @@ -49,7 +49,7 @@ use svg::{ }; use crate::{ - data::{Datum, OwnedDatum}, + data::Datum, format::{Type, UncheckedFormat}, locale::{Item, Locale, data::EN}, output::{ @@ -675,7 +675,7 @@ impl Visualization { &mut axis_domains, styles, )?; - dbg!(&axis_domains); + //dbg!(&axis_domains); let elements = self.pass( &graph, locale, @@ -685,7 +685,7 @@ impl Visualization { &mut axis_domains, styles, )?; - dbg!(&axis_domains); + //dbg!(&axis_domains); let font_metrics = FontMetrics::new(); let font_height = font_metrics.measure("0")[Axis2::Y]; @@ -1682,6 +1682,7 @@ impl<'a> AxisDomain<'a> { } } fn ticks(&self) -> Vec<(f64, String)> { + dbg!(&self.domain); let mut ticks = Vec::new(); match &self.domain { Domain::Interval { @@ -1714,21 +1715,19 @@ impl<'a> AxisDomain<'a> { if self.domain.lookup(value).is_some() { let left = index as f64 / values.len() as f64; let right = (index + 1) as f64 / values.len() as f64; - let value = left.midpoint(right); + let fraction = left.midpoint(right); ticks.push(( - value, - label.clone().unwrap_or({ - self.formatter - .display(&OwnedDatum::Number(Some(value))) - .to_string() - }), + fraction, + label + .clone() + .unwrap_or_else(|| self.formatter.display(value).to_string()), )); } } } _ => (), }; - ticks + dbg!(ticks) } } diff --git a/rust/pspp/src/spv/testdata/graph5.expected.svg b/rust/pspp/src/spv/testdata/graph5.expected.svg index 07bf487766..4afd31b926 100644 --- a/rust/pspp/src/spv/testdata/graph5.expected.svg +++ b/rust/pspp/src/spv/testdata/graph5.expected.svg @@ -50,16 +50,16 @@ V11-2 -.25 +101.10 -.75 +102.10 -.25 +101.10 -.75 +102.10 Variable 4 -- 2.47.3