egui_charts/ui/model.rs
1//! Domain model shared by the application UI components.
2//!
3//! Connection, layout, replay, and template types consumed across the
4//! toolbars, panels, and dialogs of the `ui` feature.
5
6// =============================================================================
7// Connection
8// =============================================================================
9
10/// Connection state for WebSocket or data provider
11#[derive(Debug, Clone, PartialEq)]
12pub enum ConnectionState {
13 /// The host reports an established connection.
14 Connected,
15 /// A connection attempt is in progress.
16 Connecting,
17 /// The host is retrying the connection.
18 Reconnecting {
19 /// Reconnect attempt number supplied by the host.
20 attempt: u32,
21 },
22 /// The connection is closed.
23 Disconnected,
24 /// Connection failure with a host-supplied message.
25 Failed(String),
26}
27
28// =============================================================================
29// Chart Layout
30// =============================================================================
31
32pub use crate::widget::ChartLayoutMode;
33
34// =============================================================================
35// Layout Style
36// =============================================================================
37
38/// UI layout style variant
39#[derive(Debug, Clone, Copy, PartialEq, Eq)]
40pub enum LayoutStyle {
41 /// Modern layout styling.
42 Modern,
43 /// Classic layout styling.
44 Classic,
45}
46
47// =============================================================================
48// Replay
49// =============================================================================
50
51pub use super::replay::model::{PlaybackSpeed, ReplayCommand, ReplayProgress, ToolbarReplayState};
52
53// =============================================================================
54// Templates
55// =============================================================================
56
57/// An indicator parameter template
58#[derive(Debug, Clone)]
59pub struct IndicatorTemplate {
60 /// Host identifier for this record.
61 pub id: String,
62 /// Display name.
63 pub name: String,
64 /// Study identifier used by the host for this template.
65 pub indicator_type: String,
66 /// Named numeric parameter values supplied by the host.
67 pub parameters: Vec<(String, f64)>,
68 /// Host-reported sharing state; the host manages permissions.
69 pub is_shared: bool,
70}
71
72impl IndicatorTemplate {
73 /// Summary of parameter values
74 pub fn parameter_summary(&self) -> String {
75 if self.parameters.is_empty() {
76 "Default".to_string()
77 } else {
78 self.parameters
79 .iter()
80 .map(|(k, v)| format!("{k}={v}"))
81 .collect::<Vec<_>>()
82 .join(", ")
83 }
84 }
85}