From 5b9ae1d93ea49a8d6c6779f9443c1af6057e46b1 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 8 May 2026 09:56:53 -0700 Subject: [PATCH] cellStyle --- rust/pspp/src/spv/read/graph.rs | 37 ++++++++++++++++--- rust/pspp/src/spv/read/graph/style.rs | 13 ++++++- .../pspp/src/spv/testdata/graph1.expected.svg | 1 + .../pspp/src/spv/testdata/graph3.expected.svg | 2 + .../pspp/src/spv/testdata/graph4.expected.svg | 2 + 5 files changed, 48 insertions(+), 7 deletions(-) diff --git a/rust/pspp/src/spv/read/graph.rs b/rust/pspp/src/spv/read/graph.rs index 2ed7ea3aa2..a8603e57ef 100644 --- a/rust/pspp/src/spv/read/graph.rs +++ b/rust/pspp/src/spv/read/graph.rs @@ -64,7 +64,7 @@ use crate::{ read::graph::{ format::Formatter, frames::{Component, Frames, Position}, - patterns::{ColoredPattern, Patterns}, + patterns::Patterns, style::{Style, StyleCycle}, }, }, @@ -669,6 +669,13 @@ impl Visualization { let font_height = font_metrics.measure("0")[Axis2::Y]; let mut rect = graph_frame.rect().unwrap(); + let cell_style = graph + .cell_style + .as_deref() + .and_then(|cell_style| styles.get(cell_style)) + .cloned() + .unwrap_or_default(); + let y_axis = axis_domains[Axis3::Y].ticks(); let y_axis_text_width = y_axis .iter() @@ -790,6 +797,25 @@ impl Visualization { for (y_index, y_facet) in y_facets.clone().enumerate() { let rect = rect.subrect(x_index, nx_facets, y_index, ny_facets); + if cell_style.color.is_some() { + graph_svg.append( + Rectangle::new() + .set("x", rect.0[Axis2::X].0) + .set("y", rect.0[Axis2::Y].0) + .set("width", rect.0[Axis2::X].length()) + .set("height", rect.0[Axis2::Y].length()) + .set("fill", cell_style.fill(&mut patterns)) + .set( + "stroke", + cell_style + .color2 + .unwrap_or(Color::BLACK) + .display_css() + .to_string(), + ), + ); + } + for element in &elements { let mut categoricals = IndexMap::new(); let mut color_index = None; @@ -917,11 +943,7 @@ impl Visualization { let color = style.color.unwrap_or(Color::BLACK); let color2 = style.color2.unwrap_or(Color::BLACK); - let pattern = patterns.insert(ColoredPattern { - index: style.pattern.unwrap_or_default(), - color, - color2: style.color2.unwrap_or(Color::WHITE), - }); + let pattern = style.fill(&mut patterns); fn points( rect: &Rect, @@ -2822,6 +2844,9 @@ struct Graph { #[serde(rename = "@id")] id: Option, + #[serde(rename = "@cellStyle")] + cell_style: Option, + #[serde(rename = "$value")] children: Vec, } diff --git a/rust/pspp/src/spv/read/graph/style.rs b/rust/pspp/src/spv/read/graph/style.rs index 83ed4074ef..44993c5e22 100644 --- a/rust/pspp/src/spv/read/graph/style.rs +++ b/rust/pspp/src/spv/read/graph/style.rs @@ -5,7 +5,10 @@ use crate::{ Length, look::{Color, HorzAlign, VertAlign}, }, - spv::read::graph::{LocationLength, LocationLengthRange}, + spv::read::graph::{ + LocationLength, LocationLengthRange, + patterns::{ColoredPattern, Patterns}, + }, }; #[derive(Clone, Deserialize, Debug)] @@ -197,6 +200,14 @@ impl Style { TextAlignment::Mixed => None, } } + + pub fn fill(&self, patterns: &mut Patterns) -> String { + patterns.insert(ColoredPattern { + index: self.pattern.unwrap_or_default(), + color: self.color.unwrap_or(Color::BLACK), + color2: self.color2.unwrap_or(Color::WHITE), + }) + } } #[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize)] diff --git a/rust/pspp/src/spv/testdata/graph1.expected.svg b/rust/pspp/src/spv/testdata/graph1.expected.svg index 13f5d1ed41..6494e8b6b4 100644 --- a/rust/pspp/src/spv/testdata/graph1.expected.svg +++ b/rust/pspp/src/spv/testdata/graph1.expected.svg @@ -64,6 +64,7 @@ X Axis Y Axis + diff --git a/rust/pspp/src/spv/testdata/graph3.expected.svg b/rust/pspp/src/spv/testdata/graph3.expected.svg index a64b0ace26..47a964691a 100644 --- a/rust/pspp/src/spv/testdata/graph3.expected.svg +++ b/rust/pspp/src/spv/testdata/graph3.expected.svg @@ -56,10 +56,12 @@ Percent Percent + + diff --git a/rust/pspp/src/spv/testdata/graph4.expected.svg b/rust/pspp/src/spv/testdata/graph4.expected.svg index 099f3f9e6a..2d277fd075 100644 --- a/rust/pspp/src/spv/testdata/graph4.expected.svg +++ b/rust/pspp/src/spv/testdata/graph4.expected.svg @@ -39,12 +39,14 @@ 0.0 + + -- 2.47.3