diff --git a/crates/render/src/tests.rs b/crates/render/src/tests.rs index d94b646b0..881867693 100644 --- a/crates/render/src/tests.rs +++ b/crates/render/src/tests.rs @@ -3256,20 +3256,33 @@ fn line_chart_value_labels_are_drawn_above_their_points() { let sh = Shape { id: ShapeId(633), xfrm: Some(Xfrm::new(0.0, 0.0, 400.0, 300.0)), kind: ShapeKind::Chart(Box::new(c)), ..Default::default() }; render_slide(&deck_with(vec![sh]), 0, &RenderOpts { scale: 1.0, ..Default::default() }) }; - let red = |img: &Image| { - (0..400u32) - .flat_map(|x| (0..300u32).map(move |y| (x, y))) - .filter(|(x, y)| { - let p = img.pixel(*x, *y); - p[0] > 200 && p[1] < 60 && p[2] < 60 - }) - .count() + let is_red = |p: [u8; 4]| p[0] > 200 && p[1] < 60 && p[2] < 60; + let red = |img: &Image| (0..400u32).flat_map(|x| (0..300u32).map(move |y| (x, y))).filter(|(x, y)| is_red(img.pixel(*x, *y))).count(); + // The labels' own ink, counted as separate runs of columns, so the check holds in any interface face: every + // point gets a label of its own, whatever its glyphs weigh. + let label_runs = |off: &Image, on: &Image| { + let added: Vec = (0..400u32).map(|x| (0..300u32).any(|y| is_red(on.pixel(x, y)) && !is_red(off.pixel(x, y)))).collect(); + let mut runs = 0; + let mut gap = usize::MAX; + for inked in added { + if inked { + if gap >= 3 { + runs += 1; + } + gap = 0; + } else { + gap = gap.saturating_add(1); + } + } + runs }; for kind in [ChartType::Line, ChartType::LineMarkers] { - let (off, on) = (red(&draw(kind, false, false)), red(&draw(kind, true, false))); - assert!(on > off + 100, "{kind:?}: labels add red ink ({off} → {on})"); - let own = red(&draw(kind, true, true)); - assert!(own > off + 30, "{kind:?}: a series' own showVal shows its labels ({off} → {own})"); + let points = Chart::sample(kind).categories.len(); + let (off, on) = (draw(kind, false, false), draw(kind, true, false)); + assert!(red(&on) > red(&off), "{kind:?}: labels add red ink"); + assert!(label_runs(&off, &on) >= points, "{kind:?}: every point has its label ({} runs, {points} points)", label_runs(&off, &on)); + let own = draw(kind, true, true); + assert!(label_runs(&off, &own) >= points, "{kind:?}: a series' own showVal labels each of its points"); } // Area series keep none, and scatter and bubble series (drawn by the same code) are unchanged. for kind in [ChartType::Area, ChartType::Scatter, ChartType::Bubble] {