Skip to main content

teksilo_core/styles/
chart_style.rs

1// SPDX-License-Identifier: MPL-2.0
2// SPDX-FileCopyrightText: 2026 FernTech
3
4//! Tier-3 style protocol for `BarChart` / `LineChart` / `PieChart` (teksilo-charts).
5//! Unlike every other Tier-3 trait, `ChartStyle` returns pure-data recipes only —
6//! no `make_*(cfg, ctx) -> WidgetId` methods (charts are batched-paint). `RecipeChartStyle`,
7//! the shipped default, lives in teksilo-charts itself (NOT teksilo-widgets), because
8//! teksilo-charts does not depend on teksilo-widgets. teksilo-core only holds the trait
9//! + the `Rc<dyn ChartStyle>` slot type.
10
11use teksilo_tokens::Color;
12
13use crate::styles::{BorderRecipe, FillRecipe, Theme};
14
15#[derive(Clone, Copy, Debug)]
16pub struct ChartFillContext<'a> {
17    pub series_index: usize,
18    pub resolved_color: Color,
19    pub theme: &'a Theme,
20}
21
22pub trait ChartStyle: 'static {
23    fn bar_fill(&self, cfg: &ChartFillContext) -> FillRecipe;
24    fn area_fill(&self, cfg: &ChartFillContext, opacity: f32) -> FillRecipe;
25    fn donut_fill(&self, cfg: &ChartFillContext) -> FillRecipe;
26    fn gridline(&self, theme: &Theme) -> BorderRecipe;
27}
28
29pub type SharedChartStyle = std::rc::Rc<dyn ChartStyle>;