plotters_unsable/series/
point_series.rs1use crate::element::PointElement;
2use crate::style::ShapeStyle;
3
4pub struct PointSeries<'a, Coord, I: IntoIterator<Item = Coord>, E> {
7 style: ShapeStyle<'a>,
8 size: u32,
9 data_iter: I::IntoIter,
10 make_point: &'a dyn Fn(Coord, u32, ShapeStyle<'a>) -> E,
11}
12
13impl<'a, Coord, I: IntoIterator<Item = Coord>, E> Iterator for PointSeries<'a, Coord, I, E> {
14 type Item = E;
15 fn next(&mut self) -> Option<Self::Item> {
16 self.data_iter
17 .next()
18 .map(|x| (self.make_point)(x, self.size, self.style.clone()))
19 }
20}
21
22impl<'a, Coord, I: IntoIterator<Item = Coord>, E> PointSeries<'a, Coord, I, E>
23where
24 E: PointElement<'a, Coord>,
25{
26 pub fn new<S: Into<ShapeStyle<'a>>>(iter: I, size: u32, style: S) -> Self {
30 Self {
31 data_iter: iter.into_iter(),
32 size,
33 style: style.into(),
34 make_point: &|a, b, c| E::make_point(a, b, c),
35 }
36 }
37}
38
39impl<'a, Coord, I: IntoIterator<Item = Coord>, E> PointSeries<'a, Coord, I, E> {
40 pub fn of_element<S: Into<ShapeStyle<'a>>, F: Fn(Coord, u32, ShapeStyle<'a>) -> E>(
44 iter: I,
45 size: u32,
46 style: S,
47 cons: &'a F,
48 ) -> Self {
49 Self {
50 data_iter: iter.into_iter(),
51 size,
52 style: style.into(),
53 make_point: cons,
54 }
55 }
56}