vidi_charts/lib.rs
1//! # Vidi
2//!
3//! A high-performance data visualization library for Rust, powered by [Bevy](https://bevyengine.org/).
4//!
5//! Vidi provides a declarative API for creating interactive 2D/3D plots and dashboards
6//! that run natively or in the browser via WebAssembly.
7//!
8//! ## Features
9//!
10//! - **2D Charts**: Line plots, scatter plots, area charts, bar charts, bubble charts
11//! - **3D Visualization**: 3D scatter plots and surface plots with orbit controls
12//! - **Statistical Plots**: Histograms, PDFs, box plots, ECDF
13//! - **Financial Charts**: Candlestick/OHLC charts
14//! - **Heatmaps**: 2D heatmaps with multiple colormaps
15//! - **Radial Charts**: Pie charts and radar/spider charts
16//! - **Interactive**: Pan, zoom, and rotate controls
17//! - **Real-time Updates**: Stream data via WebSocket
18//!
19//! ## Quick Start
20//!
21//! ```rust,no_run
22//! use vidi::prelude::*;
23//! use glam::Vec2;
24//!
25//! fn main() {
26//! dash()
27//! .add_2d(|p| {
28//! let data: Vec<Vec2> = (0..100)
29//! .map(|i| {
30//! let x = i as f32 * 0.1;
31//! Vec2::new(x, x.sin())
32//! })
33//! .collect();
34//!
35//! p.line(data, None)
36//! .x_label("Time")
37//! .y_label("Amplitude")
38//! })
39//! .run_local();
40//! }
41//! ```
42//!
43//! ## Dashboard Builder
44//!
45//! Use the [`dash()`] function to start building a dashboard:
46//!
47//! ```rust,no_run
48//! use vidi::prelude::*;
49//!
50//! dash()
51//! .add_2d(|p| p.scatter(vec![], None)) // 2D plot
52//! .add_3d(|p| p.points(vec![], None)) // 3D plot
53//! .add_distribution(|d| d.histogram(vec![])) // Statistical
54//! .add_heatmap(|h| h.data(10, 10, vec![0.0; 100])) // Heatmap
55//! .run_local();
56//! ```
57//!
58//! ## Web Dashboard
59//!
60//! Post dashboards to a vidi-server for browser viewing:
61//!
62//! ```rust,ignore
63//! let handle = dash()
64//! .add_2d(|p| p.line(data, None))
65//! .run_web("http://localhost:8080", WebConfig::default())?;
66//!
67//! // Stream updates
68//! handle.append_points_2d(plot_id, 0, &new_points)?;
69//! ```
70//!
71//! ## Modules
72//!
73//! - [`core`]: Data model definitions (Plot, Graph2D, Graph3D, etc.)
74//! - [`dash`]: Builder API for constructing dashboards
75//! - [`render`]: Bevy ECS rendering implementation
76//! - [`runtime`]: Application bootstrap and run loop
77
78pub mod core;
79pub mod dash;
80pub mod render;
81pub mod runtime;
82#[cfg(target_arch = "wasm32")]
83pub mod wasm_api;
84
85use std::fmt;
86
87/// Error type for Vidi operations.
88#[derive(Debug)]
89pub struct VidiError;
90
91impl fmt::Display for VidiError {
92 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
93 write!(f, "VidiError")
94 }
95}
96
97impl std::error::Error for VidiError {}
98
99/// Result type alias using error-stack for rich error context.
100pub type Result<T> = std::result::Result<T, error_stack::Report<VidiError>>;
101
102#[cfg(target_arch = "wasm32")]
103use wasm_bindgen::prelude::*;
104
105#[cfg(target_arch = "wasm32")]
106#[wasm_bindgen(start)]
107pub fn start() {
108 console_error_panic_hook::set_once();
109}
110
111/// Prelude module - import everything you need with `use vidi::prelude::*;`
112///
113/// This includes:
114/// - All core data types (Plot, Graph2D, Graph3D, Color, Style, etc.)
115/// - Dashboard builder API (dash, DashBuilder, Plot2DBuilder, etc.)
116/// - Render components (PlotId, etc.)
117/// - Runtime functions (run_dashboard)
118/// - Web dashboard types (WebConfig, WebDashboard) on native
119pub mod prelude {
120 pub use crate::core::*;
121 pub use crate::dash::*;
122 pub use crate::render::*;
123 pub use crate::runtime::*;
124
125 // Re-export web dashboard types (native only)
126 #[cfg(not(target_arch = "wasm32"))]
127 pub use crate::dash::{WebConfig, WebDashboard};
128}