forge_charts/series.rs
1//! Series metadata. Drives the legend + per-series CSS color hooks.
2
3/// What kind of geometry a [`Series`] renders.
4///
5/// v0.1 only supports `Area`; `Line` and `Bar` are placeholder
6/// variants the API will need when those chart types ship. Pattern-
7/// matching `non_exhaustive` so adding variants later isn't a
8/// breaking change.
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
10#[non_exhaustive]
11pub enum SeriesKind {
12 /// Filled area under the curve. Used by [`crate::AreaChart`].
13 Area,
14}
15
16/// One series in a chart. Carries display name + a CSS-class
17/// fragment consumers use to theme color.
18///
19/// The `color_class` becomes part of the CSS class on the rendered
20/// SVG group: `charts-series charts-series-<color_class>`. Consumers
21/// hook into that with their own CSS (or set `--charts-series-<color>`
22/// variables that the bundled stylesheet reads).
23#[derive(Debug, Clone, PartialEq, Eq, Hash)]
24pub struct Series {
25 pub name: String,
26 pub color_class: String,
27 pub kind: SeriesKind,
28}
29
30impl Series {
31 /// Filled area series. The most common factory.
32 #[must_use]
33 pub fn area(name: impl Into<String>, color_class: impl Into<String>) -> Self {
34 Self {
35 name: name.into(),
36 color_class: color_class.into(),
37 kind: SeriesKind::Area,
38 }
39 }
40}