1use super::*;
2
3#[non_exhaustive]
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum BarDirection {
7 Horizontal,
9 Vertical,
11}
12
13#[derive(Debug, Clone)]
15pub struct Bar {
16 pub label: String,
18 pub value: f64,
20 pub color: Option<Color>,
22 pub text_value: Option<String>,
24 pub value_style: Option<Style>,
26}
27
28impl Bar {
29 pub fn new(label: impl Into<String>, value: f64) -> Self {
31 Self {
32 label: label.into(),
33 value,
34 color: None,
35 text_value: None,
36 value_style: None,
37 }
38 }
39
40 pub fn color(mut self, color: Color) -> Self {
42 self.color = Some(color);
43 self
44 }
45
46 pub fn text_value(mut self, text: impl Into<String>) -> Self {
48 self.text_value = Some(text.into());
49 self
50 }
51
52 pub fn value_style(mut self, style: Style) -> Self {
54 self.value_style = Some(style);
55 self
56 }
57}
58
59#[derive(Debug, Clone, Copy)]
61pub struct BarChartConfig {
62 pub direction: BarDirection,
64 pub bar_width: u16,
66 pub bar_gap: u16,
68 pub group_gap: u16,
70 pub max_value: Option<f64>,
72}
73
74impl Default for BarChartConfig {
75 fn default() -> Self {
76 Self {
77 direction: BarDirection::Horizontal,
78 bar_width: 1,
79 bar_gap: 0,
80 group_gap: 2,
81 max_value: None,
82 }
83 }
84}
85
86impl BarChartConfig {
87 pub fn direction(&mut self, direction: BarDirection) -> &mut Self {
89 self.direction = direction;
90 self
91 }
92
93 pub fn bar_width(&mut self, bar_width: u16) -> &mut Self {
95 self.bar_width = bar_width.max(1);
96 self
97 }
98
99 pub fn bar_gap(&mut self, bar_gap: u16) -> &mut Self {
101 self.bar_gap = bar_gap;
102 self
103 }
104
105 pub fn group_gap(&mut self, group_gap: u16) -> &mut Self {
107 self.group_gap = group_gap;
108 self
109 }
110
111 pub fn max_value(&mut self, max_value: f64) -> &mut Self {
113 self.max_value = Some(max_value);
114 self
115 }
116}
117
118#[derive(Debug, Clone)]
120pub struct BarGroup {
121 pub label: String,
123 pub bars: Vec<Bar>,
125}
126
127impl BarGroup {
128 pub fn new(label: impl Into<String>, bars: Vec<Bar>) -> Self {
130 Self {
131 label: label.into(),
132 bars,
133 }
134 }
135}