Skip to main content

Theme

Struct Theme 

Source
#[non_exhaustive]
pub struct Theme {
Show 39 fields pub text: String, pub text_secondary: String, pub text_strong: String, pub axis_line: String, pub tick: String, pub grid: String, pub bg: String, pub title_font_family: String, pub title_font_size: f32, pub title_font_weight: u16, pub title_font_style: String, pub label_font_family: String, pub label_font_size: f32, pub label_font_weight: u16, pub label_letter_spacing: f32, pub label_text_transform: TextTransform, pub numeric_font_family: String, pub numeric_font_size: f32, pub legend_font_family: String, pub legend_font_size: f32, pub legend_font_weight: u16, pub axis_line_weight: f32, pub grid_line_weight: f32, pub series_line_weight: f32, pub annotation_line_weight: f32, pub bar_corner_radius: BarCornerRadius, pub dot_radius: f32, pub dot_halo_color: Option<String>, pub dot_halo_width: f32, pub grid_style: GridStyle, pub zero_line: Option<ZeroLineSpec>, pub table_header_bg: String, pub table_header_text: String, pub table_row_bg: String, pub table_row_bg_alt: String, pub table_border: String, pub table_text: String, pub table_cell_padding: String, pub table_font_size: String,
}
Expand description

Chart theme — colors, typography, and shape defaults.

Color fields are CSS color strings (typically hex like "#374151") that are written directly into SVG stroke and fill attributes.

§Line weight audit (Phase 2)

Defaults for the stroke-weight fields were chosen by auditing every hardcoded stroke_width: Some(X.0) across the renderer crates and categorizing each by role. The audit found:

  • axis_line_weight = 1.0 — universal across chartml-chart-cartesian/src/helpers.rs (lines 419, 684, 756, 866, 957) and chartml-chart-scatter/src/lib.rs (lines 237, 242). All axis lines currently use 1.0. (Tick marks also use 1.0 today and reuse this field.)
  • grid_line_weight = 1.0 — universal across chartml-chart-cartesian/src/helpers.rs (lines 434, 780, 982) and chartml-chart-scatter/src/lib.rs (lines 168, 211).
  • series_line_weight = 2.0 — majority value in chartml-chart-cartesian/src/{line.rs:454, 563, 635}, area.rs:{212, 343, 481}, and bar.rs:1258 (combo line). Outlier: legend line symbols use 2.5 in bar.rs:1352 and chartml-core/src/layout/legend.rs:220 — this is a legend-specific glyph weight, not a series weight, and is intentionally not folded in. NOT included: chartml-chart-pie/src/lib.rs:75 (pie slice border). The pie slice border uses theme.bg as its color — it is a background-colored separator gap between slices, not a series mark, and must NOT be wired to series_line_weight in later phases.
  • annotation_line_weight = 1.0 — annotations currently read their stroke width from the spec (ann.stroke_width in helpers.rs:1348, 1382); no hardcoded default exists. 1.0 is chosen as the natural fallback for a future “annotation default” path (reference lines, brackets, etc.).
  • bar_corner_radius = BarCornerRadius::Uniform(0.0) — default is no rounding (byte-identical to pre-3.1 behavior). Uniform(r) rounds all four corners; Top(r) rounds only the two corners at the max-value end of the bar (see BarCornerRadius docs).
  • dot_radius = 5.0 — matches chartml-chart-scatter/src/lib.rs:106 (default when no size field) and line endpoint markers in chartml-chart-cartesian/src/line.rs:{466, 577, 649} and bar.rs:1268 (combo line dots).

§Construction contract

Theme is #[non_exhaustive]: external crates cannot construct it with a struct literal or the functional-update spread syntax. They must start from Theme::default() (or Theme::dark()) and mutate fields:

let mut theme = Theme::default();
theme.axis_line = "#9ca3af".into();
theme.grid = "#374151".into();

This makes adding new fields genuinely non-breaking forever — every downstream consumer that follows the mutate-after-default pattern keeps compiling regardless of how many fields land in Theme later.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§text: String

Primary text color (metric values, param controls).

