plotters_unsable/series/
line_series.rs

1use crate::element::Path;
2use crate::style::ShapeStyle;
3
4/// The line series object, which takes an iterator of points in guest coordinate system
5/// and creates the element rendering the line plot
6pub struct LineSeries<'a, Coord, I: IntoIterator<Item = Coord>> {
7    style: ShapeStyle<'a>,
8    data_iter: Option<I::IntoIter>,
9}
10
11impl<'b, Coord, I: IntoIterator<Item = Coord>> Iterator for LineSeries<'b, Coord, I> {
12    type Item = Path<'b, Coord>;
13    fn next(&mut self) -> Option<Self::Item> {
14        if self.data_iter.is_some() {
15            let mut data_iter = None;
16            std::mem::swap(&mut self.data_iter, &mut data_iter);
17            Some(Path::new(
18                data_iter.unwrap().collect::<Vec<_>>(),
19                self.style.clone(),
20            ))
21        } else {
22            None
23        }
24    }
25}
26
27impl<'a, Coord, I: IntoIterator<Item = Coord>> LineSeries<'a, Coord, I> {
28    pub fn new<S: Into<ShapeStyle<'a>>>(iter: I, style: S) -> Self {
29        Self {
30            style: style.into(),
31            data_iter: Some(iter.into_iter()),
32        }
33    }
34}