crisol-plot 1.13.0

Crisol plot: interactive 2D charts and a 3D sibling with SVG, PNG, and PDF export.
Documentation
//! Workbench theme → headless chart theme.

use crisol_core::color::Rgba;
use crisol_plot_core::spec::PlotTheme;
use crisol_ui_kit::theme::Theme;

fn rgba(color: egui::Color32) -> Rgba {
    Rgba::from_rgba_unmultiplied(color.r(), color.g(), color.b(), color.a())
}

/// The chart colors that match a workbench theme, for the desktop plot, exports, and
/// Theme Studio previews.
pub fn plot_theme(theme: &Theme) -> PlotTheme {
    PlotTheme {
        background: rgba(theme.background),
        plot_background: rgba(theme.surface),
        text: rgba(theme.text),
        axis: rgba(theme.border),
        grid: rgba(theme.hover),
        palette: vec![
            rgba(theme.link),
            rgba(theme.warning),
            rgba(theme.success),
            rgba(theme.danger),
            rgba(theme.done),
            rgba(theme.accent),
        ],
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crisol_ui_kit::theme::ThemeId;

    #[test]
    fn every_built_in_theme_has_a_six_color_chart_palette() {
        for id in ThemeId::ALL {
            let chart = plot_theme(&Theme::for_id(id));
            assert_eq!(chart.palette.len(), 6, "{id:?}");
            assert_eq!(chart.background.to_array()[3], 255);
        }
    }
}