crisol_plot/
chart_theme.rs1use crisol_core::color::Rgba;
4use crisol_plot_core::spec::PlotTheme;
5use crisol_ui_kit::theme::Theme;
6
7fn rgba(color: egui::Color32) -> Rgba {
8 Rgba::from_rgba_unmultiplied(color.r(), color.g(), color.b(), color.a())
9}
10
11pub fn plot_theme(theme: &Theme) -> PlotTheme {
14 PlotTheme {
15 background: rgba(theme.background),
16 plot_background: rgba(theme.surface),
17 text: rgba(theme.text),
18 axis: rgba(theme.border),
19 grid: rgba(theme.hover),
20 palette: vec![
21 rgba(theme.link),
22 rgba(theme.warning),
23 rgba(theme.success),
24 rgba(theme.danger),
25 rgba(theme.done),
26 rgba(theme.accent),
27 ],
28 }
29}
30
31#[cfg(test)]
32mod tests {
33 use super::*;
34 use crisol_ui_kit::theme::ThemeId;
35
36 #[test]
37 fn every_built_in_theme_has_a_six_color_chart_palette() {
38 for id in ThemeId::ALL {
39 let chart = plot_theme(&Theme::for_id(id));
40 assert_eq!(chart.palette.len(), 6, "{id:?}");
41 assert_eq!(chart.background.to_array()[3], 255);
42 }
43 }
44}