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::Hour1)
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`] | 160+ 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** | 160+ 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(clippy::too_many_arguments)]
107#![allow(clippy::module_inception)]
108#![allow(clippy::needless_range_loop)]
109
110// ─── Core engine modules ─────────────────────────────────────────────────────
111
112pub mod chart;
113pub mod drawings;
114pub mod model;
115pub mod scales;
116pub mod studies;
117
118// ─── Configuration & data ────────────────────────────────────────────────────
119
120pub mod config;
121pub mod data;
122pub mod validation;
123
124// ─── Theme & design system ───────────────────────────────────────────────────
125
126pub mod ext;
127#[cfg(feature = "icons")]
128pub mod icons;
129pub mod styles;
130pub mod theme;
131pub mod theming;
132pub mod tokens;
133
134// ─── Widget layer ────────────────────────────────────────────────────────────
135
136pub mod widget;
137
138// ─── Application-level UI (feature-gated) ────────────────────────────────────
139
140/// Reusable UI components (buttons, dialogs, forms, color pickers, etc.).
141///
142/// These are domain-agnostic building blocks consumed by the [`ui`] module.
143/// Enable the `ui` feature to access them.
144#[cfg(feature = "ui")]
145pub mod ui_kit;
146
147/// Application-level chart UI: drawing toolbar, top toolbar, timeframe bar,
148/// replay controls, dialogs, and widget panels.
149///
150/// Built on top of [`ui_kit`] primitives and the core chart engine. Enable the
151/// `ui` feature to access this module.
152#[cfg(feature = "ui")]
153pub mod ui;
154
155/// Chart settings template management.
156///
157/// Provides `SettingsTemplate` and
158/// `TemplateManager` for persisting and
159/// restoring chart configurations. Requires the `ui` feature because it
160/// re-exports types from [`ui::model`].
161#[cfg(feature = "ui")]
162pub mod templates;
163
164// ─── Optional domain modules (feature-gated) ─────────────────────────────────
165
166#[cfg(feature = "backtest")]
167pub mod backtest;
168#[cfg(feature = "scripting")]
169pub mod scripting;
170
171// ─── Convenience re-exports ──────────────────────────────────────────────────
172
173pub use chart::builder::{ChartBuilder, TradingChart};
174pub use data::DataSource;
175pub use model::ChartType;
176pub use widget::{Chart, RightClickTarget};