}
impl PivotTable {
- fn builder(title: impl Into<Value>, dimensions: Vec<DimensionBuilder>) -> PivotTableBuilder {
- PivotTableBuilder::from_builders(title, dimensions)
- }
fn axis_values(&self, axis: Axis3) -> AxisIterator {
AxisIterator {
indexes: repeat_n(0, self.axes[axis].dimensions.len()).collect(),
pub fn leaf_path(&self, index: usize) -> Option<Path<'_>> {
self.root.leaf_path(index, SmallVec::new())
}
-
- pub fn builder(axis: Axis3, root: GroupBuilder) -> DimensionBuilder {
- DimensionBuilder::new(axis, root)
- }
}
#[derive(Clone, Debug)]
self
}
- pub fn builder(name: impl Into<Value>) -> GroupBuilder {
- GroupBuilder::new(name)
- }
-
pub fn nth_leaf(&self, mut index: usize) -> Option<&Leaf> {
for child in &self.children {
let len = child.len();
}
}
-#[derive(Clone)]
-pub struct DimensionBuilder {
- axis: Axis3,
- dimension: Dimension,
-}
-
-impl DimensionBuilder {
- pub fn new(axis: Axis3, root: GroupBuilder) -> Self {
- let root = root.build(true);
- Self {
- axis,
- dimension: Dimension {
- presentation_order: (0..root.len()).collect(),
- root,
- hide_all_labels: false,
- },
- }
- }
- pub fn with_all_labels_hidden(mut self) -> Self {
- self.dimension.hide_all_labels = true;
- self
- }
- fn build(self) -> Dimension {
- self.dimension
- }
-}
-
-#[derive(Clone)]
-pub struct GroupBuilder {
- name: Box<Value>,
- children: Vec<CategoryBuilder>,
- show_label: Option<bool>,
-}
-
-impl GroupBuilder {
- pub fn new(name: impl Into<Value>) -> Self {
- Self {
- name: Box::new(name.into()),
- children: Vec::new(),
- show_label: None,
- }
- }
- pub fn push<T>(&mut self, value: T)
- where
- T: Into<CategoryBuilder>,
- {
- self.children.push(value.into());
- }
- pub fn with<T>(mut self, value: T) -> Self
- where
- T: Into<CategoryBuilder>,
- {
- self.push(value);
- self
- }
- pub fn with_label_hidden(self) -> Self {
- self.with_show_label(false)
- }
- pub fn with_label_shown(self) -> Self {
- self.with_show_label(true)
- }
- pub fn with_show_label(mut self, show_label: bool) -> Self {
- self.show_label = Some(show_label);
- self
- }
- fn len(&self) -> usize {
- self.children.iter().map(|category| category.len()).sum()
- }
- fn build(self, is_root: bool) -> Group {
- Group {
- len: self.children.iter().map(|c| c.len()).sum(),
- name: self.name,
- children: self.children.into_iter().map(|c| c.build()).collect(),
- show_label: {
- // By default, nested group labels are shown, but not dimension root labels.
- self.show_label.unwrap_or(!is_root)
- },
- }
- }
-}
-
-#[derive(Clone)]
-pub enum CategoryBuilder {
- Group(Box<GroupBuilder>),
- Leaf {
- name: Box<Value>,
- class: Option<Class>,
- },
-}
-
-impl CategoryBuilder {
- fn len(&self) -> usize {
- match self {
- CategoryBuilder::Group(group) => group.len(),
- CategoryBuilder::Leaf { .. } => 1,
- }
- }
- fn build(self) -> Category {
- match self {
- Self::Group(group) => Category::Group(group.build(false)),
- Self::Leaf { name, class } => Category::Leaf(Leaf { name, class }),
- }
- }
-}
-
-impl From<GroupBuilder> for CategoryBuilder {
- fn from(value: GroupBuilder) -> Self {
- Self::Group(Box::new(value))
- }
-}
-
-impl From<Value> for CategoryBuilder {
- fn from(name: Value) -> Self {
- Self::Leaf {
- name: Box::new(name),
- class: None,
- }
- }
-}
-
-impl From<(Value, Class)> for CategoryBuilder {
- fn from((name, class): (Value, Class)) -> Self {
- Self::Leaf {
- name: Box::new(name),
- class: Some(class),
- }
- }
-}
-
-impl From<&str> for CategoryBuilder {
- fn from(name: &str) -> Self {
- Self::Leaf {
- name: Box::new(Value::new_text(name)),
- class: None,
- }
- }
-}
-
#[derive(Clone, Debug, Default)]
pub struct Footnotes(Vec<Arc<Footnote>>);
footnotes: Footnotes::new(),
}
}
- pub fn from_builders(
- title: impl Into<Value>,
- dimension_builders: Vec<DimensionBuilder>,
- ) -> Self {
- let mut dimensions = Vec::with_capacity(dimension_builders.len());
- let mut axes = EnumMap::from_fn(|_axis| Axis {
- dimensions: Vec::with_capacity(dimension_builders.len()),
- });
- for d in dimension_builders {
- axes[d.axis].dimensions.push(dimensions.len());
- dimensions.push(d.build());
- }
- Self {
- look: Settings::global().look.clone(),
- title: Box::new(title.into()),
- axes,
- dimensions,
- cells: HashMap::new(),
- footnotes: Footnotes::new(),
- }
- }
pub fn with_look(mut self, look: Arc<Look>) -> Self {
self.look = look;
self