mirror of
https://github.com/storytold/deckcraft.git
synced 2026-12-01 02:04:59 -06:00
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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
fab5453a6e
commit
5d2e4eb3cc
+25
-12
@@ -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<bool> = (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] {
|
||||
|
||||
Reference in New Issue
Block a user