pub struct KpiCard { /* private fields */ }Expand description
One key number: a label, the value, its change with a direction, an
optional sparkline and an optional Status.
╭───────────────────────╮
│ Requests ✓ ok │
│ 12.4k/s │
│ ▲ +8.49% vs last week │
│ ▁▂▂▄▆▅▃▆█▇▅▃ │
╰───────────────────────╯- The delta is an arrow and a signed number:
▲ +8.5%,▼ -120,= 0(^,vand=in ASCII). It is styledchart.delta.goodorchart.delta.badby whether the change is for the better (higher_is_better, on by default), and the arrow and sign carry the direction without colour. - The status is a symbol and a word (
✓ ok,! warning,✗ critical), right-aligned on the label’s line. - The card measures to its content, so cards sit side by side in a
Columnsor aTablegrid;widthfixes the width andexpandfills what it is given, so a row of cards lines up. Every card with the same parts has the same height. - Given less width the label is cut, then the other lines; the sparkline resamples. Below 5 cells the border goes.
use rich::Console;
use rich_ext::chart::{Charset, KpiCard, Status};
let console = Console::builder().width(40).color_system(None).build();
let card = KpiCard::new("Errors", 42.0)
.previous(56.0)
.higher_is_better(false)
.caption("vs yesterday")
.status(Status::Warning);
assert_eq!(
console.render_export(&card),
concat!(
"╭─────────────────────╮\n",
"│ Errors ! warning │\n",
"│ 42 │\n",
"│ ▼ -25% vs yesterday │\n",
"╰─────────────────────╯\n",
)
);Implementations§
Source§impl KpiCard
impl KpiCard
Sourcepub fn format(self, format: ValueFormat) -> Self
pub fn format(self, format: ValueFormat) -> Self
How the value and an absolute delta are written (default
ValueFormat::Compact).
Sourcepub fn unit(self, unit: impl Into<String>) -> Self
pub fn unit(self, unit: impl Into<String>) -> Self
Written right after the value, such as %, /s or ms.
Sourcepub fn delta_percent(self, percent: f64) -> Self
pub fn delta_percent(self, percent: f64) -> Self
The change as a percentage.
Sourcepub fn previous(self, previous: f64) -> Self
pub fn previous(self, previous: f64) -> Self
The change from previous to the value, as a percentage (as an
amount when previous is 0).
Sourcepub fn caption(self, caption: impl Into<String>) -> Self
pub fn caption(self, caption: impl Into<String>) -> Self
Words after the delta, such as vs last week.
Sourcepub fn higher_is_better(self, higher: bool) -> Self
pub fn higher_is_better(self, higher: bool) -> Self
Whether a rise is good news (default on); off for errors, latency and costs.
Sourcepub fn trend(self, values: impl IntoIterator<Item = f64>) -> Self
pub fn trend(self, values: impl IntoIterator<Item = f64>) -> Self
A sparkline of values under the delta.
Sourcepub fn expand(self, expand: bool) -> Self
pub fn expand(self, expand: bool) -> Self
Fill the width given (default off: the content’s width).
Sourcepub fn charset(self, charset: Charset) -> Self
pub fn charset(self, charset: Charset) -> Self
Glyphs to draw with: Charset::Ascii asks for ASCII; anything else
draws box drawing and arrows (ASCII on an ASCII-only console). A
sparkline keeps its own charset unless this asks for ASCII.
Trait Implementations§
Source§impl AccessibleText for KpiCard
KPI Errors: 42, down 25% vs yesterday, better, status warning: the
value, its change in words and whether that is for the better, and the
status; then the sparkline’s text, if it has one.
impl AccessibleText for KpiCard
KPI Errors: 42, down 25% vs yesterday, better, status warning: the
value, its change in words and whether that is for the better, and the
status; then the sparkline’s text, if it has one.
Source§fn accessible_text(&self, width: usize) -> String
fn accessible_text(&self, width: usize) -> String
width where layout matters.Source§impl Renderable for KpiCard
impl Renderable for KpiCard
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
(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
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>
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
"\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.