From e2a61a260c367d07355b3d93f13f80b938fe2938 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 24 Jun 2026 08:04:08 -0700 Subject: [PATCH] bug fixes --- rust/pspp/src/spv/read/graph.rs | 68 ++++++++++++++++++++------- rust/pspp/src/spv/testdata/graph5.xml | 6 +-- 2 files changed, 54 insertions(+), 20 deletions(-) diff --git a/rust/pspp/src/spv/read/graph.rs b/rust/pspp/src/spv/read/graph.rs index a384616ede..19ad654079 100644 --- a/rust/pspp/src/spv/read/graph.rs +++ b/rust/pspp/src/spv/read/graph.rs @@ -778,7 +778,7 @@ impl Visualization { .set("c:description", "X axis facets above graph") .set( "transform", - format!("translate({} {})", rect.0[Axis2::X].0, rect.0[Axis2::Y].0), + format!("translate({} {})", inner.0[Axis2::X].0, rect.0[Axis2::Y].0), ); let bottom = x_headings .render(Side::Bottom) @@ -5094,15 +5094,17 @@ impl<'a> FacetHeadings<'a> { fn render(&self, side: Side) -> Group { let span = Span(0.0, self.width).subdivide(self.n_facets, 5.0); let mut group = Group::new(); + /* group.append( - Rect(enum_map! { - Axis2::X => Span(0.0, self.width), - Axis2::Y => Span(0.0, self.height(side)) - }) - .as_svg() - .set("fill", "blue"), - );*/ + Rect(enum_map! { + Axis2::X => Span(0.0, self.width), + Axis2::Y => Span(0.0, self.height(side)) + }) + .as_svg() + .set("fill", "none") + .set("stroke", "red"), + );*/ let mut y = 0.0; for axis in self.axes.iter().filter(|axis| axis.side == side) { if dbg!(axis.axis.combine_axis_labels) { @@ -5126,16 +5128,48 @@ impl<'a> FacetHeadings<'a> { }; y += axis.height; } - for height in self.facets.iter().filter(|height| height.side == side) { + let heights = self + .facets + .iter() + .rev() + .filter(|height| height.side == side); + let parents = std::iter::once(None).chain(heights.clone().map(Some)); + for (height, parent) in zip(heights, parents) { if let Some(axis_label) = height.row.axis_label() { - dbg!(&axis_label); - group.append( - svg::node::element::Text::new(axis_label) - .set("x", self.width / 2.0) - .set("y", y) - .set("dominant-baseline", "hanging") - .set("text-anchor", "middle"), - ); + let parent = if let Some(facet_level) = height.row.facet_level + && !facet_level.axis.combine_axis_labels + { + parent + } else { + None + }; + + match parent { + Some(parent) => { + // XXX the corresponding code for measurement in + // FacetHeading::new doesn't use the right width for + // this case. + for column in &parent.row.columns { + let span = span.range(&column.columns); + group.append( + svg::node::element::Text::new(&axis_label) + .set("x", span.midpoint()) + .set("y", y) + .set("dominant-baseline", "hanging") + .set("text-anchor", "middle"), + ); + } + } + None => { + group.append( + svg::node::element::Text::new(axis_label) + .set("x", self.width / 2.0) + .set("y", y) + .set("dominant-baseline", "hanging") + .set("text-anchor", "middle"), + ); + } + } } y += height.axis_label_height; diff --git a/rust/pspp/src/spv/testdata/graph5.xml b/rust/pspp/src/spv/testdata/graph5.xml index 4f06ca6e33..ef25f454d0 100644 --- a/rust/pspp/src/spv/testdata/graph5.xml +++ b/rust/pspp/src/spv/testdata/graph5.xml @@ -63,14 +63,14 @@ - + - + - + -- 2.47.3