Skip to main content

Crate shape_viz_core

Crate shape_viz_core 

Source
Expand description

§Shape Viz Core

High-performance GPU-accelerated charting library with modular layer architecture.

§Architecture Overview

Shape Viz Core is built around a modular layer system where each visual component (range bars, grid, axes, indicators) is implemented as a separate layer that can be composed together to create complex charts.

§Core Components

  • Renderer: GPU-accelerated rendering engine using WGPU
  • Layers: Modular rendering components (range bars, grid, axes, etc.)
  • Viewport: Coordinate system and transformation management
  • Data: Efficient data structures for generic time series
  • Themes: Professional styling and color schemes

§Example Usage

use shape_viz_core::{Chart, ChartConfig, ChartData, Series};
use shape_viz_core::layers::{CandlestickLayer, GridLayer, PriceAxisLayer};
use std::any::Any;

#[derive(Debug)]
struct SimpleSeries {
    name: String,
    x: Vec<f64>,
    y: Vec<f64>,
}

impl Series for SimpleSeries {
    fn name(&self) -> &str { &self.name }
    fn len(&self) -> usize { self.x.len() }
    fn get_x(&self, index: usize) -> f64 { self.x[index] }
    fn get_y(&self, index: usize) -> f64 { self.y[index] }
    fn get_x_range(&self) -> (f64, f64) {
        (*self.x.first().unwrap(), *self.x.last().unwrap())
    }
    fn get_y_range(&self, _x_min: f64, _x_max: f64) -> (f64, f64) {
        let min = self.y.iter().cloned().fold(f64::INFINITY, f64::min);
        let max = self.y.iter().cloned().fold(f64::NEG_INFINITY, f64::max);
        (min, max)
    }
    fn find_index(&self, x: f64) -> Option<usize> {
        self.x.iter().position(|v| *v == x)
    }
    fn as_any(&self) -> &dyn Any { self }
}

let config = ChartConfig::default();
let mut chart = pollster::block_on(Chart::new(config))?;

// Add layers
chart.add_layer(Box::new(GridLayer::new()));
chart.add_layer(Box::new(CandlestickLayer::new()));
chart.add_layer(Box::new(PriceAxisLayer::new()));

// Attach data
let series = SimpleSeries {
    name: "demo".to_string(),
    x: vec![1.0, 2.0, 3.0],
    y: vec![10.0, 12.0, 11.0],
};
chart.set_data(ChartData::new(Box::new(series)))?;

// Render frame
let image_data = pollster::block_on(chart.render())?;

Re-exports§

pub use text_gpu as text;
pub use chart::Chart;
pub use chart::ChartConfig;
pub use data::ChartData;
pub use data::RangeSeries;
pub use data::Series;
pub use data::TimeRange;
pub use error::ChartError;
pub use error::Result;
pub use event::ChartEvent;
pub use event::ChartState;
pub use renderer::GpuRenderer;
pub use renderer::RenderContext;
pub use style::ChartStyle;
pub use style::LayoutStyle;
pub use theme::ChartTheme;
pub use theme::ColorScheme;
pub use viewport::ChartBounds;
pub use viewport::Rect;
pub use viewport::Viewport;
pub use layers::Layer;

Modules§

chart
Main chart API and configuration
data
Data structures for generic time series visualization
error
Error types for FChart Core
event
Core event types and simple state container for interactive charting
layers
Modular layer system for chart rendering
renderer
GPU-accelerated rendering system using WGPU
style
Chart styling parameters to tune layout and layer appearance.
text_gpu
GPU-accelerated text rendering using glyphon
theme
Theme and styling system for charts
utils
Shared utilities for chart calculations
viewport
Viewport and coordinate system management
wire
Wire format integration for Shape interoperability

Structs§

Vec2
A 2-dimensional vector.