Skip to main content

Heatmap

Struct Heatmap 

Source
pub struct Heatmap<Msg> { /* private fields */ }
Expand description

A grid of days as tones: one cell per value, a column per week, the tone carrying how much that day holds.

Values run oldest first and fill the grid column by column, so a column is a week and a row is a weekday; the newest column is on the right. starts_at leaves the first cells of the first column blank, for a year that does not begin on the first weekday: a blank cell is a day outside the range and shows nothing at all, while a day inside it that holds nothing takes the empty tone. The two never look the same.

The tone is a step, not a gradient: a value at or below zero takes the empty tone, and any value above it takes one of four steps towards the full tone, the topmost step reserved for the largest value (or for max, when the scale is fixed). With series the full tone is one of the theme’s series tones instead of the accent, so several heatmaps beside each other read as different categories — name them with a Legend.

Nothing is drawn with characters, so the grid looks the same in every glyph mode. Where the terminal cannot tell two steps apart (a 16-colour terminal), the steps that would collapse are dropped and the remaining tones are spread over the four levels: fewer steps, but never two different levels in the same tone.

A heatmap is a picture and stays passive until on_select is given. With it, the cell under the pointer and the cell the keyboard cursor is on light up, a click or Enter reports that cell’s index, and the caller writes its value as text — a single cell’s number cannot be read out of a tone, and the runtime does not tell widgets about pointer movement, so lighting a cell is what hovering can do and reading the number needs the one press that the keyboard makes with Enter.

Narrow areas keep the newest columns and drop the oldest whole columns, so the grid never shows a half week; Heatmap::columns says how many are left, for a caller that wants to write “the last 12 weeks”. An area shorter than the grid keeps the rows that fit from the top. An area with no room, or a heatmap with no values, draws nothing and measures nothing, which leaves the caller room for an empty state.

Style keys: heatmap (empty for a day that holds nothing, fill for the full tone, cursor for the tone the lit cell mixes towards) and heatmap:focus (cursor while the keyboard moved the cursor last).

Implementations§

Source§

impl<Msg: 'static> Heatmap<Msg>

Source

pub fn new(values: impl IntoIterator<Item = f32>) -> Self

A heatmap of values, oldest first, in a grid seven rows tall.

Source

pub fn rows(self, rows: u16) -> Self

Rows of the grid; seven by default, one per weekday. At least one.

Source

pub fn max(self, max: f32) -> Self

The value the topmost step stands for, e.g. a daily goal; the largest value by default.

Source

pub fn starts_at(self, row: u16) -> Self

Blank cells before the first value, for a range that does not start on the first row of a column. Kept within one column.

Source

pub fn series(self, index: usize) -> Self

Builds the tones from the theme’s index-th series tone instead of the accent, for one category among several.

Source

pub fn selected(self, index: Option<usize>) -> Self

The value the cursor rests on, which the caller keeps as it hears on_select.

Source

pub fn on_select(self, message: impl Fn(usize) -> Msg + 'static) -> Self

Message for a cell chosen with a click or with Enter, carrying its index into the values.

Source

pub fn columns(&self, width: u16) -> u16

How many columns the grid has in width cells: every week that fits, newest kept.

Trait Implementations§

Source§

impl<Msg: 'static> Widget<Msg> for Heatmap<Msg>

Source§

fn measure(&self, _cx: &mut MeasureCx<'_>, available: Size) -> Size

The size the widget wants when it may use up to available.
Source§

fn paint(&self, cx: &mut PaintCx<'_>, area: Rect)

Draws the widget into area.
Source§

fn event(&self, cx: &mut EventCx<'_, Msg>, event: &Event) -> bool

Handles input. Returns true when the event was used; unused key and scroll events bubble to the parent widget.
Source§

fn focusable(&self) -> bool

Whether the widget can take keyboard focus.
Source§

fn paint_overlay(&self, _cx: &mut PaintCx<'_>, _anchor: Rect)

Draws the widget’s overlay after the whole view was painted, when it asked for one with PaintCx::request_overlay. anchor is the area the widget was painted in.
Source§

fn children(&self) -> &[Node<Msg>]

Child nodes, for widgets that contain other widgets.
Source§

fn children_mut(&mut self) -> &mut [Node<Msg>]

Mutable child nodes, used to assign ids.

Auto Trait Implementations§

§

impl<Msg> !RefUnwindSafe for Heatmap<Msg>

§

impl<Msg> !Send for Heatmap<Msg>

§

impl<Msg> !Sync for Heatmap<Msg>

§

impl<Msg> !UnwindSafe for Heatmap<Msg>

§

impl<Msg> Freeze for Heatmap<Msg>
where Option<Box<dyn Fn(usize) -> Msg>>: Freeze,

§

impl<Msg> Unpin for Heatmap<Msg>
where Option<Box<dyn Fn(usize) -> Msg>>: Unpin,

§

impl<Msg> UnsafeUnpin for Heatmap<Msg>
where Option<Box<dyn Fn(usize) -> Msg>>: UnsafeUnpin,

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> 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> IntoEither for T

Source§

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.