From: Ben Pfaff Date: Thu, 7 May 2026 20:39:34 +0000 (-0700) Subject: bar graphs starting to look pretty OK X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d74de902b9bf9d76c49921ea63dc91cc50a67e97;p=pspp bar graphs starting to look pretty OK --- diff --git a/rust/pspp/src/spv/read/graph.rs b/rust/pspp/src/spv/read/graph.rs index ea8240ae4a..2cd3b32fb3 100644 --- a/rust/pspp/src/spv/read/graph.rs +++ b/rust/pspp/src/spv/read/graph.rs @@ -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 = ::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 = ::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 = ::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 = ::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() diff --git a/rust/pspp/src/spv/testdata/graph3.expected.svg b/rust/pspp/src/spv/testdata/graph3.expected.svg index b8ebc99127..90c070141b 100644 --- a/rust/pspp/src/spv/testdata/graph3.expected.svg +++ b/rust/pspp/src/spv/testdata/graph3.expected.svg @@ -57,12 +57,12 @@ Percent Percent - - + + - - + +