pub struct ChartModel<T: 'static> { /* private fields */ }Expand description
A concrete reactive multi-series chart data model.
ChartModel<T> is Clone — cloning produces a second handle to the same
data. Multiple charts can hold clones and all see the same series and
points, and receive the same ChartChange notifications.
Implementations§
Source§impl<T: 'static> ChartModel<T>
impl<T: 'static> ChartModel<T>
Sourcepub fn from_series_vec(series: Vec<ChartSeries<T>>) -> Self
pub fn from_series_vec(series: Vec<ChartSeries<T>>) -> Self
Build a model directly from a vector of ChartSeries DTOs — the
primary constructor. Populates the arena in one pass with no
per-item notification (mirrors crate::ListModel::from_vec).
Sourcepub fn from_points(points: Vec<ChartDatum<T>>) -> Self
pub fn from_points(points: Vec<ChartDatum<T>>) -> Self
Build a model with a single anonymous, visible series holding
points — the flat/pie-chart path where series structure doesn’t
matter.
Sourcepub fn only_series(&self) -> Option<SeriesId>
pub fn only_series(&self) -> Option<SeriesId>
The model’s sole series id, iff it has exactly one series.
Sourcepub fn add_series(&self, name: impl Into<String>) -> SeriesId
pub fn add_series(&self, name: impl Into<String>) -> SeriesId
Append a new, empty, visible series named name.
Sourcepub fn remove_series(&self, series: SeriesId)
pub fn remove_series(&self, series: SeriesId)
Sourcepub fn rename_series(&self, series: SeriesId, name: impl Into<String>)
pub fn rename_series(&self, series: SeriesId, name: impl Into<String>)
Rename a series. A no-op (no notify, no version bump) if name
already matches the current value.
§Panics
Panics if series is unknown.
Sourcepub fn set_series_color(&self, series: SeriesId, color: impl Into<ColorProp>)
pub fn set_series_color(&self, series: SeriesId, color: impl Into<ColorProp>)
Set a series’ explicit color. Bumps Self::style_version (not
Self::structure_version) — this is a paint-only change. A no-op
(no notify, no version bump) if color already matches the current
value.
§Panics
Panics if series is unknown.
Sourcepub fn clear_series_color(&self, series: SeriesId)
pub fn clear_series_color(&self, series: SeriesId)
Clear a series’ explicit color (falls back to the chart’s palette).
Bumps Self::style_version. A no-op (no notify, no version bump)
if the series already has no explicit color.
§Panics
Panics if series is unknown.
Sourcepub fn set_series_pattern(&self, series: SeriesId, pattern: SeriesPattern)
pub fn set_series_pattern(&self, series: SeriesId, pattern: SeriesPattern)
Set a series’ explicit SeriesPattern — the non-colour channel that
identifies it. Bumps Self::style_version (paint-only), like
set_series_color. A no-op if unchanged.
§Panics
Panics if series is unknown.
Sourcepub fn clear_series_pattern(&self, series: SeriesId)
pub fn clear_series_pattern(&self, series: SeriesId)
Clear a series’ explicit pattern, falling back to the one its position
implies. Bumps Self::style_version. A no-op if already unset.
§Panics
Panics if series is unknown.
Sourcepub fn set_series_visible(&self, series: SeriesId, visible: bool)
pub fn set_series_visible(&self, series: SeriesId, visible: bool)
Show or hide a series. A no-op (no notify, no version bump) if
visible already matches the current value.
§Panics
Panics if series is unknown.
Sourcepub fn move_series(&self, series: SeriesId, to: usize)
pub fn move_series(&self, series: SeriesId, to: usize)
Move a series to a new position among its siblings. A no-op (no
notify, no version bump) if to is already the series’ position.
§Panics
Panics if series is unknown or to is out of bounds.
Sourcepub fn push_point(&self, series: SeriesId, category: T, value: f32)
pub fn push_point(&self, series: SeriesId, category: T, value: f32)
Sourcepub fn insert_point(
&self,
series: SeriesId,
index: usize,
category: T,
value: f32,
)
pub fn insert_point( &self, series: SeriesId, index: usize, category: T, value: f32, )
Insert a point at index within series.
§Panics
Panics if series is unknown or index > point_count(series).
Sourcepub fn remove_point(&self, series: SeriesId, index: usize) -> ChartDatum<T>
pub fn remove_point(&self, series: SeriesId, index: usize) -> ChartDatum<T>
Remove and return the point at index within series.
§Panics
Panics if series is unknown or index >= point_count(series).
Sourcepub fn update_point(
&self,
series: SeriesId,
index: usize,
category: T,
value: f32,
)
pub fn update_point( &self, series: SeriesId, index: usize, category: T, value: f32, )
Replace the point at index within series.
§Panics
Panics if series is unknown or index >= point_count(series).
Sourcepub fn replace_series_data(&self, series: SeriesId, points: Vec<ChartDatum<T>>)
pub fn replace_series_data(&self, series: SeriesId, points: Vec<ChartDatum<T>>)
Sourcepub fn series_count(&self) -> usize
pub fn series_count(&self) -> usize
Number of series.
Sourcepub fn series_ids(&self) -> Vec<SeriesId>
pub fn series_ids(&self) -> Vec<SeriesId>
The series ids, in display order.
Sourcepub fn series_id_at(&self, index: usize) -> Option<SeriesId>
pub fn series_id_at(&self, index: usize) -> Option<SeriesId>
The series id at index, if any.
Sourcepub fn series_index_of(&self, series: SeriesId) -> Option<usize>
pub fn series_index_of(&self, series: SeriesId) -> Option<usize>
The display index of series, if it exists.
Sourcepub fn point_count(&self, series: SeriesId) -> usize
pub fn point_count(&self, series: SeriesId) -> usize
Number of points in series (0 if unknown).
Sourcepub fn with_series<R>(
&self,
series: SeriesId,
f: impl FnOnce(&str, Option<&ColorProp>, bool) -> R,
) -> Option<R>
pub fn with_series<R>( &self, series: SeriesId, f: impl FnOnce(&str, Option<&ColorProp>, bool) -> R, ) -> Option<R>
Access a series’ metadata (name, color, visibility) via a callback.
Returns None if series is unknown.
Sourcepub fn with_point<R>(
&self,
series: SeriesId,
index: usize,
f: impl FnOnce(&ChartDatum<T>) -> R,
) -> Option<R>
pub fn with_point<R>( &self, series: SeriesId, index: usize, f: impl FnOnce(&ChartDatum<T>) -> R, ) -> Option<R>
Access a point within series via a callback. Returns None if the
series or index is unknown.
Sourcepub fn with_series_view<R>(
&self,
series: SeriesId,
f: impl FnOnce(SeriesView<'_, T>) -> R,
) -> Option<R>
pub fn with_series_view<R>( &self, series: SeriesId, f: impl FnOnce(SeriesView<'_, T>) -> R, ) -> Option<R>
Access a whole-series view (metadata + points slice) via a callback.
Returns None if series is unknown.
Sourcepub fn with_all_series<R>(&self, f: impl FnOnce(&[SeriesView<'_, T>]) -> R) -> R
pub fn with_all_series<R>(&self, f: impl FnOnce(&[SeriesView<'_, T>]) -> R) -> R
Access every series as an ordered slice of views via a callback.
Sourcepub fn structure_version(&self) -> Signal<u64>
pub fn structure_version(&self) -> Signal<u64>
Structural version signal — bumped by every mutation except a color
change (series add/remove/move/rename/show-hide, all point ops).
Bind at BindingLevel::Relayout or Rebuild.
Ordering: every mutator notifies the ChartChange observers
registered via Self::observe_changes before bumping this
signal — see the note on observe_changes for what that means for a
callback that reads the signal back synchronously.
Sourcepub fn style_version(&self) -> Signal<u64>
pub fn style_version(&self) -> Signal<u64>
Style version signal — bumped only by a series color change. Bind at
BindingLevel::RepaintOnly. Same notify-before-bump ordering as
Self::structure_version — see Self::observe_changes.
Sourcepub fn observe_changes(
&self,
f: impl Fn(&ChartChange) + 'static,
) -> ObserverHandle
pub fn observe_changes( &self, f: impl Fn(&ChartChange) + 'static, ) -> ObserverHandle
Register an observer that is called on every mutation.
Returns an ObserverHandle — dropping it removes the callback.
Ordering contract: every mutator calls this observer before
bumping Self::structure_version / Self::style_version (see
e.g. rename_series, push_point) — notify, then bump. This is
intentional, not an implementation accident: it lets a ChartChange
callback distinguish “did I get here via the change I’m reacting to”
from “did something else bump the version already”, by comparing the
version signal’s value inside the callback against a value captured
before the mutation. The flip side: a callback that reads
structure_version()/style_version() synchronously inside
itself always observes the pre-bump value for the mutation
currently being notified — the bump hasn’t happened yet. Don’t use
the version signal from inside a ChartChange observer as a proxy
for “has this specific mutation been applied” — the ChartChange
argument already tells you that; use the signal for external
bind-and-rerun consumers (widgets), not from within the notify path
itself.
Source§impl<T: Debug + 'static> ChartModel<T>
impl<T: Debug + 'static> ChartModel<T>
Sourcepub fn debug_named(self, _name: impl Into<String>) -> Self
pub fn debug_named(self, _name: impl Into<String>) -> Self
Register this model with the debug inspector under name. In
release builds (!cfg(debug_assertions)) this is a no-op
pass-through so call sites stay free of #[cfg] lines.
Idempotent on repeated calls — the latest registration wins.
The registration drops automatically when the last ChartModel
handle is freed (the adapter the registry holds is Weak).