Expand description
ChartSelection — point-level selection state for chart widgets.
ChartSelection manages which (series, point index) pairs are
selected across a crate::ChartModel — the chart counterpart of
crate::SelectionModel (flat lists) and
crate::KeyedSelectionModel (keyed collections). It is a
share-by-clone handle: pass a clone to each chart that should share
selection state. The current selection is exposed as a reactive
Signal<HashSet<(SeriesId, usize)>> so widgets can bind to it without
polling.
HashSet (not BTreeSet) is used because SeriesId is intentionally
not Ord (it’s an opaque SlotMap key, mirroring crate::NodeId) —
there is no natural ordering across series, only within one series’
point indices. This is the same rationale as
crate::KeyedSelectionModel, which uses HashSet<K> for the same
reason.
Three selection behaviours are available via
SelectionMode: None, Single, and Multi
(toggle + anchor-based range extension). ChartSelection::extend_to
only extends within the anchor’s own series — a cross-series “range” has
no natural order, so it falls back to a single-point select.
ChartSelection::adjust keeps selected points consistent as the
source model mutates (series removed, points inserted/removed) — call it
from your own model observer, or skip the wiring entirely with
ChartSelection::attached (equivalently, ChartSelection::attach on
an existing selection), which subscribes internally and calls adjust
for you, the same way crate::ChartWindow/crate::ChartAggregate
self-wire in their own constructors. Forgetting to wire adjust up
manually otherwise leaves the selection silently stale after a mutation.
let model: ChartModel<i32> = ChartModel::new();
let s = model.add_series("s");
for i in 0..5 {
model.push_point(s, i, i as f32);
}
let sel = ChartSelection::attached(SelectionMode::Multi, &model);
sel.select_point(s, 1);
sel.extend_to(s, 3);
assert_eq!(sel.count(), 3); // (s,1), (s,2), (s,3)
model.remove_point(s, 0); // upstream mutation — no manual adjust() call
assert_eq!(sel.count(), 3); // (s,0), (s,1), (s,2) — shifted down
sel.clear();
assert_eq!(sel.count(), 0);Structs§
- Chart
Selection - Point-level selection state for a chart, keyed by
(series, point index). See module documentation for semantics.