1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use crate::color::{COLOR_HEX_BLUE_1, COLOR_HEX_BLUE_2};
use crate::Color;
pub struct BarsValues {
values: Vec<f32>,
fill_color: String,
stroke_color: String,
}
impl BarsValues {
pub fn new(values: Vec<f32>) -> Self {
Self {
values,
fill_color: COLOR_HEX_BLUE_2.to_string(),
stroke_color: COLOR_HEX_BLUE_1.to_string(),
}
}
pub fn set_fill_color(mut self, fill_color: Color) -> Self {
self.fill_color = fill_color.to_string();
self
}
pub fn set_stroke_color(mut self, stroke_color: Color) -> Self {
self.stroke_color = stroke_color.to_string();
self
}
pub fn values(&self) -> &Vec<f32> {
&self.values
}
pub fn fill_color(&self) -> &str {
&self.fill_color
}
pub fn stroke_color(&self) -> &str {
&self.stroke_color
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::color::{COLOR_HEX_GREEN_3, COLOR_HEX_GREEN_5};
#[test]
fn bars_values_basic() {
let bars_values = BarsValues::new(vec![77_f32, 12_f32, 32_f32, 24_f32, 6_f32])
.set_fill_color(Color::new_from_hex(COLOR_HEX_GREEN_5))
.set_stroke_color(Color::new_from_hex(COLOR_HEX_GREEN_3));
assert_eq!(
*bars_values.values(),
vec![77_f32, 12_f32, 32_f32, 24_f32, 6_f32]
);
assert_eq!(bars_values.fill_color(), COLOR_HEX_GREEN_5);
assert_eq!(bars_values.stroke_color(), COLOR_HEX_GREEN_3);
}
}