mirror of
https://github.com/storytold/deckcraft.git
synced 2026-10-24 10:37:03 -06:00
Pie data labels take the chart's text colour when it has one
A textColor set on a chart (chart.options, or Font Color with the chart selected) coloured the title, axes and legend but left a pie's data labels white. They stay white by default, on the slices, and follow a colour the chart's text was given. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
be9bf48eb2
commit
30b7eff487
@@ -324,7 +324,8 @@ fn draw_inner(ctx: &mut RenderContext, rctx: &Ctx, c: &Chart, m: Affine, w: f64,
|
||||
base,
|
||||
Align::Center,
|
||||
Anchor::Middle,
|
||||
Rgba::WHITE,
|
||||
// On the slices themselves: white, unless the chart's text was given a colour.
|
||||
if c.text_color.is_some() { text_col } else { Rgba::WHITE },
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2747,3 +2747,27 @@ fn chart_text_follows_the_theme_when_it_has_no_colour_of_its_own() {
|
||||
let dark_ink = count(&light_titled, &|l| l < 80) as i64 - count(&light_bare, &|l| l < 80) as i64;
|
||||
assert!(dark_ink > 100, "the title is dark on a light theme (dark pixels added: {dark_ink})");
|
||||
}
|
||||
|
||||
/// Pie data labels sit on the slices in white; a colour given to the chart's text (chart.options
|
||||
/// textColor, Font Color on the chart) colours them too, as it does the title and legend.
|
||||
#[test]
|
||||
fn pie_data_labels_take_the_chart_text_colour_when_it_has_one() {
|
||||
let draw = |colour: Option<ColorRef>| {
|
||||
let mut c = Chart::sample(ChartType::Pie);
|
||||
c.title = None;
|
||||
c.legend = None;
|
||||
c.data_labels = true;
|
||||
c.text_color = colour;
|
||||
let sh = Shape { id: ShapeId(632), xfrm: Some(Xfrm::new(0.0, 0.0, 400.0, 400.0)), kind: ShapeKind::Chart(Box::new(c)), ..Default::default() };
|
||||
render_slide(&deck_with(vec![sh]), 0, &RenderOpts { scale: 1.0, ..Default::default() })
|
||||
};
|
||||
let count = |img: &Image, f: &dyn Fn([u8; 4]) -> bool| {
|
||||
(0..400u32).flat_map(|x| (0..400u32).map(move |y| (x, y))).filter(|(x, y)| f(img.pixel(*x, *y))).count()
|
||||
};
|
||||
let red = |p: [u8; 4]| p[0] > 200 && p[1] < 60 && p[2] < 60;
|
||||
let white = |p: [u8; 4]| p[0] > 245 && p[1] > 245 && p[2] > 245;
|
||||
let (plain, coloured) = (draw(None), draw(Some(ColorRef::rgb(deckcraft_color::Rgba::rgb(255, 0, 0)))));
|
||||
assert_eq!(count(&plain, &red), 0, "no red without a text colour");
|
||||
assert!(count(&coloured, &red) > 30, "the labels take the chart's red: {} red pixels", count(&coloured, &red));
|
||||
assert!(count(&plain, &white) > count(&coloured, &white), "the labels were white before");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user