egui_charts/model/study.rs
1//! Serializable calculation inputs shared by studies and saved alerts.
2
3use super::{PriceSource, Timeframe};
4use egui::Color32;
5
6/// A price series or an output of another study on the chart.
7#[derive(Clone, Copy, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
8pub enum StudySource {
9 /// A field or average of fields of the input bars.
10 Price(PriceSource),
11 /// A stable chart study id and its zero-based output column, without plot displacement.
12 Study {
13 /// Source series identifier assigned by the chart.
14 id: usize,
15 /// Zero-based plot index within the source study.
16 plot: usize,
17 },
18}
19
20/// A study input's current value.
21#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
22#[non_exhaustive]
23pub enum InputValue {
24 /// A bar count or nonnegative integer parameter.
25 Length(usize),
26 /// A signed integer parameter.
27 Integer(i32),
28 /// A finite numeric parameter.
29 Number(f64),
30 /// Index in the input's choices.
31 Choice(usize),
32 /// An enabled or disabled input.
33 Toggle(bool),
34 /// A price field or another study's output.
35 Source(StudySource),
36 /// An RGBA colour.
37 Color(Color32),
38 /// A calculation interval; `None` follows the chart.
39 Timeframe(Option<Timeframe>),
40 /// A host-resolved symbol; an empty string follows the chart.
41 Symbol(String),
42 /// Text the study parses itself, such as a date and time.
43 Text(String),
44}