use crate::element::PointElement;
use crate::style::{ShapeStyle, SizeDesc};
pub struct PointSeries<'a, Coord, I: IntoIterator<Item = Coord>, E, Size: SizeDesc + Clone> {
style: ShapeStyle,
size: Size,
data_iter: I::IntoIter,
make_point: &'a dyn Fn(Coord, Size, ShapeStyle) -> E,
}
impl<'a, Coord, I: IntoIterator<Item = Coord>, E, Size: SizeDesc + Clone> Iterator
for PointSeries<'a, Coord, I, E, Size>
{
type Item = E;
fn next(&mut self) -> Option<Self::Item> {
self.data_iter
.next()
.map(|x| (self.make_point)(x, self.size.clone(), self.style))
}
}
impl<'a, Coord, I: IntoIterator<Item = Coord>, E, Size: SizeDesc + Clone>
PointSeries<'a, Coord, I, E, Size>
where
E: PointElement<Coord, Size>,
{
pub fn new<S: Into<ShapeStyle>>(iter: I, size: Size, style: S) -> Self {
Self {
data_iter: iter.into_iter(),
size,
style: style.into(),
make_point: &|a, b, c| E::make_point(a, b, c),
}
}
}
impl<'a, Coord, I: IntoIterator<Item = Coord>, E, Size: SizeDesc + Clone>
PointSeries<'a, Coord, I, E, Size>
{
pub fn of_element<S: Into<ShapeStyle>, F: Fn(Coord, Size, ShapeStyle) -> E>(
iter: I,
size: Size,
style: S,
cons: &'a F,
) -> Self {
Self {
data_iter: iter.into_iter(),
size,
style: style.into(),
make_point: cons,
}
}
}