]> pintos-os.org Git - pspp/commitdiff
cellStyle
authorBen Pfaff <blp@cs.stanford.edu>
Fri, 8 May 2026 16:56:53 +0000 (09:56 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Fri, 8 May 2026 16:56:53 +0000 (09:56 -0700)
rust/pspp/src/spv/read/graph.rs
rust/pspp/src/spv/read/graph/style.rs
rust/pspp/src/spv/testdata/graph1.expected.svg
rust/pspp/src/spv/testdata/graph3.expected.svg
rust/pspp/src/spv/testdata/graph4.expected.svg

index 2ed7ea3aa255d2bed292f15ab91be0f7031857dd..a8603e57ef36dfcca0a21a2c852ee20220de56fc 100644 (file)
@@ -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<String>,
 
+    #[serde(rename = "@cellStyle")]
+    cell_style: Option<String>,
+
     #[serde(rename = "$value")]
     children: Vec<GraphChild>,
 }
index 83ed4074efa86e948cd39b17243249780ecafd8e..44993c5e22e79fe95b3512d8b13be97c4915c447 100644 (file)
@@ -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)]
index 13f5d1ed41c4bee025abef34d5868c938a9a2a6a..6494e8b6b4f2d4cc4c9939da55630a12d2bb8036 100644 (file)
@@ -64,6 +64,7 @@ X Axis
 <text dominant-baseline="hanging" text-anchor="middle" transform="rotate(-90, 6.25, 245)" x="6.25" y="245">
 Y Axis
 </text>
+<rect fill="#f0f0f0" height="388" stroke="#000000" width="557.5" x="61.25" y="51"/>
 <g id="element_simpleline_1">
 <path d="M618.75,51 L590.875,51 L563,51 L563,69.47619 L535.125,69.47619 L535.125,87.95238 L507.25,87.95238 L479.375,87.95238 L479.375,106.42857 L451.5,106.42857 L423.625,106.42857 L395.75,106.42857 L367.875,106.42857 L340,106.42857 L312.125,106.42857 L312.125,124.90476 L284.25,124.90476 L284.25,143.38095 L256.375,143.38095 L228.5,143.38095 L200.625,143.38095 L200.625,161.85715 L200.625,180.33333 L200.625,198.80952 L172.75,198.80952 L172.75,217.28572 L172.75,235.7619 L172.75,254.2381 L172.75,272.7143 L172.75,291.1905 L144.875,291.1905 L144.875,309.66666 L117,309.66666 L89.125,309.66666 L89.125,328.14285 L89.125,346.61905 L89.125,365.09525 L89.125,383.57144 L89.125,402.0476 L89.125,420.5238 L89.125,439 L61.25,439" fill="none" stroke="#3e58ac"/>
 </g>
index a64b0ace26a8469921af27f105becb3570fc74b8..47a964691a5635a995dd2bdaee7aef0dd8fdaa5a 100644 (file)
@@ -56,10 +56,12 @@ Percent
 <text dominant-baseline="hanging" text-anchor="middle" transform="rotate(-90, 6.25, 331.75)" x="6.25" y="331.75">
 Percent
 </text>
+<rect fill="#f0f0f0" height="214.5" stroke="#000000" width="548.5" x="70.25" y="5"/>
 <g id="element_bar_1">
 <rect fill="url(#pattern12_d3ce97_000000)" height="92.56696428571429" stroke="#000000" width="205.6875" x="104.53125" y="126.93303571428571"/>
 <rect fill="url(#pattern12_d3ce97_000000)" height="204.2857142857143" stroke="#000000" width="205.6875" x="378.78125" y="15.214285714285701"/>
 </g>
+<rect fill="#f0f0f0" height="214.5" stroke="#000000" width="548.5" x="70.25" y="224.5"/>
 <g id="element_bar_1">
 <rect fill="url(#pattern12_d3ce97_000000)" height="121.29464285714289" stroke="#000000" width="205.6875" x="104.53125" y="317.7053571428571"/>
 <rect fill="url(#pattern12_d3ce97_000000)" height="127.67857142857144" stroke="#000000" width="205.6875" x="378.78125" y="311.32142857142856"/>
index 099f3f9e6accbc358d68acbde26a6b4836a8282e..2d277fd075f63f74474bba3a5219ada4e718a6f0 100644 (file)
 <text dominant-baseline="middle" text-anchor="end" x="28.25" y="NaN">
 0.0
 </text>
+<rect fill="rgb(0, 0, 0, 0.00)" height="226" stroke="rgb(0, 0, 0, 0.00)" width="430.5" x="38.25" y="5"/>
 <g id="element_element_1">
 <rect fill="#3e58ac" height="113" stroke="#000000" width="1" x="246.55645161290323" y="118"/>
 </g>
 <g id="element_element_1">
 <rect fill="#2eb848" height="113" stroke="#000000" width="1" x="191.00806451612905" y="118"/>
 </g>
+<rect fill="rgb(0, 0, 0, 0.00)" height="226" stroke="rgb(0, 0, 0, 0.00)" width="430.5" x="38.25" y="236"/>
 <g id="element_element_1">
 <rect fill="#2eb848" height="113" stroke="#000000" width="1" x="468.75" y="349"/>
 </g>