Compare commits

..
3 changed files with 20 additions and 12 deletions
-5
View File
@@ -247,11 +247,6 @@ pub fn repair(p: &mut Presentation) {
if !(p.notes_size.width.is_finite() && p.notes_size.width > 0.0 && p.notes_size.height.is_finite() && p.notes_size.height > 0.0) {
p.notes_size = Presentation::default().notes_size;
}
// A notes page is bounded like a slide: canvas and handout drawing scale with it.
p.notes_size = deckcraft_model::Size::new(
p.notes_size.width.clamp(*SLIDE_SIDE.start(), *SLIDE_SIDE.end()),
p.notes_size.height.clamp(*SLIDE_SIDE.start(), *SLIDE_SIDE.end()),
);
sane_numbers(p);
}
-7
View File
@@ -451,13 +451,6 @@ fn degenerate_slide_sizes_are_repaired() {
}
}
#[test]
fn repair_bounds_the_notes_page_size() {
let mut p = Presentation { notes_size: deckcraft_model::Size::new(1e12, 0.01), ..Default::default() };
repair(&mut p);
assert_eq!((p.notes_size.width, p.notes_size.height), (4032.0, 72.0));
}
/// A file whose slide size is null, a string or missing a side (written by hand or by
/// another tool; NaN is also saved as null) opens with the default size rather than failing
/// as damaged.
+20
View File
@@ -250,7 +250,19 @@ fn axis_ticks((lo, hi, st): (f64, f64, f64)) -> impl Iterator<Item = f64> {
(0..=n).map(move |k| lo + k as f64 * st)
}
/// Most category-by-series cells one chart draws; ordinary charts hold a few hundred.
const MAX_CHART_CELLS: usize = 4_000_000;
/// Whether the independent category and series lists make the drawing loops multiply past the budget.
fn over_cell_budget(c: &Chart) -> bool {
let ncat = c.categories.len().max(c.series.iter().map(|s| s.values.len()).max().unwrap_or(0));
ncat.saturating_mul(c.series.len().max(1)) > MAX_CHART_CELLS
}
pub fn draw(ctx: &mut RenderContext, rctx: &Ctx, c: &Chart, m: Affine, w: f64, h: f64) {
if over_cell_budget(c) {
return;
}
match c.kind {
// Histograms and Pareto charts are drawn as the column (and line) chart of their bins.
ChartType::Histogram | ChartType::Pareto => {
@@ -1425,6 +1437,14 @@ mod tests {
const AREA: Rect = Rect::new(0.0, 0.0, 400.0, 300.0);
#[test]
fn category_by_series_cells_are_budgeted() {
let mut c = Chart::sample(ChartType::Column);
assert!(!over_cell_budget(&c));
c.categories = vec![String::new(); MAX_CHART_CELLS / c.series.len() + 1];
assert!(over_cell_budget(&c));
}
#[test]
fn tiny_data_gets_several_ticks() {
let sc = deckcraft_model::chart::axis_scale(1e-13, 5e-13, None, None, None, 8, true);