}
impl PivotTable {
+ pub fn with_look(mut self, look: Arc<Look>) -> Self {
+ self.look = look;
+ self
+ }
+ pub fn insert_number(&mut self, data_indexes: &[usize], number: Option<f64>, class: Class) {
+ let format = match class {
+ Class::Other => Settings::global().default_format,
+ Class::Integer => Format::F40,
+ Class::Correlations => Format::F40_3,
+ Class::Significance => Format::F40_3,
+ Class::Percent => Format::PCT40_1,
+ Class::Residual => Format::F40_2,
+ Class::Count => Format::F40, // XXX
+ };
+ let value = Value::new(ValueInner::Number {
+ show: None,
+ format,
+ honor_small: class == Class::Other,
+ value: number,
+ var_name: None,
+ value_label: None,
+ });
+ self.insert(data_indexes, value);
+ }
+
+ pub fn with_footnotes(mut self, footnotes: Footnotes) -> Self {
+ debug_assert!(self.footnotes.is_empty());
+ self.footnotes = footnotes;
+ self
+ }
fn axis_values(&self, axis: Axis3) -> AxisIterator {
AxisIterator {
indexes: repeat_n(0, self.axes[axis].dimensions.len()).collect(),
footnotes: Footnotes::new(),
}
}
- pub fn with_look(mut self, look: Arc<Look>) -> Self {
- self.look = look;
- self
- }
- pub fn insert_number(&mut self, data_indexes: &[usize], number: Option<f64>, class: Class) {
- let format = match class {
- Class::Other => Settings::global().default_format,
- Class::Integer => Format::F40,
- Class::Correlations => Format::F40_3,
- Class::Significance => Format::F40_3,
- Class::Percent => Format::PCT40_1,
- Class::Residual => Format::F40_2,
- Class::Count => Format::F40, // XXX
- };
- let value = Value::new(ValueInner::Number {
- show: None,
- format,
- honor_small: class == Class::Other,
- value: number,
- var_name: None,
- value_label: None,
- });
- self.insert(data_indexes, value);
- }
- pub fn insert(&mut self, data_indexes: &[usize], value: Value) {
- self.cells.insert(
- cell_index(data_indexes, self.dimensions.iter().map(|d| d.len())),
- value,
- );
- }
- pub fn with_footnotes(mut self, footnotes: Footnotes) -> Self {
- debug_assert!(self.footnotes.is_empty());
- self.footnotes = footnotes;
- self
- }
pub fn build(self) -> PivotTable {
let mut table = PivotTable::new(self.title, self.look.clone());
table.dimensions = self.dimensions;
.with("a2")
.with("a3"),
);
- let mut pt = PivotTableBuilder::new(Value::new_text(title), vec![(axis, dimension)]);
+ let mut pt = PivotTableBuilder::new(Value::new_text(title), vec![(axis, dimension)])
+ .build()
+ .with_look(Arc::new(test_look()));
for i in 0..3 {
pt.insert(&[i], Value::new_integer(Some(i as f64)));
}
- pt.with_look(Arc::new(test_look())).build()
+ pt
}
#[test]
.with("b3"),
);
- let mut pt = PivotTableBuilder::new(Value::new_text(title), vec![(axes[0], d1), (axes[1], d2)]);
+ let mut pt =
+ PivotTableBuilder::new(Value::new_text(title), vec![(axes[0], d1), (axes[1], d2)]).build();
let mut i = 0;
for b in 0..3 {
for a in 0..3 {
Some(position) => test_look().with_row_label_position(position),
None => test_look(),
};
- pt.with_look(Arc::new(look)).build()
+ pt.with_look(Arc::new(look))
}
#[track_caller]
let mut pt = PivotTableBuilder::new(
Value::new_text("Pivot Table with Alphabetic Subscript Footnotes").with_footnote(&f0),
vec![a, d],
- );
+ )
+ .build();
pt.insert(&[0, 0], Value::new_number(Some(0.0)));
pt.insert(&[1, 0], Value::new_number(Some(1.0)).with_footnote(&f0));
pt.insert(&[0, 1], Value::new_number(Some(2.0)).with_footnote(&f1));
let pt = pt
.with_look(Arc::new(look))
.with_footnotes(footnotes)
- .build()
.with_caption(Value::new_text("Caption").with_footnote(&f0))
.with_corner_text(
Value::new_text("Corner")
#[test]
fn no_dimension() {
let pivot_table = PivotTableBuilder::new("No Dimensions", vec![])
- .with_look(Arc::new(test_look()))
- .build();
+ .build()
+ .with_look(Arc::new(test_look()));
assert_rendering(
&pivot_table,
"No Dimensions
let d1 = (Axis3::X, Dimension::new(Group::new("a")));
let pivot_table = PivotTableBuilder::new("One Empty Dimension", vec![d1])
- .with_look(look.clone())
- .build();
+ .build()
+ .with_look(look.clone());
assert_rendering(&pivot_table, "One Empty Dimension\n");
let d1 = (Axis3::X, Dimension::new(Group::new("a")));
let d2 = (Axis3::X, Dimension::new(Group::new("b").with_label_shown()));
let pivot_table = PivotTableBuilder::new(Value::new_text("Two Empty Dimensions"), vec![d1, d2])
- .with_look(look.clone())
- .build();
+ .build()
+ .with_look(look.clone());
assert_rendering(&pivot_table, "Two Empty Dimensions\n");
let d1 = (Axis3::X, Dimension::new(Group::new("a")));
Dimension::new(Group::new("c").with("c1").with("c2")),
);
let pivot_table = PivotTableBuilder::new("Three Dimensions, Two Empty", vec![d1, d2, d3])
- .with_look(look.clone())
- .build();
+ .build()
+ .with_look(look.clone());
assert_rendering(&pivot_table, "Three Dimensions, Two Empty\n");
}
Dimension::new(Group::new("b").with(Group::new("b1")).with("b2").with("b3")),
);
- let mut pt = PivotTableBuilder::new("Empty Groups", vec![d1, d2]);
+ let mut pt = PivotTableBuilder::new("Empty Groups", vec![d1, d2]).build();
let mut i = 0;
for b in 0..2 {
for a in 0..2 {
i += 1;
}
}
- let pivot_table = pt
- .with_look(Arc::new(test_look().with_omit_empty(false)))
- .build();
+ let pivot_table = pt.with_look(Arc::new(test_look().with_omit_empty(false)));
assert_rendering(
&pivot_table,
"\
),
);
let mut pivot_table = PivotTableBuilder::new(title, vec![a, b, c, d])
+ .build()
.with_look(Arc::new(test_look().with_borders(borders)));
let mut i = 0;
for d in 0..3 {
}
}
}
- pivot_table.build()
+ pivot_table
}
#[test]
.with_label_shown(),
),
);
- let mut pt = PivotTableBuilder::new("small numbers", vec![exponent, sign, rc]);
+ let mut pt = PivotTableBuilder::new("small numbers", vec![exponent, sign, rc]).build();
pt.insert_number(&[0, 0, 0], Some(1.0), Class::Other);
pt.insert_number(&[1, 0, 0], Some(0.1), Class::Other);
pt.insert_number(&[2, 0, 0], Some(0.01), Class::Other);
pt.insert_number(&[7, 1, 1], Some(-0.0000001), Class::Residual);
pt.insert_number(&[8, 1, 1], Some(-0.00000001), Class::Residual);
pt.insert_number(&[9, 1, 1], Some(-0.000000001), Class::Residual);
- let pivot_table = pt.with_look(Arc::new(test_look())).build();
+ let pivot_table = pt.with_look(Arc::new(test_look()));
assert_rendering(
&pivot_table,
"\