From 5d2e4eb3ccfd4e9d492602d89f6150679afc00a4 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sat, 28 Nov 2026 15:25:05 +0000 Subject: [PATCH] render: line chart value labels are checked per point, in any interface face line_chart_value_labels_are_drawn_above_their_points asked the labels to add 100 red pixels. The ink a label lays down depends on the interface face the build embeds: CI's build (no craft-fonts) passed, a build with craft-fonts embedded drew the same labels with 56 and failed, in production as in the port. The test now counts the labels' own columns of ink as separate runs and asks for one per point, which holds in any face and also catches a missing label the old total could hide. It fails with the labels off. Co-Authored-By: Claude Opus 5.5 --- crates/render/src/tests.rs | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) 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] {