///
/// The root must always be a group, although it is allowed to have no
/// subcategories.
- pub root: Group,
+ root: Group,
/// Ordering of leaves for presentation.
///
pub hide_all_labels: bool,
}
+impl Dimension {
+ /// Returns the root [Group] of the dimension.
+ pub fn root(&self) -> &Group {
+ &self.root
+ }
+}
+
/// A vector of references to [Group]s.
///
/// Used to represent a sequence of groups along a [Path]. This is a [SmallVec]
len: usize,
/// The label displayed for the group.
- pub name: Box<Value>,
+ name: Box<Value>,
/// Whether to show the label.
pub show_label: bool,
///
/// A group usually has multiple children, but it is allowed to have
/// only one or even (pathologically) none.
- pub children: Vec<Category>,
+ children: Vec<Category>,
}
impl Group {
Self::with_capacity(name, 0)
}
+ /// Returns the group's child categories.
+ pub fn children(&self) -> &[Category] {
+ &self.children
+ }
+
/// Constructs a new `Group` with the given name and initial child
/// `capacity`. The group initially has no children.
pub fn with_capacity(name: impl Into<Value>, capacity: usize) -> Self {
/// A leaf category within a [Group] and ultimately within a [Dimension].
#[derive(Clone, Debug)]
-pub struct Leaf(pub Box<Value>);
+pub struct Leaf {
+ data_index: usize,
+ name: Box<Value>,
+}
impl Leaf {
/// Constructs a new `Leaf` with the given label.
pub fn new(name: Value) -> Self {
- Self(Box::new(name))
+ Self {
+ data_index: 0,
+ name: Box::new(name),
+ }
}
/// Returns the leaf's label.
pub fn name(&self) -> &Value {
- &self.0
+ &self.name
}
/// Returns a sequence of `Leaf`s for the given range, for use with
where
S: serde::Serializer,
{
- self.0.serialize(serializer)
+ self.name.serialize(serializer)
}
}
pub fn name(&self) -> &Value {
match self {
Category::Group(group) => &group.name,
- Category::Leaf(leaf) => &leaf.0,
+ Category::Leaf(leaf) => &leaf.name,
}
}
pub fn name_mut(&mut self) -> &mut Value {
match self {
Category::Group(group) => &mut group.name,
- Category::Leaf(leaf) => &mut leaf.0,
+ Category::Leaf(leaf) => &mut leaf.name,
}
}
Axis2::X,
[
Box::new(name),
- dimension.nth_leaf(layer_index).unwrap().0.clone(),
+ dimension.nth_leaf(layer_index).unwrap().name.clone(),
]
.into_iter(),
)
if let Some(group) = self.groups.get(y) {
(&*group.name, y..y + 1)
} else {
- (&self.leaf.0, self.groups.len()..height)
+ (&self.leaf.name, self.groups.len()..height)
}
}
}
Ok(PivotTable::new(
dims.into_iter()
- .map(|dim| (dim.axis, dim.dimension))
+ .map(|dim| {
+ (
+ dim.axis,
+ Dimension::new(dim.root).with_hide_all_labels(dim.hide_all_labels),
+ )
+ })
.collect::<Vec<_>>(),
)
.with_look(Arc::new(look))
let Some(dim_index) = s.dimension_index.get() else {
continue;
};
- let dimension = &mut dims[dim_index].dimension;
+ let root = &mut dims[dim_index].root;
let Ok(axis) = Axis2::try_from(dims[dim_index].axis) else {
continue;
};
for index in w.include.split(';').filter_map(|s| s.parse::<usize>().ok()) {
if let Some(locator) = s.coordinate_to_index.borrow().get(&index).copied()
- && let Some(category) = dimension.root.category_mut(locator)
+ && let Some(category) = root.category_mut(locator)
{
self.apply(
category.name_mut(),
dimension_label.set_font_style(dim_font);
}
- let dimension = Dimension::new(
- Group::new(dimension_label)
- .with_multiple(cats.into_iter().map(|cb| cb.category))
- .with_show_label(show_label),
- )
- .with_hide_all_labels(hide_all_labels);
+ let root = Group::new(dimension_label)
+ .with_multiple(cats.into_iter().map(|cb| cb.category))
+ .with_show_label(show_label);
for variable in &variables {
variable.dimension_index.set(Some(dims.len()));
}
dims.push(Dim {
axis: a,
- dimension,
+ hide_all_labels,
+ root,
series: variables[0],
});
}
struct Dim<'a> {
axis: Axis3,
- dimension: pivot::Dimension,
+ root: pivot::Group,
+ hide_all_labels: bool,
series: &'a Series,
}
}
pub fn decode(&self, mut warn: &mut dyn FnMut(LightWarning)) -> PivotTable {
+ dbg!(self);
let encoding = self.formats.encoding(warn);
let n1 = self.formats.n1();
for category in &d.categories {
category.decode(encoding, &footnotes, &mut root, warn);
}
- pivot::Dimension {
- presentation_order: (0..root.len()).collect(), /*XXX*/
- root,
- hide_all_labels: d.hide_all_labels,
- }
+ pivot::Dimension::new(root).with_hide_all_labels(d.hide_all_labels)
})
.collect::<Vec<_>>();
let dimensions = match self.axes.decode(dimensions) {
spv::SpvArchive,
};
+#[test]
+fn light1() {
+ test_raw_spvfile("light1", None);
+}
+
#[test]
fn legacy1() {
test_raw_spvfile("legacy1", None);
(index, x2): (usize, u8),
) -> binrw::BinResult<()> {
(
- &self.root.name,
+ self.root().name(),
0u8, // x1
x2,
2u32, // x3
- SpvBool(!self.root.show_label),
+ SpvBool(!self.root().show_label),
SpvBool(self.hide_all_labels),
SpvBool(true),
index as u32,
- self.root.children.len() as u32,
+ self.root().children().len() as u32,
)
.write_options(writer, endian, ())?;
let mut data_indexes = self.presentation_order.iter().copied();
- for child in &self.root.children {
+ for child in self.root().children() {
child.write_le(writer, &mut data_indexes)?;
}
Ok(())
1u8,
0u32, // x23
-1i32,
- self.children.len() as u32,
+ self.children().len() as u32,
)
.write_le(writer)?;
- for child in &self.children {
+ for child in self.children() {
child.write_le(writer, data_indexes)?;
}
Ok(())