egui_charts/model/
time_scale_event.rs1use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8#[non_exhaustive]
9pub enum EventKind {
10 Earnings,
12 Dividend,
14 Split,
16 Economic,
18 News,
20 Idea,
22}
23
24impl EventKind {
25 pub fn label(self) -> &'static str {
27 match self {
28 Self::Earnings => "E",
29 Self::Dividend => "D",
30 Self::Split => "S",
31 Self::Economic => "Ec",
32 Self::News => "N",
33 Self::Idea => "I",
34 }
35 }
36}
37
38#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
40pub struct TimeScaleEvent {
41 pub id: String,
43 pub time: DateTime<Utc>,
45 pub kind: EventKind,
47 pub title: String,
49 pub details: String,
51}
52
53#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
55#[serde(default)]
56pub struct EventVisibility {
57 pub show_dividends: bool,
59 pub show_splits: bool,
61 pub show_earnings: bool,
63 pub show_earnings_breaks: bool,
65 pub show_economic_events: bool,
67 pub show_news: bool,
69 pub show_news_notifications: bool,
72 pub show_ideas: bool,
74}
75
76impl Default for EventVisibility {
77 fn default() -> Self {
78 Self {
79 show_dividends: true,
80 show_splits: true,
81 show_earnings: false,
82 show_earnings_breaks: false,
83 show_economic_events: false,
84 show_news: true,
85 show_news_notifications: false,
86 show_ideas: true,
87 }
88 }
89}
90
91impl EventVisibility {
92 pub fn shows(&self, kind: EventKind) -> bool {
94 match kind {
95 EventKind::Dividend => self.show_dividends,
96 EventKind::Split => self.show_splits,
97 EventKind::Earnings => self.show_earnings,
98 EventKind::Economic => self.show_economic_events,
99 EventKind::News => self.show_news,
100 EventKind::Idea => self.show_ideas,
101 }
102 }
103}