Skip to main content

GpuStreamingChart

Struct GpuStreamingChart 

Source
pub struct GpuStreamingChart { /* private fields */ }
Expand description

GPU-accelerated streaming chart for high-performance live data visualization.

Combines StreamingChart functionality with GPU-accelerated renderers for efficient rendering of large datasets. The GPU path is automatically used when series exceed GPU_RENDER_THRESHOLD points.

Supports all chart types:

  • Line: GPU-instanced line segments via GpuChartLineRenderer
  • Scatter: GPU-instanced points via GpuChartScatterRenderer
  • Bar: GPU-instanced quads via GpuChartBarRenderer
  • Area: GPU-instanced fill + lines via GpuChartAreaRenderer

§Performance Characteristics

OperationCPU PathGPU Path
Data appendO(n) tessellationO(n) buffer upload (once)
Pan/zoomO(n) tessellationO(1) uniform update
RenderO(n) trianglesO(n) instances

§Text Rendering (with chart-text feature)

When the chart-text feature is enabled, use with_text() to add text rendering:

let font_system = FontSystem::with_system_fonts();
let gpu_chart = GpuStreamingChart::new(chart, context.clone(), surface_format)
    .with_text(context.clone(), font_system);

§Example

use astrelis_geometry::chart::*;
use astrelis_render::GraphicsContext;
use std::sync::Arc;

let context: Arc<GraphicsContext> = /* ... */;
let surface_format = window.surface_format();
let chart = ChartBuilder::line()
    .add_series("Sensor", &[])
    .interactive(true)
    .build();

let mut gpu_chart = GpuStreamingChart::new(chart, context, surface_format);

// In update loop:
gpu_chart.push_time_point(0, time, value);
gpu_chart.auto_scroll(AxisId::X_PRIMARY, 60.0);

// Before rendering:
let bounds = Rect::new(0.0, 0.0, 800.0, 600.0);
gpu_chart.prepare_render(&bounds);

// In render pass:
gpu_chart.render(&mut pass, viewport, &bounds);

Implementations§

Source§

impl GpuStreamingChart

Source

pub fn new( chart: Chart, context: Arc<GraphicsContext>, target_format: TextureFormat, ) -> Self

Create a new GPU-accelerated streaming chart.

The target_format must match the render target this chart will draw into.

Source

pub fn from_streaming( streaming: StreamingChart, context: Arc<GraphicsContext>, target_format: TextureFormat, ) -> Self

Create from an existing streaming chart.

The target_format must match the render target this chart will draw into.

Source

pub fn force_gpu_rendering(self, force: bool) -> Self

Force GPU rendering regardless of data size.

Useful for testing or when you know data will grow large.

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.

Source

pub fn streaming(&self) -> &StreamingChart

Get a reference to the underlying streaming chart.

Source

pub fn streaming_mut(&mut self) -> &mut StreamingChart

Get a mutable reference to the underlying streaming chart.

Source

pub fn line_renderer(&self) -> &GpuChartLineRenderer

Get a reference to the GPU line renderer.

Source

pub fn line_renderer_mut(&mut self) -> &mut GpuChartLineRenderer

Get a mutable reference to the GPU line renderer.

Source

pub fn scatter_renderer(&self) -> &GpuChartScatterRenderer

Get a reference to the GPU scatter renderer.

Source

pub fn bar_renderer(&self) -> &GpuChartBarRenderer

Get a reference to the GPU bar renderer.

Source

pub fn area_renderer(&self) -> &GpuChartAreaRenderer

Get a reference to the GPU area renderer.

Source

pub fn is_gpu_enabled(&self) -> bool

Check if GPU rendering is currently enabled.

Source

pub fn append_data(&mut self, series_idx: usize, points: &[DataPoint])

Append data points to a series.

Source

pub fn push_point( &mut self, series_idx: usize, point: DataPoint, max_points: Option<usize>, )

Push a single point with optional sliding window.

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 push_time_point(&mut self, series_idx: usize, time: f64, value: f64)

Push a time/value point to a series.

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.

Source

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

Disable auto-scrolling for an axis.

Source

pub fn mark_view_changed(&mut self)

Notify that the view has changed (pan/zoom).

Source

pub fn mark_style_changed(&mut self)

Notify that style has changed.

Source

pub fn mark_bounds_changed(&mut self)

Notify that bounds have changed (widget resized).

Source

pub fn dirty_flags(&self) -> ChartDirtyFlags

Get the current dirty flags.

Source

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

Prepare the chart for rendering.

This prepares both the coordinate cache and GPU buffers as needed. Call this once per frame before rendering.

Source

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

Prepare with detailed result information.

Source

pub fn render( &self, pass: &mut RenderPass<'_>, viewport: Viewport, geometry_renderer: &mut GeometryRenderer, bounds: &Rect, )

Render the chart to a render pass.

This uses GPU-accelerated rendering for large datasets and falls back to tessellation for small datasets.

§Arguments
  • pass - The render pass to draw into
  • viewport - The viewport for rendering
  • geometry_renderer - The geometry renderer for non-GPU elements
  • bounds - The chart bounds
Source

pub fn statistics(&self) -> GpuStreamingStatistics

Get statistics about the streaming data.

Source

pub fn get_display_data( &self, series_idx: usize, pixel_width: f32, ) -> Vec<DataPoint>

Get downsampled data for display (for external use like tooltips).

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 GpuStreamingChart

Source§

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

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

impl Deref for GpuStreamingChart

Source§

type Target = Chart

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl From<(Chart, Arc<GraphicsContext>, TextureFormat)> for GpuStreamingChart

Source§

fn from( (chart, context, target_format): (Chart, Arc<GraphicsContext>, TextureFormat), ) -> 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,