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>
impl<Msg: 'static> Heatmap<Msg>
Sourcepub fn new(values: impl IntoIterator<Item = f32>) -> Self
pub fn new(values: impl IntoIterator<Item = f32>) -> Self
A heatmap of values, oldest first, in a grid seven rows tall.
Sourcepub fn rows(self, rows: u16) -> Self
pub fn rows(self, rows: u16) -> Self
Rows of the grid; seven by default, one per weekday. At least one.
Sourcepub fn max(self, max: f32) -> Self
pub fn max(self, max: f32) -> Self
The value the topmost step stands for, e.g. a daily goal; the largest value by default.
Sourcepub fn starts_at(self, row: u16) -> Self
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.
Sourcepub fn series(self, index: usize) -> Self
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.
Sourcepub fn selected(self, index: Option<usize>) -> Self
pub fn selected(self, index: Option<usize>) -> Self
The value the cursor rests on, which the caller keeps as it hears on_select.
Trait Implementations§
Source§impl<Msg: 'static> Widget<Msg> for Heatmap<Msg>
impl<Msg: 'static> Widget<Msg> for Heatmap<Msg>
Source§fn measure(&self, _cx: &mut MeasureCx<'_>, available: Size) -> Size
fn measure(&self, _cx: &mut MeasureCx<'_>, available: Size) -> Size
available.Source§fn event(&self, cx: &mut EventCx<'_, Msg>, event: &Event) -> bool
fn event(&self, cx: &mut EventCx<'_, Msg>, event: &Event) -> bool
true when the event was used; unused key and scroll events
bubble to the parent widget.Source§fn paint_overlay(&self, _cx: &mut PaintCx<'_>, _anchor: Rect)
fn paint_overlay(&self, _cx: &mut PaintCx<'_>, _anchor: Rect)
PaintCx::request_overlay. anchor is the area the widget was painted in.Source§fn children_mut(&mut self) -> &mut [Node<Msg>]
fn children_mut(&mut self) -> &mut [Node<Msg>]
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>
impl<Msg> Unpin for Heatmap<Msg>
impl<Msg> UnsafeUnpin for Heatmap<Msg>
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
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> ⓘ
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> ⓘ
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