trading_charts_core/data/
legend.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Serialize, Deserialize, Clone, PartialEq)]
4#[serde(rename_all = "camelCase")]
5pub struct LegendOptions {
6 visible: bool,
7 show_ohlc: bool,
8 show_percent: bool,
9 show_series: bool,
10 show_volume: bool,
11 toggle_series_visibility: bool,
12 text: String,
13 text_color: String,
14 background_color: String,
15 font_size: f64,
16 font_family: String,
17 top: f64,
18 left: f64,
19}
20
21impl LegendOptions {
22 pub fn new() -> Self {
23 Self::default()
24 }
25
26 pub fn with_visible(self, visible: bool) -> Self {
27 Self {
28 visible,
29 ..self
30 }
31 }
32
33 pub fn with_show_ohlc(self, show_ohlc: bool) -> Self {
34 Self {
35 show_ohlc,
36 ..self
37 }
38 }
39
40 pub fn with_show_percent(self, show_percent: bool) -> Self {
41 Self {
42 show_percent,
43 ..self
44 }
45 }
46
47 pub fn with_show_series(self, show_series: bool) -> Self {
48 Self {
49 show_series,
50 ..self
51 }
52 }
53
54 pub fn with_show_volume(self, show_volume: bool) -> Self {
55 Self {
56 show_volume,
57 ..self
58 }
59 }
60
61 pub fn with_toggle_series_visibility(self, toggle_series_visibility: bool) -> Self {
62 Self {
63 toggle_series_visibility,
64 ..self
65 }
66 }
67
68 pub fn with_text(self, text: impl Into<String>) -> Self {
69 Self {
70 text: text.into(),
71 ..self
72 }
73 }
74
75 pub fn with_text_color(self, text_color: impl Into<String>) -> Self {
76 Self {
77 text_color: text_color.into(),
78 ..self
79 }
80 }
81
82 pub fn with_background_color(self, background_color: impl Into<String>) -> Self {
83 Self {
84 background_color: background_color.into(),
85 ..self
86 }
87 }
88
89 pub fn with_font_size(self, font_size: f64) -> Self {
90 Self {
91 font_size,
92 ..self
93 }
94 }
95
96 pub fn with_font_family(self, font_family: impl Into<String>) -> Self {
97 Self {
98 font_family: font_family.into(),
99 ..self
100 }
101 }
102
103 pub fn with_top(self, top: f64) -> Self {
104 Self {
105 top,
106 ..self
107 }
108 }
109
110 pub fn with_left(self, left: f64) -> Self {
111 Self {
112 left,
113 ..self
114 }
115 }
116}
117
118impl Default for LegendOptions {
119 fn default() -> Self {
120 Self {
121 visible: true,
122 show_ohlc: true,
123 show_percent: true,
124 show_series: true,
125 show_volume: true,
126 toggle_series_visibility: true,
127 text: String::new(),
128 text_color: String::from("#0f172a"),
129 background_color: String::from("rgba(0, 0, 0, 0)"),
130 font_size: 12.0,
131 font_family: String::from(
132 "Avenir Next, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif",
133 ),
134 top: 10.0,
135 left: 10.0,
136 }
137 }
138}