pub struct StreamingChart { /* private fields */ }Expand description
A wrapper around Chart that automatically manages caching for live updates.
StreamingChart tracks dirty state and provides efficient methods for
updating chart data in real-time scenarios.
§Example
use astrelis_geometry::chart::*;
// Create a streaming chart for sensor data
let chart = ChartBuilder::line()
.add_series("Temperature", &[])
.interactive(true)
.build();
let mut streaming = StreamingChart::new(chart);
// In your update loop:
streaming.push_point(0, DataPoint::new(timestamp, temperature), Some(1000));
// Before rendering:
streaming.prepare_render(&bounds);
// Render using cached data
chart_renderer.draw(streaming.chart(), bounds);Implementations§
Source§impl StreamingChart
impl StreamingChart
Sourcepub fn chart_mut(&mut self) -> &mut Chart
pub fn chart_mut(&mut self) -> &mut Chart
Get a mutable reference to the underlying chart.
Note: Direct mutations bypass dirty tracking. Prefer using the streaming-specific methods when possible.
Sourcepub fn cache(&self) -> &ChartCache
pub fn cache(&self) -> &ChartCache
Get a reference to the cache.
Sourcepub fn cache_mut(&mut self) -> &mut ChartCache
pub fn cache_mut(&mut self) -> &mut ChartCache
Get a mutable reference to the cache.
Sourcepub fn needs_rebuild(&self) -> bool
pub fn needs_rebuild(&self) -> bool
Check if the cache needs to be rebuilt before rendering.
Sourcepub fn prepare_render(&mut self, bounds: &Rect)
pub fn prepare_render(&mut self, bounds: &Rect)
Prepare the chart for rendering by rebuilding the cache if needed.
Sourcepub fn append_data(&mut self, series_idx: usize, points: &[DataPoint])
pub fn append_data(&mut self, series_idx: usize, points: &[DataPoint])
Append data points to a series.
This method tracks the change for efficient partial cache updates.
Sourcepub fn push_point(
&mut self,
series_idx: usize,
point: DataPoint,
max_points: Option<usize>,
)
pub fn push_point( &mut self, series_idx: usize, point: DataPoint, max_points: Option<usize>, )
Push a single point with optional sliding window.
If max_points causes data to be removed, this marks as a full
data change. Otherwise, it marks as an append for partial updates.
Sourcepub fn set_data(&mut self, series_idx: usize, data: Vec<DataPoint>)
pub fn set_data(&mut self, series_idx: usize, data: Vec<DataPoint>)
Replace all data in a series.
Sourcepub fn clear_data(&mut self, series_idx: usize)
pub fn clear_data(&mut self, series_idx: usize)
Clear all data from a series.
Sourcepub fn mark_view_changed(&mut self)
pub fn mark_view_changed(&mut self)
Notify that the view has changed (pan/zoom).
Call this after modifying chart.interactive.pan_offset or
chart.interactive.zoom.
Sourcepub fn mark_style_changed(&mut self)
pub fn mark_style_changed(&mut self)
Notify that style has changed.
Sourcepub fn mark_axes_changed(&mut self)
pub fn mark_axes_changed(&mut self)
Notify that axes have changed.
Sourcepub fn mark_bounds_changed(&mut self)
pub fn mark_bounds_changed(&mut self)
Notify that bounds have changed.
Sourcepub fn dirty_flags(&self) -> ChartDirtyFlags
pub fn dirty_flags(&self) -> ChartDirtyFlags
Get the current dirty flags.
Sourcepub fn clear_dirty(&mut self)
pub fn clear_dirty(&mut self)
Manually clear dirty flags (normally done by prepare_render).
Sourcepub fn push_time_point(&mut self, series_idx: usize, time: f64, value: f64)
pub fn push_time_point(&mut self, series_idx: usize, time: f64, value: f64)
Push a time/value point to a series.
Convenient method for time series data.
Sourcepub fn push_time_point_windowed(
&mut self,
series_idx: usize,
time: f64,
value: f64,
max_points: usize,
)
pub fn push_time_point_windowed( &mut self, series_idx: usize, time: f64, value: f64, max_points: usize, )
Push a time/value point with sliding window.
Sourcepub fn auto_scroll(&mut self, axis_id: AxisId, window_size: f64)
pub fn auto_scroll(&mut self, axis_id: AxisId, window_size: f64)
Sourcepub fn disable_auto_scroll(&mut self, axis_id: AxisId)
pub fn disable_auto_scroll(&mut self, axis_id: AxisId)
Disable auto-scrolling for an axis.
Sourcepub fn apply_auto_scroll(&mut self)
pub fn apply_auto_scroll(&mut self)
Apply auto-scroll to update axis ranges.
Call this after pushing data to adjust the view window.
Sourcepub fn prepare_render_with_result(&mut self, bounds: &Rect) -> PrepareResult
pub fn prepare_render_with_result(&mut self, bounds: &Rect) -> PrepareResult
Prepare for rendering and return detailed update information.
Sourcepub fn get_display_data(
&self,
series_idx: usize,
pixel_width: f32,
) -> Vec<DataPoint>
pub fn get_display_data( &self, series_idx: usize, pixel_width: f32, ) -> Vec<DataPoint>
Get display data for a series, downsampled if necessary.
Uses LTTB (Largest Triangle Three Buckets) algorithm to preserve visual features while reducing point count for rendering.
§Arguments
series_idx- Index of the seriespixel_width- Width of the display area in pixels
§Returns
Downsampled data points optimized for the given pixel width. If the data has fewer points than pixels, returns all points.
Sourcepub fn get_all_display_data(&self, pixel_width: f32) -> Vec<Vec<DataPoint>>
pub fn get_all_display_data(&self, pixel_width: f32) -> Vec<Vec<DataPoint>>
Get downsampled data for all series.
Sourcepub fn statistics(&self) -> StreamingStatistics
pub fn statistics(&self) -> StreamingStatistics
Get statistics about the streaming data.
Methods from Deref<Target = Chart>§
Sourcepub fn series_len(&self, series_idx: usize) -> usize
pub fn series_len(&self, series_idx: usize) -> usize
Get the number of data points in a series.
Sourcepub fn total_points(&self) -> usize
pub fn total_points(&self) -> usize
Get the total number of data points across all series.
Sourcepub fn data_bounds_for_axis(&self, axis_id: AxisId) -> Option<(f64, f64)>
pub fn data_bounds_for_axis(&self, axis_id: AxisId) -> Option<(f64, f64)>
Get the combined bounds of all series for a specific axis.
Sourcepub fn data_bounds(&self) -> Option<(DataPoint, DataPoint)>
pub fn data_bounds(&self) -> Option<(DataPoint, DataPoint)>
Get the combined bounds of all series.
Sourcepub fn axis_range(&self, axis_id: AxisId) -> (f64, f64)
pub fn axis_range(&self, axis_id: AxisId) -> (f64, f64)
Get the effective range for an axis.
Trait Implementations§
Source§impl Debug for StreamingChart
impl Debug for StreamingChart
Source§impl Deref for StreamingChart
impl Deref for StreamingChart
Auto Trait Implementations§
impl Freeze for StreamingChart
impl RefUnwindSafe for StreamingChart
impl Send for StreamingChart
impl Sync for StreamingChart
impl Unpin for StreamingChart
impl UnsafeUnpin for StreamingChart
impl UnwindSafe for StreamingChart
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more