Skip to main content

StreamingChart

Struct StreamingChart 

Source
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

Source

pub fn new(chart: Chart) -> Self

Create a new streaming chart wrapper.

Source

pub fn chart(&self) -> &Chart

Get a reference to the underlying chart.

Source

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.

Source

pub fn cache(&self) -> &ChartCache

Get a reference to the cache.

Source

pub fn cache_mut(&mut self) -> &mut ChartCache

Get a mutable reference to the cache.

Source

pub fn needs_rebuild(&self) -> bool

Check if the cache needs to be rebuilt before rendering.

Source

pub fn prepare_render(&mut self, bounds: &Rect)

Prepare the chart for rendering by rebuilding the cache if needed.

Source

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.

Source

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.

Source

pub fn set_data(&mut self, series_idx: usize, data: Vec<DataPoint>)

Replace all data in a series.

Source

pub fn clear_data(&mut self, series_idx: usize)

Clear all data from a series.

Source

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.

Source

pub fn mark_style_changed(&mut self)

Notify that style has changed.

Source

pub fn mark_axes_changed(&mut self)

Notify that axes have changed.

Source

pub fn mark_bounds_changed(&mut self)

Notify that bounds have changed.

Source

pub fn dirty_flags(&self) -> ChartDirtyFlags

Get the current dirty flags.

Source

pub fn clear_dirty(&mut self)

Manually clear dirty flags (normally done by prepare_render).

Source

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.

Source

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.

Source

pub fn auto_scroll(&mut self, axis_id: AxisId, window_size: f64)

Configure auto-scrolling for an axis.

When enabled, the axis range will automatically shift to show the most recent window_size units of data.

§Example
// Show the last 60 seconds of data
streaming.auto_scroll(AxisId::X_PRIMARY, 60.0);
Source

pub fn disable_auto_scroll(&mut self, axis_id: AxisId)

Disable auto-scrolling for an axis.

Source

pub fn apply_auto_scroll(&mut self)

Apply auto-scroll to update axis ranges.

Call this after pushing data to adjust the view window.

Source

pub fn prepare_render_with_result(&mut self, bounds: &Rect) -> PrepareResult

Prepare for rendering and return detailed update information.

Source

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 series
  • pixel_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.

Source

pub fn get_all_display_data(&self, pixel_width: f32) -> Vec<Vec<DataPoint>>

Get downsampled data for all series.

Source

pub fn statistics(&self) -> StreamingStatistics

Get statistics about the streaming data.

Methods from Deref<Target = Chart>§

Source

pub fn series_len(&self, series_idx: usize) -> usize

Get the number of data points in a series.

Source

pub fn total_points(&self) -> usize

Get the total number of data points across all series.

Source

pub fn get_axis(&self, id: AxisId) -> Option<&Axis>

Get an axis by ID.

Source

pub fn x_axis(&self) -> Option<&Axis>

Get the X axis (primary).

Source

pub fn y_axis(&self) -> Option<&Axis>

Get the Y axis (primary).

Source

pub fn data_bounds_for_axis(&self, axis_id: AxisId) -> Option<(f64, f64)>

Get the combined bounds of all series for a specific axis.

Source

pub fn data_bounds(&self) -> Option<(DataPoint, DataPoint)>

Get the combined bounds of all series.

Source

pub fn axis_range(&self, axis_id: AxisId) -> (f64, f64)

Get the effective range for an axis.

Source

pub fn x_range(&self) -> (f64, f64)

Get the effective X range (respecting axis min/max overrides).

Source

pub fn y_range(&self) -> (f64, f64)

Get the effective Y range (respecting axis min/max overrides).

Trait Implementations§

Source§

impl Debug for StreamingChart

Source§

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

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

impl Deref for StreamingChart

Source§

type Target = Chart

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl From<Chart> for StreamingChart

Source§

fn from(chart: Chart) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

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

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

Convert &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)

Convert &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
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,