Skip to main content

egui_charts/
lib.rs

1//! # egui-charts
2//!
3//! High-performance financial charting engine for
4//! [egui](https://docs.rs/egui). Render interactive, TradingView-quality
5//! charts — candlesticks, OHLC bars, line, area, Renko, Kagi, Point & Figure,
6//! Market Profile (TPO) — with 95 drawing tools, 130+ technical indicators,
7//! and a full design-token theme system. Built to be embedded in
8//! [Tauri](https://tauri.app) desktop apps or any egui host.
9//!
10//! ## Quick start
11//!
12//! ```rust,no_run
13//! use egui_charts::{ChartBuilder, Chart};
14//! use egui_charts::model::{Bar, BarData, Timeframe};
15//! use egui_charts::theme::Theme;
16//!
17//! // Build a chart with the fluent API
18//! let mut trading_chart = ChartBuilder::new()
19//!     .with_symbol("BTCUSDT")
20//!     .with_timeframe(Timeframe::H1)
21//!     .with_theme(Theme::dark())
22//!     .with_drawing_tools()
23//!     .build();
24//!
25//! // In your egui update loop:
26//! // trading_chart.update();           // poll data source, progressive loading
27//! // trading_chart.show(&mut ui);      // render into an egui::Ui
28//! ```
29//!
30//! For a minimal price ticker (no grid, no crosshair, no tools):
31//!
32//! ```rust,no_run
33//! # use egui_charts::ChartBuilder;
34//! let mini = ChartBuilder::price_chart()
35//!     .with_symbol("ETHUSDT")
36//!     .with_visible_candles(30)
37//!     .build();
38//! ```
39//!
40//! ## Architecture
41//!
42//! The crate is organized into a layered set of modules:
43//!
44//! | Layer | Modules | Purpose |
45//! |---|---|---|
46//! | **Domain model** | [`model`] | `Bar`, `BarData`, `Symbol`, `Timeframe`, `ChartType`, Renko/Kagi/P&F transforms |
47//! | **Data** | [`data`] | `DataSource` trait, `DataUpdate`, historical/live data abstractions |
48//! | **Chart engine** | [`chart`] | Pan/zoom, hit-testing, coordinate mapping, series rendering, interaction |
49//! | **Drawing tools** | [`drawings`] | 95 tools (trend lines, Fibonacci, patterns, etc.), undo/redo, snapping |
50//! | **Indicators** | [`studies`] | 130+ built-in indicators, `Indicator` trait, `IndicatorRegistry` |
51//! | **Scales** | [`scales`] | Price scales (normal, log, percentage), time scales, tick generators, formatters |
52//! | **Configuration** | [`config`] | `ChartConfig`, `ChartOptions`, crosshair, tooltip, keyboard, kinetic scroll |
53//! | **Validation** | [`validation`] | OHLC integrity checks, timestamp ordering, data quality |
54//! | **Theme system** | [`theme`], [`tokens`], [`styles`], [`theming`] | Design tokens (RON), semantic colors, presets (Classic, Dark, Light, Midnight, High Contrast) |
55//! | **Widget** | [`widget`] | `Chart` egui widget, `ChartBuilder`, `TradingChart` |
56//! | **Extensions** | [`ext`] | `UiExt`, `ContextExt`, `ResponseExt`, `HasDesignTokens` |
57//! | **Icons** | [`icons`] | 280+ compile-time embedded SVG icons |
58//! | **App UI** | `ui`, `ui_kit`, `templates` | *(feature `ui`)* Toolbars, panels, dialogs, reusable form/button primitives |
59//! | **Backtest** | `backtest` | *(feature `backtest`)* Strategy backtesting on historical data |
60//! | **Scripting** | `scripting` | *(feature `scripting`)* User-defined indicators and strategies |
61//!
62//! ## Feature flags
63//!
64//! The default build includes the core engine, theme system, chart widget, and
65//! compile-time icons. Application-level UI is opt-in.
66//!
67//! | Feature | Default | Description |
68//! |---|---|---|
69//! | `icons` | **on** | 280+ compile-time embedded SVG icons. Required by `ui`. |
70//! | `ui` | off | Application-level UI: toolbars, panels, sidebars, dialogs, and the reusable `ui_kit` widget library they are built on. Enable this when you are building a full trading-terminal interface around the chart engine. |
71//! | `backtest` | off | Backtesting framework for strategy evaluation on historical data. |
72//! | `scripting` | off | Embedded scripting support for user-defined indicators and strategies. |
73//!
74//! ## Integrating with Tauri
75//!
76//! `egui-charts` is designed to be used as the rendering engine inside a Tauri
77//! desktop application. A typical setup:
78//!
79//! 1. Add the crate to your Tauri frontend's dependencies:
80//!
81//!    ```toml
82//!    [dependencies]
83//!    egui-charts = { version = "0.1", features = ["ui"] }
84//!    ```
85//!
86//! 2. Implement [`data::DataSource`] to bridge your Tauri backend (IPC /
87//!    WebSocket) to the chart's data layer.
88//!
89//! 3. Create a [`chart::builder::ChartBuilder`] in your `eframe::App::update`
90//!    and call `trading_chart.show(ui)` inside an `egui::CentralPanel`.
91//!
92//! 4. Apply a theme at startup with [`theme::apply_to_egui`] to propagate
93//!    design tokens into egui's visual system.
94//!
95//! ## Crate-level re-exports
96//!
97//! The most commonly used types are re-exported at the crate root for
98//! convenience:
99//!
100//! - [`ChartBuilder`] / [`TradingChart`] — fluent chart construction
101//! - [`Chart`] — the low-level egui widget
102//! - [`DataSource`] — data provider trait
103//! - [`ChartType`] — candlestick, line, area, bar, etc.
104
105// ─── Crate-level lint configuration ──────────────────────────────────────────
106#![allow(dead_code)]
107#![allow(unused_imports)]
108#![allow(clippy::too_many_arguments)]
109#![allow(clippy::module_inception)]
110#![allow(clippy::needless_range_loop)]
111
112// ─── Core engine modules ─────────────────────────────────────────────────────
113
114pub mod chart;
115pub mod drawings;
116pub mod model;
117pub mod scales;
118pub mod studies;
119
120// ─── Configuration & data ────────────────────────────────────────────────────
121
122pub mod config;
123pub mod data;
124pub mod validation;
125
126// ─── Theme & design system ───────────────────────────────────────────────────
127
128pub mod ext;
129#[cfg(feature = "icons")]
130pub mod icons;
131pub mod styles;
132pub mod theme;
133pub mod theming;
134pub mod tokens;
135
136// ─── Widget layer ────────────────────────────────────────────────────────────
137
138pub mod widget;
139
140// ─── Application-level UI (feature-gated) ────────────────────────────────────
141
142/// Reusable UI components (buttons, dialogs, forms, color pickers, etc.).
143///
144/// These are domain-agnostic building blocks consumed by the [`ui`] module.
145/// Enable the `ui` feature to access them.
146#[cfg(feature = "ui")]
147pub mod ui_kit;
148
149/// Application-level chart UI: drawing toolbar, top toolbar, timeframe bar,
150/// replay controls, dialogs, and widget panels.
151///
152/// Built on top of [`ui_kit`] primitives and the core chart engine. Enable the
153/// `ui` feature to access this module.
154#[cfg(feature = "ui")]
155pub mod ui;
156
157/// Chart settings template management.
158///
159/// Provides `SettingsTemplate` and
160/// `TemplateManager` for persisting and
161/// restoring chart configurations. Requires the `ui` feature because it
162/// re-exports types from [`ui::stubs`].
163#[cfg(feature = "ui")]
164pub mod templates;
165
166// ─── Optional domain modules (feature-gated) ─────────────────────────────────
167
168#[cfg(feature = "backtest")]
169pub mod backtest;
170#[cfg(feature = "scripting")]
171pub mod scripting;
172
173// ─── Convenience re-exports ──────────────────────────────────────────────────
174
175pub use chart::builder::{ChartBuilder, TradingChart};
176pub use data::DataSource;
177pub use model::ChartType;
178pub use widget::Chart;