fix display of layer values again rust
authorBen Pfaff <blp@cs.stanford.edu>
Fri, 9 Jan 2026 20:04:13 +0000 (12:04 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Fri, 9 Jan 2026 20:04:13 +0000 (12:04 -0800)
15 files changed:
rust/pspp/src/output/pivot.rs
rust/pspp/src/output/pivot/output.rs
rust/pspp/src/output/pivot/testdata/d2_cl-all_layers.expected
rust/pspp/src/output/pivot/testdata/d2_cl-layer0.expected
rust/pspp/src/output/pivot/testdata/d2_cl-layer1.expected
rust/pspp/src/output/pivot/testdata/d2_rl-all_layers.expected
rust/pspp/src/output/pivot/testdata/d2_rl-layer0.expected
rust/pspp/src/output/pivot/testdata/d2_rl-layer1.expected
rust/pspp/src/output/pivot/testdata/d3-layer0_0.expected
rust/pspp/src/output/pivot/testdata/d3-layer0_1.expected
rust/pspp/src/output/pivot/testdata/d3-layer1_2.expected
rust/pspp/src/output/pivot/tests.rs
rust/pspp/src/spv/testdata/legacy5.expected
rust/pspp/src/spv/testdata/legacy6.expected
rust/pspp/src/spv/testdata/legacy9.expected

index 70f63afd19edaeba8eaa94d5a4a486dffb6cbc3b..c49061eb01a840645abc7ddc430655edef778445 100644 (file)
@@ -631,12 +631,22 @@ pub type GroupVec<'a> = SmallVec<[&'a Group; 4]>;
 /// A path from the root of a [Dimension] to a [Leaf].
 pub struct Path<'a> {
     /// Groups along the path.
-    groups: GroupVec<'a>,
+    ///
+    /// There will be at least one group along any valid path, because the
+    /// dimension itself is a group.
+    pub groups: GroupVec<'a>,
 
     /// The leaf.
     ///
     /// This is a child of the last [Group].
-    leaf: &'a Leaf,
+    pub leaf: &'a Leaf,
+}
+
+impl<'a> Path<'a> {
+    /// Breaks the path into a vector of [Group]s and a [Leaf].
+    pub fn into_parts(self) -> (GroupVec<'a>, &'a Leaf) {
+        (self.groups, self.leaf)
+    }
 }
 
 /// Group indexes visited along a [Path].
index e6051376ff1e38293ca84656ce56eeff888cb93f..8b295a4abf08f75a7fe2a80d19d597ce948bcab1 100644 (file)
 // You should have received a copy of the GNU General Public License along with
 // this program.  If not, see <http://www.gnu.org/licenses/>.
 
-use std::{iter::once, ops::Range, sync::Arc};
+use std::{
+    iter::{once, repeat},
+    ops::Range,
+    sync::Arc,
+};
 
 use enum_map::{EnumMap, enum_map};
 use itertools::Itertools;
