pub struct ChartSelection { /* private fields */ }Expand description
Point-level selection state for a chart, keyed by (series, point index). See module documentation for semantics.
Implementations§
Source§impl ChartSelection
impl ChartSelection
Sourcepub fn new(mode: SelectionMode) -> Self
pub fn new(mode: SelectionMode) -> Self
Create a new chart selection with the given mode.
Sourcepub fn attached<T: 'static>(mode: SelectionMode, model: &ChartModel<T>) -> Self
pub fn attached<T: 'static>(mode: SelectionMode, model: &ChartModel<T>) -> Self
Create a selection that self-wires to model: every ChartChange
the model emits is automatically routed through Self::adjust, so
a point removed or shifted upstream never leaves a stale selected
index behind. Equivalent to ChartSelection::new(mode) plus
model.observe_changes(|c| sel.adjust(c)), minus the easy-to-forget
wiring — mirrors how crate::ChartWindow and
crate::ChartAggregate self-wire in their own constructors. The
manual Self::adjust path still works — call it yourself instead
if you’d rather relay through a custom change pipeline.
Sourcepub fn attach<T: 'static>(&self, model: &ChartModel<T>)
pub fn attach<T: 'static>(&self, model: &ChartModel<T>)
Subscribe this selection to model’s changes, applying
Self::adjust on every ChartChange. The subscription is held
internally (shared across clones — see Clone), so it stays alive
as long as any handle to this selection does; calling attach
again (on this handle or any clone) drops the previous subscription
and installs the new one.
The subscription closure captures only selection + anchor, not a
full Self — capturing Self would pull in attach_handle too,
which holds this very ObserverHandle, forming an Rc cycle that
would leak the subscription instead of tearing down when every
ChartSelection handle drops.
Sourcepub fn mode(&self) -> SelectionMode
pub fn mode(&self) -> SelectionMode
The selection mode.
Sourcepub fn selection_signal(&self) -> Signal<HashSet<(SeriesId, usize)>>
pub fn selection_signal(&self) -> Signal<HashSet<(SeriesId, usize)>>
A clone of the selection signal for reactive binding.
Sourcepub fn is_selected(&self, series: SeriesId, index: usize) -> bool
pub fn is_selected(&self, series: SeriesId, index: usize) -> bool
Whether (series, index) is currently selected.
Sourcepub fn selected_points(&self) -> Vec<(SeriesId, usize)>
pub fn selected_points(&self) -> Vec<(SeriesId, usize)>
The currently selected points (unordered snapshot).
Sourcepub fn select_point(&self, series: SeriesId, index: usize)
pub fn select_point(&self, series: SeriesId, index: usize)
Select a single point, clearing the previous selection and setting the anchor.
Sourcepub fn toggle_point(&self, series: SeriesId, index: usize)
pub fn toggle_point(&self, series: SeriesId, index: usize)
Toggle a point (Ctrl+click in Multi mode; acts as select_point in
Single mode).
Sourcepub fn extend_to(&self, series: SeriesId, target: usize)
pub fn extend_to(&self, series: SeriesId, target: usize)
Extend the selection from the anchor to (series, target) (for
Shift+click). Only extends within the anchor’s own series — if
the anchor is unset or belongs to a different series, falls back to
a single-point select of (series, target).
Sourcepub fn select_points(
&self,
points: impl IntoIterator<Item = (SeriesId, usize)>,
additive: bool,
)
pub fn select_points( &self, points: impl IntoIterator<Item = (SeriesId, usize)>, additive: bool, )
Replace the selection with points (or, when additive, union
them into the current selection). Used by rubber-band / marquee
selection. In Single mode an arbitrary one wins; None mode is a
no-op.
Sourcepub fn adjust(&self, change: &ChartChange)
pub fn adjust(&self, change: &ChartChange)
React to an upstream ChartChange, keeping selection consistent
with the model: a removed or wholesale-replaced series drops its
selected points (and the anchor, if it pointed there); point
insertions/removals shift or drop indices within their series.
Series metadata changes (rename/recolor/visibility/move/insert) and
in-place point updates never affect which points are selected.
Source§impl ChartSelection
impl ChartSelection
Sourcepub fn debug_named(self, _name: impl Into<String>) -> Self
pub fn debug_named(self, _name: impl Into<String>) -> Self
Register this selection 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 ChartSelection
handle is freed (the strong adapter Rc lives inside a shared
holder; the registry holds only a Weak).