From d6d2833069ec854a1d407a067d4ac6c0b40c88ac Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 10 Apr 2025 21:20:24 -0700 Subject: [PATCH] category and dimension borders 1 --- rust/pspp/src/output/pivot/mod.rs | 14 +++-- rust/pspp/src/output/pivot/test.rs | 90 ++++++++++++++++++++++++++++-- 2 files changed, 94 insertions(+), 10 deletions(-) diff --git a/rust/pspp/src/output/pivot/mod.rs b/rust/pspp/src/output/pivot/mod.rs index f00cdd77f6..d629cc29e0 100644 --- a/rust/pspp/src/output/pivot/mod.rs +++ b/rust/pspp/src/output/pivot/mod.rs @@ -1007,6 +1007,8 @@ pub struct Color { impl Color { pub const BLACK: Color = Color::new(0, 0, 0); pub const WHITE: Color = Color::new(255, 255, 255); + pub const RED: Color = Color::new(255, 0, 0); + pub const BLUE: Color = Color::new(0, 0, 255); pub const TRANSPARENT: Color = Color::new(0, 0, 0).with_alpha(0); const fn new(r: u8, g: u8, b: u8) -> Self { @@ -1413,8 +1415,8 @@ pub struct PivotTable { } impl PivotTable { - fn with_title(mut self, title: Value) -> Self { - self.title = Some(Box::new(title)); + fn with_title(mut self, title: impl Into) -> Self { + self.title = Some(Box::new(title.into())); self.show_title = true; self } @@ -1438,7 +1440,7 @@ impl PivotTable { fn with_layer(mut self, layer: &[usize]) -> Self { debug_assert_eq!(layer.len(), self.current_layer.len()); if self.look.print_all_layers { - Arc::make_mut(&mut self.look).print_all_layers = false; + self.look_mut().print_all_layers = false; } self.current_layer.clear(); self.current_layer.extend_from_slice(layer); @@ -1447,10 +1449,14 @@ impl PivotTable { fn with_all_layers(mut self) -> Self { if !self.look.print_all_layers { - Arc::make_mut(&mut self.look).print_all_layers = true; + self.look_mut().print_all_layers = true; } self } + + fn look_mut(&mut self) -> &mut Look { + Arc::make_mut(&mut self.look) + } } impl Default for PivotTable { diff --git a/rust/pspp/src/output/pivot/test.rs b/rust/pspp/src/output/pivot/test.rs index 115d6daf52..3e66720ee1 100644 --- a/rust/pspp/src/output/pivot/test.rs +++ b/rust/pspp/src/output/pivot/test.rs @@ -669,12 +669,7 @@ fn borders() { Border::Dimension(RowColBorder(HeadingRegion::Rows, Axis2::X)) | Border::Dimension(RowColBorder(HeadingRegion::Columns, Axis2::Y)) => BorderStyle { stroke: Stroke::Solid, - color: Color { - alpha: 255, - r: 0, - g: 0, - b: 255, - }, + color: Color::BLUE, }, _ => BorderStyle::none(), }); @@ -716,6 +711,89 @@ dg1 d1 c1 0│ 1 2│ 3│ 4 5│ 6│ 7 8 ╶─────────┼─────┼──┼─────┼──┼───── cg1 c2 63│64 65│66│67 68│69│70 71 c3 72│73 74│75│76 77│78│79 80 +", + ); + + let mut pivot_table = pivot_table.with_title("Category Borders 1"); + pivot_table.look_mut().borders = EnumMap::from_fn(|border| match border { + Border::Category(RowColBorder(HeadingRegion::Rows, Axis2::X)) + | Border::Category(RowColBorder(HeadingRegion::Columns, Axis2::Y)) => BorderStyle { + stroke: Stroke::Dashed, + color: Color::RED, + }, + _ => BorderStyle::none(), + }); + assert_rendering( + &pivot_table, + "\ +Category Borders 1 + b + bg1 ┊ + b1 ┊ b2 ┊ b3 + a ┊ a ┊ a + ┊ ag1 ┊ ┊ ag1 ┊ ┊ ag1 +d c a1┊a2┊a3┊a1┊a2┊a3┊a1┊a2┊a3 +dg1 d1 c1 0┊ 1┊ 2┊ 3┊ 4┊ 5┊ 6┊ 7┊ 8 + ╶╌╌╌╌╌╌╌╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌ + cg1 c2 9┊10┊11┊12┊13┊14┊15┊16┊17 + ╶╌╌╌╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌ + c3 18┊19┊20┊21┊22┊23┊24┊25┊26 + ╶╌╌╌╌╌╌╌╌╌╌╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌ + d2 c1 27┊28┊29┊30┊31┊32┊33┊34┊35 + ╶╌╌╌╌╌╌╌╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌ + cg1 c2 36┊37┊38┊39┊40┊41┊42┊43┊44 + ╶╌╌╌╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌ + c3 45┊46┊47┊48┊49┊50┊51┊52┊53 +╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌ + d3 c1 54┊55┊56┊57┊58┊59┊60┊61┊62 + ╶╌╌╌╌╌╌╌╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌ + cg1 c2 63┊64┊65┊66┊67┊68┊69┊70┊71 + ╶╌╌╌╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌ + c3 72┊73┊74┊75┊76┊77┊78┊79┊80 +", + ); + + let mut pivot_table = pivot_table.with_title("Category and Dimension Borders 1"); + pivot_table.look_mut().borders = EnumMap::from_fn(|border| match border { + Border::Dimension(RowColBorder(HeadingRegion::Rows, Axis2::X)) + | Border::Dimension(RowColBorder(HeadingRegion::Columns, Axis2::Y)) => BorderStyle { + stroke: Stroke::Solid, + color: Color::BLUE, + }, + Border::Category(RowColBorder(HeadingRegion::Rows, Axis2::X)) + | Border::Category(RowColBorder(HeadingRegion::Columns, Axis2::Y)) => BorderStyle { + stroke: Stroke::Dashed, + color: Color::RED, + }, + _ => BorderStyle::none(), + }); + assert_rendering( + &pivot_table, + "\ +Category and Dimension Borders 1 + b + bg1 │ + b1 │ b2 │ b3 + a │ a │ a + │ ag1 │ │ ag1 │ │ ag1 +d c a1│a2┊a3│a1│a2┊a3│a1│a2┊a3 +dg1 d1 c1 0│ 1┊ 2│ 3│ 4┊ 5│ 6│ 7┊ 8 + ╶─────────┼──┼──┼──┼──┼──┼──┼──┼── + cg1 c2 9│10┊11│12│13┊14│15│16┊17 + ╶╌╌╌╌╌┼╌╌+╌╌┼╌╌┼╌╌+╌╌┼╌╌┼╌╌+╌╌ + c3 18│19┊20│21│22┊23│24│25┊26 + ╶────────────┼──┼──┼──┼──┼──┼──┼──┼── + d2 c1 27│28┊29│30│31┊32│33│34┊35 + ╶─────────┼──┼──┼──┼──┼──┼──┼──┼── + cg1 c2 36│37┊38│39│40┊41│42│43┊44 + ╶╌╌╌╌╌┼╌╌+╌╌┼╌╌┼╌╌+╌╌┼╌╌┼╌╌+╌╌ + c3 45│46┊47│48│49┊50│51│52┊53 +────────────────┼──┼──┼──┼──┼──┼──┼──┼── + d3 c1 54│55┊56│57│58┊59│60│61┊62 + ╶─────────┼──┼──┼──┼──┼──┼──┼──┼── + cg1 c2 63│64┊65│66│67┊68│69│70┊71 + ╶╌╌╌╌╌┼╌╌+╌╌┼╌╌┼╌╌+╌╌┼╌╌┼╌╌+╌╌ + c3 72│73┊74│75│76┊77│78│79┊80 ", ); } -- 2.30.2