Expand description
ChartWindow<T> — a “last N points per series” streaming projection over
a crate::ChartModel.
Wraps a ChartModel<T> and exposes the tail
window_size points of every series — the live-scrolling-strip-chart
pattern (a sensor feed, a log-rate graph, a stock ticker). Unlike
crate::ChartAggregate, ChartWindow copies no point data: it
tracks, per series, the source index of the window’s first visible point
(starts) and delegates every read straight through to the source. That
means a ChartWindow<T> needs no T: Clone bound at all.
§Reactivity
The upstream ChartChange stream is translated, not collapsed to a
blanket Reset (unlike crate::SortFilterListModel, where an
arbitrary sort-key move makes fine-grained translation unsafe — a
fixed-size tail window has no such hazard): a tail append into a full
window becomes a PointsRemoved + PointsInserted pair (the window
slides), a tail append into a still-growing window becomes a plain
PointsInserted, and symmetrically a tail removal (trimming the
series’ own end — e.g. discarding a bad trailing reading) becomes the
mirror-image PointsRemoved + PointsInserted pair: points beyond the
new total drop out of the window, and if the window slid backward to
stay full, the newly-uncovered prefix is revealed as an insertion.
Anything that isn’t a clean tail append/removal (a mid-series insert or
removal) falls back to a per-series rebuild reported as
SeriesDataReplaced.
use teksilo_data::{ChartModel, ChartWindow};
let model: ChartModel<i32> = ChartModel::new();
let s = model.add_series("sensor");
for i in 0..100 {
model.push_point(s, i, i as f32);
}
let window = ChartWindow::new(model.clone(), 10);
assert_eq!(window.point_count(s), 10); // last 10 points onlyStructs§
- Chart
Window - A “last N points per series” streaming projection over a
ChartModel<T>.