Skip to main content

ChartModel

Struct ChartModel 

Source
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>

Source

pub fn new() -> Self

Create an empty chart model with no series.

Source

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).

Source

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.

Source

pub fn only_series(&self) -> Option<SeriesId>

The model’s sole series id, iff it has exactly one series.

Source

pub fn add_series(&self, name: impl Into<String>) -> SeriesId

Append a new, empty, visible series named name.

Source

pub fn insert_series(&self, index: usize, name: impl Into<String>) -> SeriesId

Insert a new, empty, visible series named name at index.

§Panics

Panics if index > series_count().

Source

pub fn remove_series(&self, series: SeriesId)

Remove a series and all of its points.

§Panics

Panics if series is unknown.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn clear(&self)

Remove every series.

Source

pub fn push_point(&self, series: SeriesId, category: T, value: f32)

Append a point to the end of series.

§Panics

Panics if series is unknown.

Source

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).

Source

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).

Source

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).

Source

pub fn replace_series_data(&self, series: SeriesId, points: Vec<ChartDatum<T>>)

Replace series’ entire point list.

§Panics

Panics if series is unknown.

Source

pub fn series_count(&self) -> usize

Number of series.

Source

pub fn series_ids(&self) -> Vec<SeriesId>

The series ids, in display order.

Source

pub fn series_id_at(&self, index: usize) -> Option<SeriesId>

The series id at index, if any.

Source

pub fn series_index_of(&self, series: SeriesId) -> Option<usize>

The display index of series, if it exists.

Source

pub fn point_count(&self, series: SeriesId) -> usize

Number of points in series (0 if unknown).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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>

Source

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).

Trait Implementations§

Source§

impl<T: 'static> Clone for ChartModel<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + 'static> Debug for ChartModel<T>

Source§

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

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

impl<T: 'static> Default for ChartModel<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for ChartModel<T>

§

impl<T> !Send for ChartModel<T>

§

impl<T> !Sync for ChartModel<T>

§

impl<T> !UnwindSafe for ChartModel<T>

§

impl<T> Freeze for ChartModel<T>

§

impl<T> Unpin for ChartModel<T>

§

impl<T> UnsafeUnpin for ChartModel<T>

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.