pub struct Sparkline<C, F, P>where
C: PixelColor,
F: Fn(Point, Point) -> P,
P: Primitive + StyledDrawable<PrimitiveStyle<C>, Color = C>,{
pub values: VecDeque<i32>,
pub max_samples: usize,
/* private fields */
}
Expand description
Drawable
primitive (in sense of embedded-graphics
lib) that is reponsible
for performing normalization, sample storage and drawing of the accumulated
data.
§Example
use embedded_graphics::prelude::*;
use embedded_graphics::pixelcolor::BinaryColor;
use embedded_graphics::primitives::{Line, Rectangle};
use embedded_graphics::mock_display::MockDisplay;
use embedded_graphics_sparklines::Sparkline;
let mut display: MockDisplay<BinaryColor> = MockDisplay::new();
display.set_allow_overdraw(true);
let draw_fn = |lastp, p| Line::new(lastp, p);
let mut sparkline = Sparkline::new(
Rectangle::new(Point::new(0, 0), Size::new(16, 5)), // position and size of the sparkline
12, // max samples to store in memory (and display on graph)
BinaryColor::On,
1, // stroke width
draw_fn,
);
for n in 0..11 {
sparkline.add((f32::sin(n as f32) * 5_f32) as i32);
}
sparkline.draw(&mut display).unwrap();
Fields§
§values: VecDeque<i32>
stores max_samples number of values
max_samples: usize
defines the max number of values that sparkline will present
Implementations§
Trait Implementations§
Source§impl<C, F, P> Drawable for Sparkline<C, F, P>where
C: PixelColor,
F: Fn(Point, Point) -> P,
P: Primitive + StyledDrawable<PrimitiveStyle<C>, Color = C>,
impl<C, F, P> Drawable for Sparkline<C, F, P>where
C: PixelColor,
F: Fn(Point, Point) -> P,
P: Primitive + StyledDrawable<PrimitiveStyle<C>, Color = C>,
Auto Trait Implementations§
impl<C, F, P> Freeze for Sparkline<C, F, P>
impl<C, F, P> RefUnwindSafe for Sparkline<C, F, P>where
C: RefUnwindSafe,
F: RefUnwindSafe,
impl<C, F, P> Send for Sparkline<C, F, P>
impl<C, F, P> Sync for Sparkline<C, F, P>
impl<C, F, P> Unpin for Sparkline<C, F, P>
impl<C, F, P> UnwindSafe for Sparkline<C, F, P>where
C: UnwindSafe,
F: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
OverflowingCasts the value.
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
Source§fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
Source§fn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
UnwrappedCasts the value.
Source§impl<T> WrappingAs for T
impl<T> WrappingAs for T
Source§fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
Source§fn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
WrappingCasts the value.