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 {
}
impl PivotTable {
- fn with_title(mut self, title: Value) -> Self {
- self.title = Some(Box::new(title));
+ fn with_title(mut self, title: impl Into<Value>) -> Self {
+ self.title = Some(Box::new(title.into()));
self.show_title = true;
self
}
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);
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 {
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(),
});
╶─────────┼─────┼──┼─────┼──┼─────
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
",
);
}