Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

KPI / indicator card

A dashboard summary tile: one big number, a one-line label, a colour-coded delta, optional sparkline.

The demo reports Apollo 11 lunar surface samples returned — 47.5 lb (21.6 kg), 2.5 lb under the mission's 50 lb pre-flight goal. The sparkline traces all six Apollo landings: 11 / 12 / 14 / 15 / 16 / 17. The visible "hockey stick" from sample 4 onwards is the Lunar Roving Vehicle arriving with Apollo 15 in 1971 — once astronauts could traverse kilometres instead of a hundred metres, sample mass quintupled.

Source: Moon rock — Wikipedia

Public surface

use wisp_chart::indicator::{Kpi, Delta, DeltaKind};

let kpi = Kpi {
    value: 1_234_567.0,
    label: "Monthly Active Users".into(),
    delta: Some(Delta {
        kind: DeltaKind::Up,
        formatted: "+12.4% vs last mo".into(),
    }),
    sparkline: Some(vec![100.0, 105.0, 102.0, 110.0, 115.0]),
};

// Sparkline as Graphics:
let sparkline = kpi.emit_graphics(&theme, Vec2::new(240.0, 120.0));
let _ = stage.add_child(root, sparkline);

// Big number + label + delta as Text:
let font = Font::bitmap_8x8(&app);
for t in kpi.emit_text_labels(&theme, Vec2::new(240.0, 120.0), &font) {
    let _ = stage.add_child(root, t);
}

Numeric formatting

format_value compacts large magnitudes into the closest power-of-thousand abbreviation:

ValueRendered
2_500_000_0002.50B
1_234_5671.23M
45_67845.7K
789789
1.51.50

Override by formatting your value into a string and storing it in Delta.formatted if you need locale-specific formatting.

Delta colours

Info

DeltaKind::Up reads theme.indicator.delta_up (green by default), Down reads delta_down (red), Neutral reads delta_neutral (grey). The arrow glyph is ^ / v / - in v1 — replace with proper Unicode arrows once the bitmap atlas covers them.

Layout

The card is laid out within a viewport_px rectangle:

RegionPosition
Valuey = 12 px, left-aligned 8 px padding
LabelBelow value with 8 px gap
DeltaBelow label with 8 px gap
SparklineBottom 25% of viewport, 8 px horizontal padding