egui-charts 0.2.0

High-performance financial charting engine for egui — candlesticks, 95 drawing tools, 130+ indicators, and a full design-token theme system
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
//! Study (indicator) related enums
//!
//! Study plot types, input types, display targets, and plot styles
//! for indicator/study configuration.

use serde::{Deserialize, Serialize};
use std::fmt;

/// Study plot type — defines how a study output is rendered
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
pub enum StudyPlotType {
    /// Standard line plot
    #[default]
    Line,
    /// Histogram bars
    Histogram,
    /// Arrow markers (up/down)
    Arrow,
    /// Column (vertical bar from zero)
    Column,
    /// Area (filled below line)
    Area,
    /// Circles / dots
    Circles,
    /// Line with breaks (NaN gaps)
    LineWithBreaks,
    /// Area with breaks
    AreaWithBreaks,
    /// Step line (horizontal then vertical)
    StepLine,
    /// Step line with diamonds at corners
    StepLineDiamond,
    /// Cross markers
    Cross,
    /// OHLC bars (for multi-output studies)
    OhlcBars,
    /// Candlestick (for multi-output studies)
    OhlcCandles,
    /// Color-coded line
    ColorLine,
    /// Color-coded histogram
    ColorHistogram,
    /// Color-coded column
    ColorColumn,
    /// Color-coded area
    ColorArea,
    /// Shape markers (various shapes)
    Shapes,
}

impl StudyPlotType {
    pub fn all() -> &'static [Self] {
        &[
            Self::Line,
            Self::Histogram,
            Self::Arrow,
            Self::Column,
            Self::Area,
            Self::Circles,
            Self::LineWithBreaks,
            Self::AreaWithBreaks,
            Self::StepLine,
            Self::StepLineDiamond,
            Self::Cross,
            Self::OhlcBars,
            Self::OhlcCandles,
            Self::ColorLine,
            Self::ColorHistogram,
            Self::ColorColumn,
            Self::ColorArea,
            Self::Shapes,
        ]
    }

    pub fn name(&self) -> &'static str {
        match self {
            Self::Line => "line",
            Self::Histogram => "histogram",
            Self::Arrow => "arrow",
            Self::Column => "column",
            Self::Area => "area",
            Self::Circles => "circles",
            Self::LineWithBreaks => "line_with_breaks",
            Self::AreaWithBreaks => "area_with_breaks",
            Self::StepLine => "step_line",
            Self::StepLineDiamond => "step_line_diamond",
            Self::Cross => "cross",
            Self::OhlcBars => "ohlc_bars",
            Self::OhlcCandles => "ohlc_candles",
            Self::ColorLine => "color_line",
            Self::ColorHistogram => "color_histogram",
            Self::ColorColumn => "color_column",
            Self::ColorArea => "color_area",
            Self::Shapes => "shapes",
        }
    }

    pub fn display_name(&self) -> &'static str {
        match self {
            Self::Line => "Line",
            Self::Histogram => "Histogram",
            Self::Arrow => "Arrow",
            Self::Column => "Column",
            Self::Area => "Area",
            Self::Circles => "Circles",
            Self::LineWithBreaks => "Line with Breaks",
            Self::AreaWithBreaks => "Area with Breaks",
            Self::StepLine => "Step Line",
            Self::StepLineDiamond => "Step Line Diamond",
            Self::Cross => "Cross",
            Self::OhlcBars => "OHLC Bars",
            Self::OhlcCandles => "OHLC Candles",
            Self::ColorLine => "Color Line",
            Self::ColorHistogram => "Color Histogram",
            Self::ColorColumn => "Color Column",
            Self::ColorArea => "Color Area",
            Self::Shapes => "Shapes",
        }
    }
}

impl fmt::Display for StudyPlotType {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.display_name())
    }
}

/// Bitflags-style display target for study plots
///
/// Controls which pane(s) a study plot renders in.
/// Values can be OR'd together: `PriceScale | SeparatePane` = 3
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum StudyDisplayTarget {
    /// Do not display
    None,
    /// Display on the main price scale (value = 1)
    #[default]
    PriceScale,
    /// Display in a separate pane below the chart (value = 2)
    SeparatePane,
    /// Display on the status line only (value = 4)
    StatusLine,
    /// Display in data window only (value = 8)
    DataWindow,
    /// Display everywhere (value = 15)
    All,
}

