pub struct Heatmap { /* private fields */ }Expand description
A grid of values, one row per label and one column per header, each cell a shade from lowest to highest.
- Values are scaled from the smallest to the largest (or
range) into equal steps: five in blocks (░▒▓█), ten in ASCII (.:-=+*#%@). The shade is the value, so the grid reads in black and white; with colour each step also takes achart.heat.Nstyle, cold to hot. - A NaN or infinite value is drawn
·(?in ASCII), so a missing value never passes for a low one. - The legend under the grid shows the steps between the lowest and highest value of the scale.
- Each cell is
cell_widthcells wide (2 by default). Column headers are written at their column’s first cell when they fit, leaving a space after the one before, so with narrow cells every second or third header shows. - Given less width, the cells narrow to one cell, then the row labels are cut, then neighbouring columns are merged (each shows the mean of its finite values) so every value still counts.
use rich::Console;
use rich_ext::chart::{Charset, Heatmap};
let console = Console::builder().width(40).color_system(None).build();
let map = Heatmap::new()
.columns(["mon", "tue", "wed", "thu"])
.row("api", [1.0, 4.0, 9.0, 2.0])
.row("web", [0.0, 6.0, 8.0, f64::NAN])
.cell_width(4)
.charset(Charset::Ascii);
assert_eq!(
console.render_export(&map),
concat!(
" mon tue wed thu \n",
"api ....====@@@@:::: \n",
"web ****%%%%???? \n",
"0 [ .:-=+*#%@] 9 ? no data\n",
)
);Implementations§
Source§impl Heatmap
impl Heatmap
Sourcepub fn columns<S: Into<String>>(
self,
headers: impl IntoIterator<Item = S>,
) -> Self
pub fn columns<S: Into<String>>( self, headers: impl IntoIterator<Item = S>, ) -> Self
The column headers.
Sourcepub fn row(
self,
label: impl Into<String>,
values: impl IntoIterator<Item = f64>,
) -> Self
pub fn row( self, label: impl Into<String>, values: impl IntoIterator<Item = f64>, ) -> Self
Add a row of values, in column order.
Sourcepub fn range(self, min: f64, max: f64) -> Self
pub fn range(self, min: f64, max: f64) -> Self
Fix the scale; values outside it take the end shades.
Sourcepub fn charset(self, charset: Charset) -> Self
pub fn charset(self, charset: Charset) -> Self
Glyphs to draw with: Charset::Ascii asks for the ASCII shades;
anything else draws blocks (ASCII on an ASCII-only console).
Sourcepub fn cell_width(self, width: usize) -> Self
pub fn cell_width(self, width: usize) -> Self
Cells per value (default 2, at least 1).
Sourcepub fn format(self, format: ValueFormat) -> Self
pub fn format(self, format: ValueFormat) -> Self
How the legend writes the bounds (default ValueFormat::Compact).
Trait Implementations§
Source§impl AccessibleText for Heatmap
Heatmap, 2 rows by 4 columns, values from 0 to 9, 1 missing, then
where the highest and lowest values are (Highest 9 at api, wed; lowest 0 at web, mon).
impl AccessibleText for Heatmap
Heatmap, 2 rows by 4 columns, values from 0 to 9, 1 missing, then
where the highest and lowest values are (Highest 9 at api, wed; lowest 0 at web, mon).
Source§fn accessible_text(&self, _width: usize) -> String
fn accessible_text(&self, _width: usize) -> String
The content as plain lines, laid out for
width where layout matters.Source§impl Renderable for Heatmap
impl Renderable for Heatmap
fn rich_render( &self, console: &Console, options: &ConsoleOptions, ) -> Vec<Segment>
Source§fn measure(&self, console: &Console, options: &ConsoleOptions) -> Measurement
fn measure(&self, console: &Console, options: &ConsoleOptions) -> Measurement
The
(minimum, maximum) cell width this renderable wants. Port of
__rich_measure__. The default is what upstream’s Measurement.get
returns for a renderable without one: anything from nothing to the
whole width, (0, max_width).Source§fn fit_to_measurement(&self) -> bool
fn fit_to_measurement(&self) -> bool
Whether a top-level
Console::print shrinks this renderable to its
measured width. Upstream renders every top-level renderable at the full
console width, so the default is false; an extension may opt in.Source§fn vertical(&self) -> Option<VerticalAlign>
fn vertical(&self) -> Option<VerticalAlign>
The vertical alignment a
Table cell holding this renderable uses in
place of its column’s. Upstream reads getattr(renderable, "vertical", None); Align sets it.Source§fn print_end_line(&self, _options: &ConsoleOptions) -> bool
fn print_end_line(&self, _options: &ConsoleOptions) -> bool
Whether a top-level print ends this renderable’s last line. This
port’s renderables separate lines, where upstream’s end each line
with
"\n", so a print adds the final line break. A renderable
whose upstream output stops without one (Screen, LiveRender, a
Rule whose end has no newline) returns false, and the next
output continues its last line. options are the print’s options.impl StructuralPartialEq for Heatmap
Auto Trait Implementations§
impl Freeze for Heatmap
impl RefUnwindSafe for Heatmap
impl Send for Heatmap
impl Sync for Heatmap
impl Unpin for Heatmap
impl UnsafeUnpin for Heatmap
impl UnwindSafe for Heatmap
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