§text_secondary: String

Secondary text color (tick labels, axis labels, legend labels).

§text_strong: String

Strong/emphasized text color (chart titles).

§axis_line: String

Axis line strokes (the main horizontal/vertical axis lines).

§tick: String

Tick mark strokes (small marks at each tick position).

§grid: String

Grid line strokes.

§bg: String

Background-aware stroke for element separators (pie slice borders, dot outlines). Should match the chart background.

§title_font_family: String

Font family for chart titles.

§title_font_size: f32

Font size (px) for chart titles.

§title_font_weight: u16

Font weight for chart titles.

§title_font_style: String

Font style ("normal" / "italic") for chart titles.

§label_font_family: String

Font family for tick and axis labels.

§label_font_size: f32

Font size (px) for tick and axis labels.

§label_font_weight: u16

Font weight for tick and axis labels.

§label_letter_spacing: f32

Extra letter spacing (px) applied to labels.

§label_text_transform: TextTransform

Text transform applied to labels.

§numeric_font_family: String

Font family for numeric tick labels (e.g. a tabular/monospaced face).

§numeric_font_size: f32

Font size (px) for numeric tick labels.

§legend_font_family: String

Font family for legend labels.

§legend_font_size: f32

Font size (px) for legend labels.

§legend_font_weight: u16

Font weight for legend labels.

§axis_line_weight: f32

Stroke width for axis lines. See audit in struct-level doc.

§grid_line_weight: f32

Stroke width for grid lines. See audit in struct-level doc.

§series_line_weight: f32

Stroke width for series marks (line paths, area outlines, combo line). Pie slice borders are NOT series marks — they use theme.bg as a background-colored separator. See audit in struct-level doc.

§annotation_line_weight: f32

Stroke width for annotation lines (reference lines, brackets). See audit in struct-level doc.

§bar_corner_radius: BarCornerRadius

Corner radius for bar rects. Supports uniform rounding (all four corners) and top-only rounding (the two corners at the max-value end of the bar). When the enclosed radius is 0.0, renderers MUST NOT emit any rx/ry attribute and MUST emit a plain <rect> (to preserve byte-identical output for un-themed charts).

§dot_radius: f32

Default radius (px) for scatter points and line endpoint markers.

§dot_halo_color: Option<String>

Optional halo/outline color for dots. When None, no halo is drawn.

§dot_halo_width: f32

Halo stroke width (px). Only used when dot_halo_color is Some.

§grid_style: GridStyle

Which gridlines to draw (both, horizontal-only, vertical-only, none).

§zero_line: Option<ZeroLineSpec>

Optional emphasized zero line on the value axis. None = no zero line.

§table_header_bg: String

Background color for the table header row.

§table_header_text: String

Text color for the table header row.

§table_row_bg: String

Background color for a regular (non-striped) body row.

§table_row_bg_alt: String

Background color for the alternating zebra-striped body row.

§table_border: String

Border color between cells and between header/body.

§table_text: String

Text color for body cells.

§table_cell_padding: String

CSS shorthand padding for body cells (e.g. "8px 12px").

§table_font_size: String

CSS font size for table text (e.g. "13px").

Implementations§

Source§

impl Theme

Source

pub fn dark() -> Self

Dark mode theme — matches the chartml.css dark-mode custom properties.

Typography and shape defaults are identical to Theme::default(); chrome color fields and table tokens are overridden to dark values.

Trait Implementations§

Source§

impl Clone for Theme

Source§

fn clone(&self) -> Theme

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Theme

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Theme

Source§

fn default() -> Self

Light mode theme — matches the chartml.css light-mode custom properties and all currently hardcoded renderer defaults.

Source§

impl PartialEq for Theme

Source§

fn eq(&self, other: &Theme) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Theme

Auto Trait Implementations§

§

impl Freeze for Theme

§

impl RefUnwindSafe for Theme

§

impl Send for Theme

§

impl Sync for Theme

§

impl Unpin for Theme

§

impl UnsafeUnpin for Theme

§

impl UnwindSafe for Theme

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,