Skip to main content

Module chart_model

Module chart_model 

Source
Expand description

ChartModel<T> — concrete reactive multi-series chart data model.

ChartModel<T> owns an ordered collection of named series, each holding a Vec<ChartDatum<T>> (a category: T paired with a numeric value: f32), in a flat SlotMap arena — the same shape as crate::TreeModel. Every mutation (series add/remove/move/rename/recolor/show-hide, point push/insert/remove/update/replace) emits a ChartChange to all registered observers and bumps one of two reactive version signals: ChartModel::style_version (color changes only — a paint-only signal a chart can bind at BindingLevel::RepaintOnly) or ChartModel::structure_version (everything else — series/point shape, bound at BindingLevel::Relayout/Rebuild). Series identity is a stable, versioned SeriesId (a SlotMap key) that is never reused after removal.

Cloning produces a second handle to the same data — all handles share series/points and receive the same change notifications. Register observers via observe_changes; the returned ObserverHandle is RAII — dropping it unregisters the callback.

For a bounded “last N points” streaming view use ChartWindow. For bucketed/rolled-up display use ChartAggregate. For point-level selection use ChartSelection.

let model = ChartModel::from_series_vec(vec![
    ChartSeries::new("Revenue").data(vec![
        ChartDatum::new("Q1".to_string(), 10.0),
        ChartDatum::new("Q2".to_string(), 20.0),
    ]),
]);
assert_eq!(model.series_count(), 1);
let s = model.series_id_at(0).unwrap();
assert_eq!(model.point_count(s), 2);

model.push_point(s, "Q3".to_string(), 30.0);
assert_eq!(model.point_count(s), 3);

Structs§

ChartDatum
One numeric data point at a category/x-axis position, with an optional per-point color that overrides the series color (bar charts only).
ChartModel
A concrete reactive multi-series chart data model.
ChartSeries
A named series of data points with an optional explicit color and a visibility flag, used to construct a ChartModel (via ChartModel::from_series_vec) or to describe one series’ desired shape. Unlike the model, visible here is a plain bool — reactivity lives in the model’s ChartModel::structure_version / ChartModel::style_version signals, not in this construction DTO.
SeriesView
A read-only, borrowed view over one series — returned by ChartModel::with_series_view / ChartModel::with_all_series.