@@ -304,19 +308,20 @@ impl PivotTable {
             .map(|index| &self.structure.dimensions[*index])
             .zip(layer_indexes)
             .rev()
-            .filter(|(dimension, _)| !dimension.is_empty())
+            .filter(|(dimension, _)| !dimension.is_empty() && !dimension.hide_all_labels)
             .map(|(dimension, &layer_index)| {
-                let value = dimension.nth_leaf(layer_index).unwrap().name.clone();
-                if dimension.root.show_label {
-                    // Append `: ` to the name of the dimension, preserving all the styling.
-                    let name = dimension.root.name();
-                    let text = format!("{}: ", name.display(self).without_suffixes());
-                    let name = Value::new_user_text(text).with_styling(name.styling.clone());
-
-                    self.create_aux_table(Area::Layers, Axis2::X, [Box::new(name), value])
-                } else {
-                    self.create_aux_table(Area::Layers, Axis2::X, [value])
+                let mut cells = Vec::with_capacity(4);
+                let (groups, leaf) = dimension.leaf_path(layer_index).unwrap().into_parts();
+                for (group, separator) in groups
+                    .iter()
+                    .zip(once(": ").chain(repeat(" ")))
+                    .filter(|(group, _separator)| group.show_label)
+                {
+                    cells.push(Box::new(group.name().clone()));
+                    cells.push(Box::new(Value::new_user_text(separator)));
                 }
+                cells.push(Box::new(leaf.name().clone()));
+                self.create_aux_table(Area::Layers, Axis2::X, cells)
             })
             .collect()
     }
index 0fac24e5d7da885fbcea5f03f6eaa64f103ce6b2..cdb9255969de7af8fcb869f4a6a07e2655c4189f 100644 (file)
@@ -1,5 +1,5 @@
 Column (All Layers)
-b: b1
+b1
 ╭──┬──┬──╮
 │a1│a2│a3│
 ├──┼──┼──┤
@@ -7,7 +7,7 @@ b: b1
 ╰──┴──┴──╯
 
 Column (All Layers)
-b: b2
+b2
 ╭──┬──┬──╮
 │a1│a2│a3│
 ├──┼──┼──┤
@@ -15,7 +15,7 @@ b: b2
 ╰──┴──┴──╯
 
 Column (All Layers)
-b: b3
+b3
 ╭──┬──┬──╮
 │a1│a2│a3│
 ├──┼──┼──┤
index 8cb69bd2bc412c90b9f76b3060633b84eb8c5744..48a28c4991a7cd7483e03650c1158acd45623766 100644 (file)
@@ -1,5 +1,5 @@
 Column x b1
-b: b1
+b1
 ╭──┬──┬──╮
 │a1│a2│a3│
 ├──┼──┼──┤
index f6c5080f1aff02e3d113f46259804c78dbe3142b..9e9323c81034e34a90b9af5d3cc0a54f23561fa6 100644 (file)
@@ -1,5 +1,5 @@
 Column x b2
-b: b2
+b2
 ╭──┬──┬──╮
 │a1│a2│a3│
 ├──┼──┼──┤
index 72f11c1822cadac07ccdbc24396e03cf0f3053de..0aa4682594747a279a48f853399b1acdeee23c57 100644 (file)
@@ -1,5 +1,5 @@
 Row (All Layers)
-b: b1
+b1
 ╭──┬─╮
 │a1│0│
 │a2│1│
@@ -7,7 +7,7 @@ b: b1
 ╰──┴─╯
 
 Row (All Layers)
-b: b2
+b2
 ╭──┬─╮
 │a1│3│
 │a2│4│
@@ -15,7 +15,7 @@ b: b2
 ╰──┴─╯
 
 Row (All Layers)
-b: b3
+b3
 ╭──┬─╮
 │a1│6│
 │a2│7│
index b516020cc792450f57f0689dad6ac087d6796162..1f7667590a143d7fcdd1b5f7e7b55875e34dc4a8 100644 (file)
@@ -1,5 +1,5 @@
 Row x b1
-b: b1
+b1
 ╭──┬─╮
 │a1│0│
 │a2│1│
index 1ee2079e106c9ba9efc3c0bd0da6e41bfdba7dd4..051797d19295c582ee6bcf7c440baf6e82041029 100644 (file)
@@ -1,5 +1,5 @@
 Row x b2
-b: b2
+b2
 ╭──┬─╮
 │a1│3│
 │a2│4│
index 3db87b5dd947ce5d19749a371e2df20f4ed603b1..62cc0e489a95b96084fd1e4b4f8a1d02991606f7 100644 (file)
@@ -1,6 +1,6 @@
 Column x b1 x a1
 b: b1
-a: a1
+a1
 ╭──┬──┬──┬──┬──╮
 │c1│c2│c3│c4│c5│
 ├──┼──┼──┼──┼──┤
index e1d4dafc908d30510ec48aebfe77bc4251b175c7..ff5428fa00772fe8b50fefb30e23014c661894e2 100644 (file)
@@ -1,6 +1,6 @@
 Column x b2 x a1
 b: b2
-a: a1
+a1
 ╭──┬──┬──┬──┬──╮
 │c1│c2│c3│c4│c5│
 ├──┼──┼──┼──┼──┤
index c4248f0a52dfda378ae695629eac6799513aad81..0f531918a3979ebf84d03093b6511260eb9ff4ed 100644 (file)
@@ -1,6 +1,6 @@
 Column x b3 x a2
 b: b3
-a: a2
+a2
 ╭──┬──┬──┬──┬──╮
 │c1│c2│c3│c4│c5│
 ├──┼──┼──┼──┼──┤
index d5a899320341745828d2ee25908c9eb91a71a1db..a7fee6a2f218c11d1b99ec2039e6655bf467ddc1 100644 (file)
@@ -390,7 +390,14 @@ fn d3() {
     );
     let b = (
         Axis3::Z,
-        Dimension::new(Group::new("b").with("b1").with("b2").with("b3").with("b4")),
+        Dimension::new(
+            Group::new("b")
+                .with("b1")
+                .with("b2")
+                .with("b3")
+                .with("b4")
+                .with_label_shown(),
+        ),
     );
     let c = (
         Axis3::X,
index 8b701e2eca076239310fffe31caf9110383f1f65..85a899e431aab970c602950d8abbb0fa4ae9222d 100644 (file)
@@ -1,5 +1,5 @@
    Statistics
-Variables: Finished
+Finished
 ╭─────────┬───╮
 │N Valid  │159│
 │  Missing│  0│
index 9abd155a085987f74c765d62c714cfe186dd5611..272bfdfcf1b20ca2386066047426861ac4e8bc1a 100644 (file)
@@ -1,5 +1,5 @@
  Notes
-Contents: Weight
+Input Weight
 ──────
 <none>
 ──────
index dfbcded95d094dcad59541607a753858b3249d6d..2312b81addb143390a9447699d9648bd2cf94db0 100644 (file)
@@ -1,5 +1,5 @@
     Analysis
-Test: Duncan[a,b]
+Duncan[a,b]
        │ Subset
 SP36  N│   1
 ───────┼───────