pub struct Sparkline;Expand description
A compact inline data trend display component.
Sparkline renders a series of data points as small bars using ratatui’s
Sparkline widget. This is a display-only component that does not
receive keyboard focus.
§Visual Format
The sparkline renders data as a compact bar chart:
▁▃▅▇█▅▃▁▂▄▆█▇▅▃With an optional title:
┌CPU Usage──────┐
│▁▃▅▇█▅▃▁▂▄▆█▇▅│
└───────────────┘§Messages
Push(f64)- Append a data pointPushBounded(f64, usize)- Append with max capacitySetData(Vec<f64>)- Replace all dataClear- Clear all dataSetMaxDisplayPoints(Option<usize>)- Set display limit
§Example
use envision::component::{Sparkline, SparklineMessage, SparklineState, Component};
let mut state = SparklineState::with_data(vec![1.0, 3.0, 7.0, 2.0, 5.0, 8.0, 4.0]);
// Append new data
Sparkline::update(&mut state, SparklineMessage::Push(6.0));
assert_eq!(state.len(), 8);
// Replace data
Sparkline::update(&mut state, SparklineMessage::SetData(vec![10.0, 20.0, 30.0]));
assert_eq!(state.len(), 3);Trait Implementations§
Source§impl Component for Sparkline
impl Component for Sparkline
Source§type State = SparklineState
type State = SparklineState
The component’s internal state type. Read more
Source§type Message = SparklineMessage
type Message = SparklineMessage
Messages this component can receive. Read more
Source§fn update(state: &mut Self::State, msg: Self::Message) -> Option<Self::Output>
fn update(state: &mut Self::State, msg: Self::Message) -> Option<Self::Output>
Update component state based on a message. Read more
Source§fn view(state: &Self::State, ctx: &mut RenderContext<'_, '_>)
fn view(state: &Self::State, ctx: &mut RenderContext<'_, '_>)
Render the component to the given area. Read more
Source§fn traced_view(state: &Self::State, ctx: &mut RenderContext<'_, '_>)
fn traced_view(state: &Self::State, ctx: &mut RenderContext<'_, '_>)
Renders the component with optional tracing instrumentation. Read more
Source§fn handle_event(
state: &Self::State,
event: &Event,
ctx: &EventContext,
) -> Option<Self::Message>
fn handle_event( state: &Self::State, event: &Event, ctx: &EventContext, ) -> Option<Self::Message>
Maps an input event to a component message. Read more
Source§fn dispatch_event(
state: &mut Self::State,
event: &Event,
ctx: &EventContext,
) -> Option<Self::Output>
fn dispatch_event( state: &mut Self::State, event: &Event, ctx: &EventContext, ) -> Option<Self::Output>
Dispatches an event by mapping it to a message and updating state. Read more
Auto Trait Implementations§
impl Freeze for Sparkline
impl RefUnwindSafe for Sparkline
impl Send for Sparkline
impl Sync for Sparkline
impl Unpin for Sparkline
impl UnsafeUnpin for Sparkline
impl UnwindSafe for Sparkline
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more