Skip to main content

flowsurface_indicator_engine/
scene.rs

1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2pub struct Color(pub u32);
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5pub enum PaneTarget {
6    Main,
7    Indicator,
8    Named(u32),
9}
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
12pub enum PlotStyle {
13    Line,
14    Step,
15    Histogram,
16    Area,
17    Candles,
18    Bars,
19    Cloud,
20    BrokenCloud,
21}
22
23#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
24pub enum PlotValueType {
25    Number,
26    Boolean,
27    Ohlc,
28    Range,
29}
30
31#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
32pub enum PlotScale {
33    Price,
34    Independent,
35}
36
37#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
38pub enum ReadoutBehavior {
39    Hidden,
40    Value,
41}
42
43#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
44pub enum PresentationViewKind {
45    Plot,
46    Table,
47    PrimaryOverlay,
48}
49
50#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
51pub enum PresentationAttachmentMode {
52    Overlay,
53    Panel,
54}
55
56#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
57pub enum PresentationDataKind {
58    Scalar,
59    Histogram,
60    Ohlc,
61    Range,
62}
63
64#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
65pub enum PresentationMarkKind {
66    Candle,
67    RegularBar,
68    Histogram,
69    HistogramSignedOverlay,
70    Line,
71    Step,
72    Area,
73    Point,
74    Cross,
75    Segment,
76    HorizontalLevel,
77}
78
79#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
80pub enum PresentationInputSource {
81    Klines,
82    DirectionalVolume,
83    Trades,
84    OpenInterest,
85}
86
87#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
88pub enum PresentationAxis {
89    Primary,
90    Secondary,
91}
92
93#[derive(Debug, Clone, Copy, PartialEq)]
94pub enum PresentationPrecision {
95    BaseTickerMinTick,
96    BaseTickerMinQty,
97    FixedStep(f64),
98}
99
100#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
101pub enum PresentationLabelMode {
102    Compact,
103    Commas,
104    Abbreviated,
105}
106
107#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
108pub enum PresentationScale {
109    Absolute,
110    FitVisible,
111    FitVisibleIncludeZero,
112    Logarithmic,
113    PercentFromBase,
114}
115
116#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
117pub enum PresentationGeometry {
118    PanelBand,
119    SeriesBand,
120}
121
122#[derive(Debug, Clone, PartialEq)]
123pub struct PresentationStyle {
124    pub id: String,
125    pub label: String,
126    pub role: String,
127    pub shade: String,
128    pub required_input: Option<PresentationInputSource>,
129}
130
131#[derive(Debug, Clone, PartialEq)]
132pub struct PresentationLayer {
133    pub channel: String,
134    pub name: String,
135    pub pane: PaneTarget,
136    pub data_kind: Option<PresentationDataKind>,
137    pub mark: Option<PresentationMarkKind>,
138    pub axis: Option<PresentationAxis>,
139}
140
141#[derive(Debug, Clone, PartialEq)]
142pub struct PresentationMark {
143    pub label: String,
144    pub kind: PresentationMarkKind,
145    pub source_channel: String,
146    pub required_input: Option<PresentationInputSource>,
147    pub fallback_mark: Option<PresentationMarkKind>,
148    /// The color used when no conditional style is active.
149    pub color_slot: String,
150    /// Optional explicit colors selected by a boolean style binding.
151    pub true_color_slot: Option<String>,
152    pub false_color_slot: Option<String>,
153    /// Optional boolean output that draws a non-destructive bar outline.
154    pub highlight_by: Option<String>,
155    /// Color slot used by the optional bar outline.
156    pub highlight_color_slot: Option<String>,
157}
158
159#[derive(Debug, Clone, PartialEq)]
160pub struct PresentationSegment {
161    pub id: String,
162    pub label: String,
163    pub color_slot: String,
164    pub line_width: f32,
165}
166
167#[derive(Debug, Clone, PartialEq)]
168pub struct PresentationFill {
169    pub upper: String,
170    pub lower: String,
171    pub upper_offset_bars: i32,
172    pub lower_offset_bars: i32,
173    pub style_by: Option<String>,
174    pub geometry: PresentationGeometry,
175    pub color_slot: String,
176    pub true_color_slot: Option<String>,
177    pub false_color_slot: Option<String>,
178    pub opacity: f32,
179}
180
181#[derive(Debug, Clone, PartialEq)]
182pub struct PresentationReadout {
183    pub label: String,
184    pub channel: String,
185    pub color_slot: String,
186    pub mark: Option<PresentationMarkKind>,
187}
188
189#[derive(Debug, Clone, PartialEq)]
190pub enum PresentationColumnColor {
191    Static {
192        slot: String,
193    },
194    Signed {
195        positive_slot: String,
196        negative_slot: String,
197    },
198}
199
200#[derive(Debug, Clone, PartialEq)]
201pub struct PresentationColumn {
202    pub label: String,
203    pub channel: String,
204    pub format: String,
205    pub color: PresentationColumnColor,
206}
207
208#[derive(Debug, Clone, PartialEq)]
209pub struct IndicatorPresentation {
210    pub view: PresentationViewKind,
211    pub attachment: Option<PresentationAttachmentMode>,
212    pub panel_title: Option<String>,
213    pub layer_name: Option<String>,
214    pub value_precision: Option<PresentationPrecision>,
215    pub axis_label_mode: Option<PresentationLabelMode>,
216    pub header_label_mode: Option<PresentationLabelMode>,
217    pub max_decimals: Option<u8>,
218    pub preferred_scale: Option<PresentationScale>,
219    pub layers: Vec<PresentationLayer>,
220    pub styles: Vec<PresentationStyle>,
221    pub region_style_slots: Vec<String>,
222    pub marks: Vec<PresentationMark>,
223    pub segments: Vec<PresentationSegment>,
224    pub fills: Vec<PresentationFill>,
225    pub readouts: Vec<PresentationReadout>,
226    pub columns: Vec<PresentationColumn>,
227}
228
229impl Default for IndicatorPresentation {
230    fn default() -> Self {
231        Self {
232            view: PresentationViewKind::Plot,
233            attachment: None,
234            panel_title: None,
235            layer_name: None,
236            value_precision: None,
237            axis_label_mode: None,
238            header_label_mode: None,
239            max_decimals: None,
240            preferred_scale: None,
241            layers: Vec::new(),
242            styles: Vec::new(),
243            region_style_slots: Vec::new(),
244            marks: Vec::new(),
245            segments: Vec::new(),
246            fills: Vec::new(),
247            readouts: Vec::new(),
248            columns: Vec::new(),
249        }
250    }
251}
252
253#[derive(Debug, Clone, PartialEq)]
254pub struct PlotDescriptor {
255    pub id: String,
256    pub label: String,
257    pub value_type: PlotValueType,
258    pub pane: PaneTarget,
259    pub scale: PlotScale,
260    pub width: f32,
261    pub output_precision: Option<OutputPrecision>,
262    pub style: PlotStyle,
263    pub readout: ReadoutBehavior,
264    pub offset_bars: i32,
265    pub color_slot: Option<String>,
266    pub style_by: Option<String>,
267    pub true_color_slot: Option<String>,
268    pub false_color_slot: Option<String>,
269    pub layer_title: Option<String>,
270    pub overlay: bool,
271    pub presentation_data_kind: Option<PresentationDataKind>,
272    pub presentation_mark: Option<PresentationMarkKind>,
273    pub presentation_axis: Option<PresentationAxis>,
274    pub layer: bool,
275}
276
277#[derive(Debug, Clone, Copy, PartialEq)]
278pub enum OutputPrecision {
279    Instrument,
280    Decimals(u8),
281    Step(f64),
282}
283
284impl OutputPrecision {
285    pub const fn is_valid(self) -> bool {
286        match self {
287            Self::Instrument | Self::Decimals(_) => true,
288            Self::Step(step) => step.is_finite() && step > 0.0,
289        }
290    }
291}