Skip to main content

Sparkline

Struct Sparkline 

Source
pub struct Sparkline<'a> { /* private fields */ }
Expand description

A single-row sparkline of samples, scaled to the sample max, using the eight vertical block glyphs ▁▂▃▄▅▆▇█.

The most recent samples are right-aligned so the graph scrolls left as new data arrives. By default, bar height and color track each sample’s fraction of the max via Meter (a green-to-red load ramp); call Sparkline::style to draw every bar in one fixed color instead, height only, the right choice once the color channel would otherwise imply something the data doesn’t mean (e.g. a frame-time graph, where “tallest bar in view” isn’t the same thing as “bad”: super::PerfOverlay does this). Only the first row of area is drawn.

Unlike super::BoxBorder, super::Gauge, super::StatBar, super::Table, and super::Button, Sparkline has no theme()/ theme_on() pair: Meter already gives its bars a semantic green-to-red color, and a fixed Sparkline::style override has no single Theme role to map onto either.

§Examples

use retroglyph_core::grid::{Grid, Rect};
use retroglyph_ui::{Surface, Sparkline, Widget};

let samples = [1.0, 3.0, 2.0, 4.0, 1.5];
let mut grid = Grid::new(10, 1);
let area = Rect::new(0, 0, 10, 1);
Sparkline::new(&samples).render(&mut Surface::new(&mut grid, area, 0));

Implementations§

Source§

impl<'a> Sparkline<'a>

Source

pub const fn new(samples: &'a [f32]) -> Self

A sparkline of samples, colored by Meter (green-to-red load ramp) unless overridden with style.

Source

pub const fn style(self, style: Style) -> Self

Draws every bar in style’s foreground color instead of the default Meter ramp. Height still tracks each sample’s fraction of the max; only the color stops varying.

Trait Implementations§

Source§

impl<'a> Clone for Sparkline<'a>

Source§

fn clone(&self) -> Sparkline<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Sparkline<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Widget for Sparkline<'_>

Source§

fn render(&self, surface: &mut Surface<'_>)

Draw this widget into surface, filling surface.area(). Read more
Source§

impl<'a> Copy for Sparkline<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Sparkline<'a>

§

impl<'a> RefUnwindSafe for Sparkline<'a>

§

impl<'a> Send for Sparkline<'a>

§

impl<'a> Sync for Sparkline<'a>

§

impl<'a> Unpin for Sparkline<'a>

§

impl<'a> UnsafeUnpin for Sparkline<'a>

§

impl<'a> UnwindSafe for Sparkline<'a>

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> 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

impl<C> WithAlpha for C
where C: Copy,

§

fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>

Wraps self with alpha, storing alpha before the color in memory (see [AlphaFirst]).
§

fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>

Wraps self with alpha, storing alpha after the color in memory (see [AlphaLast]).