]> pintos-os.org Git - pspp/commitdiff
bar graphs starting to look pretty OK
authorBen Pfaff <blp@cs.stanford.edu>
Thu, 7 May 2026 20:39:34 +0000 (13:39 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Thu, 7 May 2026 20:39:34 +0000 (13:39 -0700)
rust/pspp/src/spv/read/graph.rs
rust/pspp/src/spv/testdata/graph3.expected.svg

index ea8240ae4ad56d5acd01d82100ac82785d9fc774..2cd3b32fb36f195891cf28e4e2ee0c685c2b71b6 100644 (file)
@@ -885,54 +885,37 @@ impl Visualization {
                             .push(values);
                     }
                     for (categoricals, group) in &grouped_data {
-                        let mut color = Color::BLACK;
-                        if let Some(style_color) = element.style.color {
-                            color = style_color;
-                        }
-                        if let Some(color_index) = color_index {
-                            let index = categoricals[color_index]
-                                .as_number()
-                                .unwrap_or_default()
-                                .unwrap_or_default();
-                            let index = <usize as NumCast>::from(index).unwrap_or_default();
-                            color = PALETTE[index % PALETTE.len()];
-                        }
+                        let mut style = element.style.clone().into_owned();
                         if let Some((index, style_cycle)) = styling {
                             let index = categoricals[index]
                                 .as_number()
                                 .unwrap_or_default()
                                 .unwrap_or_default();
                             let index = <usize as NumCast>::from(index).unwrap_or_default();
-                            let style = style_cycle.get_style(index);
-                            if let Some(style_color) = style.color {
-                                color = style_color;
+                            for s in style_cycle.get_style_components(index) {
+                                style = style.overridden_with(s);
                             }
                         }
-
-                        let mut color2 = Color::BLACK;
-                        if let Some(style_color) = element.style.color2 {
-                            color2 = style_color;
-                        }
-                        if let Some(color2_index) = color2_index {
-                            let index = categoricals[color2_index]
+                        if let Some(color_index) = color_index {
+                            let index = categoricals[color_index]
                                 .as_number()
                                 .unwrap_or_default()
                                 .unwrap_or_default();
                             let index = <usize as NumCast>::from(index).unwrap_or_default();
-                            color2 = PALETTE[index % PALETTE.len()];
+                            style.color = Some(PALETTE[index % PALETTE.len()]);
                         }
-                        if let Some((index, style_cycle)) = styling {
-                            let index = categoricals[index]
+                        if let Some(color2_index) = color2_index {
+                            let index = categoricals[color2_index]
                                 .as_number()
                                 .unwrap_or_default()
                                 .unwrap_or_default();
                             let index = <usize as NumCast>::from(index).unwrap_or_default();
-                            let style = style_cycle.get_style(index);
-                            if let Some(style_color) = style.color2 {
-                                color2 = style_color;
-                            }
+                            style.color2 = Some(PALETTE[index % PALETTE.len()]);
                         }
 
+                        let color = style.color.unwrap_or(Color::BLACK);
+                        let color2 = style.color2.unwrap_or(Color::BLACK);
+
                         fn points(
                             rect: &Rect,
                             group: &[Vec<&SeriesValue>],
@@ -982,7 +965,16 @@ impl Visualization {
                         match element.graphic {
                             Graphic::Interval => {
                                 // Size defaults to 33%.
+                                let fraction = match style.symbol_size {
+                                    Some(LocationLength::Percent(percent)) => percent,
+                                    _ => 33.0,
+                                } / 100.0
+                                    / 2.0;
                                 for (x, y0) in ranges(&rect, group, &axis_domains) {
+                                    let width = x.end - x.start;
+                                    let midpoint = x.start.midpoint(x.end);
+                                    let x =
+                                        midpoint - width * fraction..midpoint + width * fraction;
                                     let y1 = rect.0[Axis2::Y].1;
                                     element_svg.append(
                                         Rectangle::new()
index b8ebc991275a34fc4bcb99b79964e9cd646755d4..90c070141bd72ae52ad15d2fd354b7b69c43e9e3 100644 (file)
@@ -57,12 +57,12 @@ Percent
 Percent
 </text>
 <g id="element_bar_1">
-<rect fill="#d3ce97" height="92.56696428571429" stroke="#000000" width="274.25" x="70.25" y="126.93303571428571"/>
-<rect fill="#d3ce97" height="204.2857142857143" stroke="#000000" width="274.25" x="344.5" y="15.214285714285701"/>
+<rect fill="#d3ce97" height="92.56696428571429" stroke="#000000" width="205.6875" x="104.53125" y="126.93303571428571"/>
+<rect fill="#d3ce97" height="204.2857142857143" stroke="#000000" width="205.6875" x="378.78125" y="15.214285714285701"/>
 </g>
 <g id="element_bar_1">
-<rect fill="#d3ce97" height="121.29464285714289" stroke="#000000" width="274.25" x="70.25" y="317.7053571428571"/>
-<rect fill="#d3ce97" height="127.67857142857144" stroke="#000000" width="274.25" x="344.5" y="311.32142857142856"/>
+<rect fill="#d3ce97" height="121.29464285714289" stroke="#000000" width="205.6875" x="104.53125" y="317.7053571428571"/>
+<rect fill="#d3ce97" height="127.67857142857144" stroke="#000000" width="205.6875" x="378.78125" y="311.32142857142856"/>
 </g>
 </g>
 </svg>