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
use crate::time_series::{TimeSeries, Style};
use crate::plotable::Plotable;
use plotlib::view::{View, ContinuousView};
use plotlib::repr::Plot;
pub struct Grouper {
group: Vec<TimeSeries>,
}
impl Grouper {
pub fn new(series: &TimeSeries) -> Self {
Self {
group: vec!(series.clone())
}
}
pub fn add(mut self, series: &TimeSeries) -> Self{
self.group.push(series.clone());
self
}
pub fn last_with_style(mut self, style: Style) -> Self {
*self.last_mut().style_mut() = style;
self
}
fn last_mut(&mut self) -> &mut TimeSeries {
self.group.last_mut().expect("Can't get last element in grouper")
}
}
impl Plotable for Grouper {
fn plot(&self) -> Box<dyn View> {
let mut view = ContinuousView::new();
for i in 0..self.group.len() {
view = view.add(self.group[i].as_plot());
}
Box::new(view)
}
fn as_plot(&self) -> Plot {
panic!("Sorry, mate, you can't get a plot from a grouper")
}
}
impl Default for Grouper {
fn default() -> Self {
Self {
group: Vec::default()
}
}
}