From c1906c0174e3c030538b3cc706320b46ef442541 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sat, 5 Apr 2025 11:49:59 -0700 Subject: [PATCH] headings basically work --- rust/pspp/src/output/pivot/mod.rs | 19 +++++++++++------ rust/pspp/src/output/pivot/output.rs | 32 +++++++++++++++------------- rust/pspp/src/output/text.rs | 3 ++- 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/rust/pspp/src/output/pivot/mod.rs b/rust/pspp/src/output/pivot/mod.rs index ec4b5ce22a..98795c4a26 100644 --- a/rust/pspp/src/output/pivot/mod.rs +++ b/rust/pspp/src/output/pivot/mod.rs @@ -357,9 +357,6 @@ pub struct Dimension { /// Display. hide_all_labels: bool, - - /// Number of rows or columns needed to express the labels. - label_depth: usize, } impl Dimension { @@ -370,6 +367,14 @@ impl Dimension { pub fn len(&self) -> usize { self.data_leaves.len() } + + pub fn label_depth(&self) -> usize { + if self.hide_all_labels { + 0 + } else { + self.root.label_depth + } + } } #[derive(Clone, Debug)] @@ -432,7 +437,6 @@ impl DimensionBuilder { data_leaves: leaves.clone(), presentation_leaves: leaves, hide_all_labels: self.hide_all_labels, - label_depth: 0, } } } @@ -520,8 +524,8 @@ impl GroupBuilder { Arc::new_cyclic(|weak| Group { parent, name: self.name, - label_depth: 0, - extra_depth: 0, + label_depth: self.label_depth, + extra_depth: self.extra_depth, children: self .children .into_iter() @@ -685,7 +689,8 @@ impl PivotTableBuilder { } table.dimensions = dimensions; table.axes = axes.map(|_axis, dimensions| { - let label_depth = dimensions.iter().map(|d| d.label_depth).sum(); + let label_depth = dimensions.iter().map(|d| d.label_depth()).sum(); + dbg!(label_depth); let extent = dimensions.iter().map(|d| d.data_leaves.len()).product(); Axis { dimensions, diff --git a/rust/pspp/src/output/pivot/output.rs b/rust/pspp/src/output/pivot/output.rs index 9f1cdbb808..9849566e9e 100644 --- a/rust/pspp/src/output/pivot/output.rs +++ b/rust/pspp/src/output/pivot/output.rs @@ -93,13 +93,10 @@ impl PivotTable { ) -> AxisEnumeration { let axis = &self.axes[enum_axis]; let indexes = if axis.dimensions.is_empty() { - dbg!(enum_axis); vec![0] } else if axis.extent == 0 { - dbg!(enum_axis); vec![] } else { - dbg!(enum_axis); let mut enumeration = Vec::with_capacity(axis.extent.checked_mul(axis.dimensions.len()).unwrap()); if omit_empty { @@ -117,7 +114,6 @@ impl PivotTable { } enumeration }; - println!("enumeration for {enum_axis:?}: {indexes:?}"); AxisEnumeration { indexes, stride: axis.dimensions.len().max(1), @@ -382,12 +378,14 @@ fn compose_headings( rotate_outer_labels: bool, area: Area, ) { + dbg!(h); let v = !h; let v_size = h_axis.label_depth; let h_ofs = v_axis.label_depth; let n_columns = column_enumeration.len(); if h_axis.dimensions.is_empty() || n_columns == 0 || v_size == 0 { + dbg!(); return; } @@ -449,20 +447,21 @@ fn compose_headings( vrules[0] = true; vrules[n_columns] = true; - for dim_index in (0..h_axis.dimensions.len()).rev() { - let d = &h_axis.dimensions[dim_index]; - if d.hide_all_labels { - continue; - } - - for row_ofs in 0..d.label_depth { + for (dim_index, d) in h_axis + .dimensions + .iter() + .enumerate() + .rev() + .filter(|(_, d)| !d.hide_all_labels) + { + for row_ofs in 0..d.label_depth() { let mut x1 = 0; while x1 < n_columns { let Some(c): Option = find_category( d, dim_index, column_enumeration.get(x1), - d.label_depth - row_ofs - 1, + d.label_depth() - row_ofs - 1, ) else { x1 += 1; continue; @@ -474,7 +473,7 @@ fn compose_headings( d, dim_index, column_enumeration.get(x2), - d.label_depth - row_ofs - 1, + d.label_depth() - row_ofs - 1, ); if c2.as_ref().is_none_or(|c2| !c.ptr_eq(c2)) { break; @@ -487,6 +486,9 @@ fn compose_headings( let is_outer_row = y1 == 0; let is_inner_row = y2 == v_size; if c.show_label() { + dbg!(h_ofs, x1..x2); + dbg!(top_row, row_ofs, y1..y2); + dbg!(&c); table.put( Rect2::for_ranges((h, x1 + h_ofs..x2 + h_ofs), y1..y2), CellInner { @@ -558,7 +560,7 @@ fn compose_headings( if d.root.show_label_in_corner && h_ofs > 0 { table.put( - Rect2::for_ranges((h, 0..h_ofs), top_row..top_row + d.label_depth), + Rect2::for_ranges((h, 0..h_ofs), top_row..top_row + d.label_depth()), CellInner::new(Area::Corner, d.root.name.clone()), ); } @@ -584,8 +586,8 @@ fn compose_headings( h_ofs..table.n[h], ); } - top_row += d.label_depth; } + top_row += d.label_depth(); } } diff --git a/rust/pspp/src/output/text.rs b/rust/pspp/src/output/text.rs index e275cd6d68..b61559731f 100644 --- a/rust/pspp/src/output/text.rs +++ b/rust/pspp/src/output/text.rs @@ -240,7 +240,7 @@ impl TextDriver { emphasis: false, width, min_hbreak: 20, - box_chars: &*ASCII_BOX, + box_chars: &*&UNICODE_BOX, n_objects: 0, params: Params { size: Coord2::new(width, usize::MAX), @@ -527,6 +527,7 @@ impl Device for TextDriver { HorzAlign::Left => bb[X].start, HorzAlign::Center => (bb[X].start + bb[X].end - width + 1) / 2, }; + dbg!(horz_align); let Some((x, text)) = clip_text(&text, &(x..x + width), &clip[X]) else { continue; }; -- 2.30.2