impl StudyDisplayTarget {
    pub fn all() -> &'static [Self] {
        &[
            Self::None,
            Self::PriceScale,
            Self::SeparatePane,
            Self::StatusLine,
            Self::DataWindow,
            Self::All,
        ]
    }

    /// Numeric value for display target bitflags
    pub fn value(&self) -> u8 {
        match self {
            Self::None => 0,
            Self::PriceScale => 1,
            Self::SeparatePane => 2,
            Self::StatusLine => 4,
            Self::DataWindow => 8,
            Self::All => 15,
        }
    }

    pub fn name(&self) -> &'static str {
        match self {
            Self::None => "none",
            Self::PriceScale => "price_scale",
            Self::SeparatePane => "separate_pane",
            Self::StatusLine => "status_line",
            Self::DataWindow => "data_window",
            Self::All => "all",
        }
    }

    pub fn display_name(&self) -> &'static str {
        match self {
            Self::None => "None",
            Self::PriceScale => "Price Scale",
            Self::SeparatePane => "Separate Pane",
            Self::StatusLine => "Status Line",
            Self::DataWindow => "Data Window",
            Self::All => "All",
        }
    }
}

impl fmt::Display for StudyDisplayTarget {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.display_name())
    }
}

/// Study input parameter type
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum StudyInputType {
    /// Integer input
    #[default]
    Integer,
    /// Floating point input
    Float,
    /// Boolean toggle
    Bool,
    /// Text / string input
    Text,
    /// Color picker
    Color,
    /// Symbol search input
    Symbol,
    /// Resolution / timeframe selector
    Resolution,
    /// Session selector
    Session,
    /// Source selector (close, open, high, low, etc.)
    Source,
    /// Line style selector
    LineStyle,
    /// Line width selector
    LineWidth,
    /// Price source (another study's output)
    PriceSource,
    /// Custom input defined by the study
    Custom,
}

impl StudyInputType {
    pub fn all() -> &'static [Self] {
        &[
            Self::Integer,
            Self::Float,
            Self::Bool,
            Self::Text,
            Self::Color,
            Self::Symbol,
            Self::Resolution,
            Self::Session,
            Self::Source,
            Self::LineStyle,
            Self::LineWidth,
            Self::PriceSource,
            Self::Custom,
        ]
    }

    pub fn name(&self) -> &'static str {
        match self {
            Self::Integer => "integer",
            Self::Float => "float",
            Self::Bool => "bool",
            Self::Text => "text",
            Self::Color => "color",
            Self::Symbol => "symbol",
            Self::Resolution => "resolution",
            Self::Session => "session",
            Self::Source => "source",
            Self::LineStyle => "line_style",
            Self::LineWidth => "line_width",
            Self::PriceSource => "price_source",
            Self::Custom => "custom",
        }
    }

    pub fn display_name(&self) -> &'static str {
        match self {
            Self::Integer => "Integer",
            Self::Float => "Float",
            Self::Bool => "Boolean",
            Self::Text => "Text",
            Self::Color => "Color",
            Self::Symbol => "Symbol",
            Self::Resolution => "Resolution",
            Self::Session => "Session",
            Self::Source => "Source",
            Self::LineStyle => "Line Style",
            Self::LineWidth => "Line Width",
            Self::PriceSource => "Price Source",
            Self::Custom => "Custom",
        }
    }
}

impl fmt::Display for StudyInputType {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.display_name())
    }
}

/// Target price scale for a study
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum StudyTargetPriceScale {
    /// Left price scale
    Left,
    /// Right price scale
    #[default]
    Right,
    /// No price scale (overlay)
    NoScale,
}

impl StudyTargetPriceScale {
    pub fn all() -> &'static [Self] {
        &[Self::Left, Self::Right, Self::NoScale]
    }

    pub fn name(&self) -> &'static str {
        match self {
            Self::Left => "left",
            Self::Right => "right",
            Self::NoScale => "no_scale",
        }
    }

    pub fn display_name(&self) -> &'static str {
        match self {
            Self::Left => "Left",
            Self::Right => "Right",
            Self::NoScale => "No Scale",
        }
    }
}

