1use crate::theme::{Rgb, Theme};
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
10#[non_exhaustive]
11pub enum TypeScale {
12 #[default]
14 Compact,
15 Large,
17 XLarge,
19}
20
21impl TypeScale {
22 #[must_use]
24 pub const fn compact() -> Self {
25 Self::Compact
26 }
27
28 #[must_use]
30 pub const fn large() -> Self {
31 Self::Large
32 }
33
34 #[must_use]
36 pub const fn xlarge() -> Self {
37 Self::XLarge
38 }
39
40 #[must_use]
42 pub const fn pixel(self) -> u32 {
43 match self {
44 Self::Compact => 1,
45 Self::Large => 2,
46 Self::XLarge => 3,
47 }
48 }
49
50 #[must_use]
52 pub const fn advance(self) -> u32 {
53 6 * self.pixel()
54 }
55
56 #[must_use]
58 pub const fn row_height(self) -> u32 {
59 match self {
60 Self::Compact => 18,
61 Self::Large => 28,
62 Self::XLarge => 40,
63 }
64 }
65
66 #[must_use]
68 pub const fn header_height(self) -> u32 {
69 match self {
70 Self::Compact => 20,
71 Self::Large => 32,
72 Self::XLarge => 44,
73 }
74 }
75
76 #[must_use]
78 pub const fn pad(self) -> u32 {
79 match self {
80 Self::Compact => 8,
81 Self::Large => 12,
82 Self::XLarge => 16,
83 }
84 }
85
86 #[must_use]
88 pub const fn cell_pad_x(self) -> u32 {
89 match self {
90 Self::Compact => 8,
91 Self::Large => 12,
92 Self::XLarge => 16,
93 }
94 }
95
96 #[must_use]
98 pub const fn min_col(self) -> u32 {
99 match self {
100 Self::Compact => 56,
101 Self::Large => 88,
102 Self::XLarge => 120,
103 }
104 }
105
106 #[must_use]
108 pub const fn max_col(self) -> u32 {
109 match self {
110 Self::Compact => 240,
111 Self::Large => 360,
112 Self::XLarge => 480,
113 }
114 }
115
116 #[must_use]
118 pub const fn plot_left(self) -> u32 {
119 self.advance().saturating_mul(7).saturating_add(self.pad())
120 }
121
122 #[must_use]
124 pub const fn plot_bottom(self) -> u32 {
125 self.row_height().saturating_add(4)
126 }
127}
128
129#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
131#[non_exhaustive]
132pub enum MarkerStyle {
133 None,
135 Last,
137 #[default]
139 Hover,
140}
141
142#[derive(Debug, Clone, Copy, PartialEq, Eq)]
144#[non_exhaustive]
145pub struct ChartStyle {
146 pub stroke_px: u8,
148 pub area_fill: bool,
150 pub area_alpha: u8,
152 pub tick_count: u8,
154 pub nice_ticks: bool,
156 pub series: [Rgb; 4],
158 pub plot_background: Rgb,
160 pub markers: MarkerStyle,
162}
163
164impl Default for ChartStyle {
165 fn default() -> Self {
166 Self::from_theme(&Theme::default())
167 }
168}
169
170impl ChartStyle {
171 #[must_use]
173 pub fn from_theme(theme: &Theme) -> Self {
174 Self {
175 stroke_px: 2,
176 area_fill: true,
177 area_alpha: 48,
178 tick_count: 5,
179 nice_ticks: true,
180 series: [
181 theme.series,
182 Rgb::new(0x3e, 0xc8, 0xbf),
183 theme.crosshair,
184 Rgb::new(0xc0, 0x84, 0xfc),
185 ],
186 plot_background: Rgb::new(
187 theme.background.r.saturating_add(14),
188 theme.background.g.saturating_add(16),
189 theme.background.b.saturating_add(22),
190 ),
191 markers: MarkerStyle::Hover,
192 }
193 }
194}
195
196#[derive(Debug, Clone, Copy, PartialEq, Eq)]
198#[non_exhaustive]
199pub struct Appearance {
200 pub theme: Theme,
202 pub type_scale: TypeScale,
204 pub chart: ChartStyle,
206}
207
208impl Default for Appearance {
209 fn default() -> Self {
210 let theme = Theme::default();
211 Self {
212 chart: ChartStyle::from_theme(&theme),
213 theme,
214 type_scale: TypeScale::Compact,
215 }
216 }
217}
218
219impl Appearance {
220 #[must_use]
222 pub fn compact() -> Self {
223 Self::default()
224 }
225
226 #[must_use]
228 pub fn light() -> Self {
229 let theme = Theme::light();
230 Self {
231 chart: ChartStyle::from_theme(&theme),
232 theme,
233 type_scale: TypeScale::Compact,
234 }
235 }
236
237 #[must_use]
239 pub fn high_contrast() -> Self {
240 let theme = Theme::high_contrast();
241 Self {
242 chart: ChartStyle::from_theme(&theme),
243 theme,
244 type_scale: TypeScale::Compact,
245 }
246 }
247
248 #[must_use]
250 pub fn large() -> Self {
251 Self {
252 type_scale: TypeScale::Large,
253 ..Self::default()
254 }
255 }
256
257 #[must_use]
259 pub fn xlarge() -> Self {
260 Self {
261 type_scale: TypeScale::XLarge,
262 ..Self::default()
263 }
264 }
265}