From 78073228a501fcf137e40a00c20291cc62a699ea Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sat, 5 Apr 2025 18:41:08 -0700 Subject: [PATCH] transpose --- rust/pspp/src/output/pivot/mod.rs | 11 +++++------ rust/pspp/src/output/pivot/output.rs | 3 --- rust/pspp/src/output/pivot/test.rs | 5 ++++- rust/pspp/src/output/render.rs | 7 ------- rust/pspp/src/output/text.rs | 4 ---- 5 files changed, 9 insertions(+), 21 deletions(-) diff --git a/rust/pspp/src/output/pivot/mod.rs b/rust/pspp/src/output/pivot/mod.rs index 4ae6f1b00c..ec6f68c797 100644 --- a/rust/pspp/src/output/pivot/mod.rs +++ b/rust/pspp/src/output/pivot/mod.rs @@ -324,9 +324,6 @@ impl Axis { /// data.) #[derive(Clone, Debug)] pub struct Dimension { - /// Our axis within the pivot table. - axis: Axis3, - /// The index for this dimension within its axis. /// /// This [Dimension] is `pivot_table.axes[axis].dimensions[level]`. @@ -426,7 +423,6 @@ impl DimensionBuilder { self.root.assign_label_depth(label_position); let root = self.root.build(label_position, None, &mut leaves); Dimension { - axis: self.axis, level, top_index, root, @@ -675,13 +671,12 @@ impl PivotTableBuilder { LabelPosition::Nested }; let d = Arc::new(d.build(axes[axis].len(), top_index, label_position)); - axes[d.axis].push(d.clone()); + axes[axis].push(d.clone()); dimensions.push(d); } table.dimensions = dimensions; table.axes = axes.map(|_axis, dimensions| { 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, @@ -1641,6 +1636,10 @@ impl PivotTable { footnote_marker_type: self.look.footnote_marker_type, } } + + pub fn transpose(&mut self) { + self.axes.swap(Axis3::X, Axis3::Y); + } } pub struct Layers {} diff --git a/rust/pspp/src/output/pivot/output.rs b/rust/pspp/src/output/pivot/output.rs index 2341aadb6a..536ae3f9b5 100644 --- a/rust/pspp/src/output/pivot/output.rs +++ b/rust/pspp/src/output/pivot/output.rs @@ -71,7 +71,6 @@ impl PivotTable { fixed_indexes: &[usize], fixed_axis: Axis3, ) -> bool { - dbg!(); let vary_axis = fixed_axis.transpose().unwrap(); for vary_indexes in self.axes[vary_axis].iter() { let mut presentation_indexes = enum_map! { @@ -81,11 +80,9 @@ impl PivotTable { presentation_indexes[vary_axis] = &vary_indexes; let data_indexes = self.convert_indexes_ptod(presentation_indexes); if self.get(&data_indexes).is_some() { - dbg!(); return false; } } - dbg!(); true } fn enumerate_axis( diff --git a/rust/pspp/src/output/pivot/test.rs b/rust/pspp/src/output/pivot/test.rs index 7534430bd5..97bae33091 100644 --- a/rust/pspp/src/output/pivot/test.rs +++ b/rust/pspp/src/output/pivot/test.rs @@ -34,5 +34,8 @@ fn pivot_table_1d() { pt.insert(&[i], Value::new_number(Some(i as f64))); } let mut driver = TextDriver::new(File::create("/dev/stdout").unwrap()); - driver.write(&Arc::new(Item::new(Details::Table(Box::new(pt.build()))))); + let mut pt = pt.build(); + driver.write(&Arc::new(Item::new(Details::Table(Box::new(pt.clone()))))); + pt.transpose(); + driver.write(&Arc::new(Item::new(Details::Table(Box::new(pt))))); } diff --git a/rust/pspp/src/output/render.rs b/rust/pspp/src/output/render.rs index b2e7fa5c86..1870a1f1d4 100644 --- a/rust/pspp/src/output/render.rs +++ b/rust/pspp/src/output/render.rs @@ -373,7 +373,6 @@ impl Page { fn new(table: Arc, device: &dyn Device, min_width: usize, look: &Look) -> Self { use Axis2::*; - dbg!(&table); let n = table.n.clone(); // Figure out rule widths. @@ -385,7 +384,6 @@ impl Page { .map(|z| measure_rule(&*device, &*table, axis, z)) .collect::>() }); - dbg!(&rules); let px_size = device.params().px_size.unwrap_or_default(); let heading_widths = look @@ -422,7 +420,6 @@ impl Page { } } } - dbg!(&unspanned_columns); // Distribute widths of spanned columns. let mut columns = unspanned_columns.clone(); @@ -458,7 +455,6 @@ impl Page { columns[1][i] = columns[0][i]; } } - dbg!(&columns); // Decide final column widths. let rule_widths = rules[X].iter().copied().sum::(); @@ -466,7 +462,6 @@ impl Page { .iter() .map(|row| row.iter().sum::() + rule_widths) .collect::>(); - dbg!(&table_widths); let cp_x = if table_widths[1] <= device.params().size[X] { // Fits even with maximum widths. Use them. @@ -487,7 +482,6 @@ impl Page { // later we can break it horizontally into multiple pages. Self::use_row_widths(&columns[0], &rules[X]) }; - dbg!(&cp_x); // Calculate heights of cells that do not span multiple rows. let mut unspanned_rows = vec![0; n[Y]]; @@ -1327,7 +1321,6 @@ impl Break { } fn find_breakpoint(&mut self, device: &dyn Device, size: usize) -> Option<(usize, usize)> { - dbg!(self.axis, self.z..self.page.n[self.axis]); for z in self.z..self.page.n[self.axis] { let needed = self.needed_size(z + 1); if needed > size { diff --git a/rust/pspp/src/output/text.rs b/rust/pspp/src/output/text.rs index d78e91d32b..c290050a62 100644 --- a/rust/pspp/src/output/text.rs +++ b/rust/pspp/src/output/text.rs @@ -338,7 +338,6 @@ where postindex }; if index <= self.indexes.end { - dbg!(); continue; } @@ -360,7 +359,6 @@ where // // We trim trailing spaces from the line we return, and leading // spaces from the position where we resume. - dbg!(); let segment = self.text[self.indexes.clone()].trim_end(); let start = self.text[self.indexes.end..].trim_start_matches([' ', '\t']); @@ -507,7 +505,6 @@ impl Device for TextDriver { ) { let display = Self::display_cell(cell); let text = display.to_string(); - println!("text={text:?} bb={bb:?}"); let horz_align = cell .style .cell_style @@ -527,7 +524,6 @@ 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