Sparkline

Struct Sparkline 

Source
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§

Source§

impl<C, F, P> Sparkline<C, F, P>
where C: PixelColor, F: Fn(Point, Point) -> P, P: Primitive + StyledDrawable<PrimitiveStyle<C>, Color = C>,

Source

pub fn new( bbox: Rectangle, max_samples: usize, color: C, stroke_width: u32, draw_fn: F, ) -> Self

Source

pub fn add(&mut self, val: i32)

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>,

Source§

type Color = C

The pixel color type.
Source§

type Output = ()

The return type of the draw method. Read more
Source§

fn draw<D>(&self, target: &mut D) -> Result<Self::Output, D::Error>
where D: DrawTarget<Color = Self::Color>,

Draw the graphics object using the supplied DrawTarget.

Auto Trait Implementations§

§

impl<C, F, P> Freeze for Sparkline<C, F, P>
where C: Freeze, F: Freeze,

§

impl<C, F, P> RefUnwindSafe for Sparkline<C, F, P>

§

impl<C, F, P> Send for Sparkline<C, F, P>
where C: Send, F: Send,

§

impl<C, F, P> Sync for Sparkline<C, F, P>
where C: Sync, F: Sync,

§

impl<C, F, P> Unpin for Sparkline<C, F, P>
where C: Unpin, F: Unpin,

§

impl<C, F, P> UnwindSafe for Sparkline<C, F, P>
where C: UnwindSafe, F: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

OverflowingCasts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

UnwrappedCasts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

WrappingCasts the value.