impl fmt::Display for StudyTargetPriceScale {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.display_name())
    }
}

/// Line study plot style (for studies that render as line tools)
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum LineStudyPlotStyle {
    /// Solid line
    #[default]
    Line,
    /// Histogram bars
    Histogram,
    /// Cross markers
    Cross,
    /// Area fill
    Area,
    /// Column bars
    Columns,
    /// Circles / dots
    Circles,
    /// Arrow markers
    Arrows,
    /// Step line
    StepLine,
    /// Bars (OHLC)
    Bars,
    /// Candlestick
    Candles,
    /// Hollow candles
    HollowCandles,
}

impl LineStudyPlotStyle {
    pub fn all() -> &'static [Self] {
        &[
            Self::Line,
            Self::Histogram,
            Self::Cross,
            Self::Area,
            Self::Columns,
            Self::Circles,
            Self::Arrows,
            Self::StepLine,
            Self::Bars,
            Self::Candles,
            Self::HollowCandles,
        ]
    }

    pub fn name(&self) -> &'static str {
        match self {
            Self::Line => "line",
            Self::Histogram => "histogram",
            Self::Cross => "cross",
            Self::Area => "area",
            Self::Columns => "columns",
            Self::Circles => "circles",
            Self::Arrows => "arrows",
            Self::StepLine => "step_line",
            Self::Bars => "bars",
            Self::Candles => "candles",
            Self::HollowCandles => "hollow_candles",
        }
    }

    pub fn display_name(&self) -> &'static str {
        match self {
            Self::Line => "Line",
            Self::Histogram => "Histogram",
            Self::Cross => "Cross",
            Self::Area => "Area",
            Self::Columns => "Columns",
            Self::Circles => "Circles",
            Self::Arrows => "Arrows",
            Self::StepLine => "Step Line",
            Self::Bars => "Bars",
            Self::Candles => "Candles",
            Self::HollowCandles => "Hollow Candles",
        }
    }
}

impl fmt::Display for LineStudyPlotStyle {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.display_name())
    }
}

/// OHLC study plot style
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum OhlcStudyPlotStyle {
    /// Traditional OHLC bars
    #[default]
    OhlcBars,
    /// Japanese candlesticks
    Candles,
}

impl OhlcStudyPlotStyle {
    pub fn all() -> &'static [Self] {
        &[Self::OhlcBars, Self::Candles]
    }

    pub fn name(&self) -> &'static str {
        match self {
            Self::OhlcBars => "ohlc_bars",
            Self::Candles => "candles",
        }
    }

    pub fn display_name(&self) -> &'static str {
        match self {
            Self::OhlcBars => "OHLC Bars",
            Self::Candles => "Candles",
        }
    }
}

impl fmt::Display for OhlcStudyPlotStyle {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.display_name())
    }
}

/// Filled area type (for study areas between two plots)
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum FilledAreaType {
    /// Fill between two plot lines
    #[default]
    AbsolutePrice,
    /// Fill between a plot and a horizontal level
    HorizontalLine,
}

impl FilledAreaType {
    pub fn all() -> &'static [Self] {
        &[Self::AbsolutePrice, Self::HorizontalLine]
    }

    pub fn name(&self) -> &'static str {
        match self {
            Self::AbsolutePrice => "absolute_price",
            Self::HorizontalLine => "horizontal_line",
        }
    }

    pub fn display_name(&self) -> &'static str {
        match self {
            Self::AbsolutePrice => "Between Plots",
            Self::HorizontalLine => "To Level",
        }
    }
}

impl fmt::Display for FilledAreaType {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.display_name())
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_study_plot_type_count() {
        // 18 variants (not counting default duplicate)
        assert!(StudyPlotType::all().len() >= 18);
    }

    #[test]
    fn test_display_target_values() {
        assert_eq!(StudyDisplayTarget::None.value(), 0);
        assert_eq!(StudyDisplayTarget::PriceScale.value(), 1);
        assert_eq!(StudyDisplayTarget::All.value(), 15);
    }

    #[test]
    fn test_study_input_type_count() {
        assert_eq!(StudyInputType::all().len(), 13);
    }
}