}
pub fn output_body(&self, layer_indexes: &[usize], printing: bool) -> Table {
- let column_enumeration = self.enumerate_axis(Axis3::X, layer_indexes, self.look.omit_empty);
- let column_headings = Headings::new(self, Axis2::X, &column_enumeration);
+ let headings =
+ EnumMap::from_fn(|axis| Headings::new(self, axis, layer_indexes, self.look.omit_empty));
- let row_enumeration = self.enumerate_axis(Axis3::Y, layer_indexes, self.look.omit_empty);
- let row_headings = Headings::new(self, Axis2::Y, &row_enumeration);
-
- let data = Coord2::new(column_enumeration.len(), row_enumeration.len());
- let stub = Coord2::new(row_headings.height(), column_headings.height());
- let n = EnumMap::from_fn(|axis| data[axis] + stub[axis]).into();
+ let data = Coord2::from_fn(|axis| headings[axis].width());
+ let stub = Coord2::from_fn(|axis| headings[!axis].height());
let mut body = Table::new(
- n,
+ Coord2::from_fn(|axis| data[axis] + stub[axis]),
stub,
self.look.areas.clone(),
self.borders(printing),
self.as_value_options(),
);
- column_headings.render(
- &mut body,
- row_headings.height(),
- HeadingRegion::Columns,
- self.rotate_outer_row_labels,
- false,
- );
- row_headings.render(
- &mut body,
- column_headings.height(),
- HeadingRegion::Rows,
- false,
- self.rotate_inner_column_labels,
- );
+ for h in [Axis2::X, Axis2::Y] {
+ headings[h].render(&mut body, headings[!h].height(), h.into(), false, false);
+ }
- for (y, row_indexes) in row_enumeration.iter().enumerate() {
- let y = y + stub[Axis2::Y];
- for (x, column_indexes) in column_enumeration.iter().enumerate() {
- let x = x + stub[Axis2::X];
+ for (row_indexes, y) in headings[Axis2::Y].values.iter().zip(stub[Axis2::Y]..) {
+ for (column_indexes, x) in headings[Axis2::X].values.iter().zip(stub[Axis2::X]..) {
let presentation_indexes = enum_map! {
Axis3::X => &column_indexes,
Axis3::Y => &row_indexes,
struct Headings<'a> {
headings: Vec<Heading<'a>>,
h: Axis2,
- column_enumeration: &'a AxisEnumeration,
+ values: AxisEnumeration,
}
impl<'a> Headings<'a> {
- fn new(pt: &'a PivotTable, h: Axis2, column_enumeration: &'a AxisEnumeration) -> Self {
+ fn new(pt: &'a PivotTable, h: Axis2, layer_indexes: &[usize], omit_empty: bool) -> Self {
+ let column_enumeration = pt.enumerate_axis(h.into(), layer_indexes, omit_empty);
Self {
headings: pt.axes[h.into()]
.dimensions
.enumerate()
.rev()
.filter_map(|(axis_index, dim_index)| {
- Heading::new(&pt.dimensions[dim_index], axis_index, column_enumeration)
+ Heading::new(&pt.dimensions[dim_index], axis_index, &column_enumeration)
})
.collect(),
h,
- column_enumeration,
+ values: column_enumeration,
}
}
}
fn width(&self) -> usize {
- self.headings.first().map_or(0, |h| h.width())
+ self.values.len()
}
fn render(