/// 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].
// 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;
.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()
}