1#[non_exhaustive]
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4pub enum BarDirection {
5 Horizontal,
7 Vertical,
9}
10
11#[derive(Debug, Clone)]
13pub struct Bar {
14 pub label: String,
16 pub value: f64,
18 pub color: Option<Color>,
20 pub text_value: Option<String>,
22 pub value_style: Option<Style>,
24}
25
26impl Bar {
27 pub fn new(label: impl Into<String>, value: f64) -> Self {
29 Self {
30 label: label.into(),
31 value,
32 color: None,
33 text_value: None,
34 value_style: None,
35 }
36 }
37
38 pub fn color(mut self, color: Color) -> Self {
40 self.color = Some(color);
41 self
42 }
43
44 pub fn text_value(mut self, text: impl Into<String>) -> Self {
46 self.text_value = Some(text.into());
47 self
48 }
49
50 pub fn value_style(mut self, style: Style) -> Self {
52 self.value_style = Some(style);
53 self
54 }
55}
56
57#[derive(Debug, Clone, Copy)]
59pub struct BarChartConfig {
60 pub direction: BarDirection,
62 pub bar_width: u16,
64 pub bar_gap: u16,
66 pub group_gap: u16,
68 pub max_value: Option<f64>,
70}
71
72impl Default for BarChartConfig {
73 fn default() -> Self {
74 Self {
75 direction: BarDirection::Horizontal,
76 bar_width: 1,
77 bar_gap: 0,
78 group_gap: 2,
79 max_value: None,
80 }
81 }
82}
83
84impl BarChartConfig {
85 pub fn direction(&mut self, direction: BarDirection) -> &mut Self {
87 self.direction = direction;
88 self
89 }
90
91 pub fn bar_width(&mut self, bar_width: u16) -> &mut Self {
93 self.bar_width = bar_width.max(1);
94 self
95 }
96
97 pub fn bar_gap(&mut self, bar_gap: u16) -> &mut Self {
99 self.bar_gap = bar_gap;
100 self
101 }
102
103 pub fn group_gap(&mut self, group_gap: u16) -> &mut Self {
105 self.group_gap = group_gap;
106 self
107 }
108
109 pub fn max_value(&mut self, max_value: f64) -> &mut Self {
111 self.max_value = Some(max_value);
112 self
113 }
114}
115
116#[derive(Debug, Clone)]
118pub struct BarGroup {
119 pub label: String,
121 pub bars: Vec<Bar>,
123}
124
125impl BarGroup {
126 pub fn new(label: impl Into<String>, bars: Vec<Bar>) -> Self {
128 Self {
129 label: label.into(),
130 bars,
131 }
132 }
133}