GPUI Deck

Chart

Categorical series, grouped/stacked/pie/radar layouts, visible-series domain, linear or angular point inspection and exact native values.

Rendered by GPUI’s web backend from the real component. Requires a browser with WebGPU.

ChartState accepts category labels and ChartSeries values. Each series has one finite value per category. The retained state supplies visible series, inspected category, exact-value descriptions, and a zero-inclusive signed numeric range. Hiding all series or using all-zero data yields a usable 0..1 range. The range is retained until visibility or layout changes; normalizing a point does not rescan the dataset.

ChartLayout selects how the same data shares the plot, and set_layout keeps visibility and inspection:

  • Grouped (default) places side-by-side series over evenly spaced category bands.
  • Stacked stacks positive and negative values separately from zero. Its range covers each category's visible sums, and stack_span(series, category) gives a visible segment's start and end values.
  • Pie gives each category one slice sized by its nonnegative visible-series total. pie_slices returns start/end turns; a zero or negative total has an empty slice.
  • Radar places categories on evenly spaced spokes (radar_turn) with radii normalized like Grouped.

Radial turns run clockwise from the top and mirror counterclockwise in RTL. Chart provides a named plot focus region: Left/Right/Home/End inspect categories in every layout. Pointer travel inspects by horizontal band for Grouped/Stacked, and by angle inside the largest centered circle for Pie/Radar; a pointer outside that circle or over no slice keeps the current inspection. It emits inspection/visibility events without prescribing colors or draw paths.

The copyable examples/recipes/chart.rs builds on this behavior with GPUI canvas line, grouped bar, area, stacked bar/area, pie, donut and radar plots, axis or spoke labels, a pie category key, Toggle-based series legend, an exact-value readout and an ordinary Table containing the same complete dataset. ChartKind::layout names the state layout each kind draws; the catalogue's Media and data view sets both when switching kind or direction and retains legend/inspection state. Plot geometry, palette and numeric formatting belong to the consumer. This categorical contract does not supply time/log scales, per-slice legend selection, zoom, streaming data ingestion or a separate rendering engine.

When copying the recipe, pass the plot's accessible name, the full table's name and its category column heading to ChartRecipe::new. The default ticks retain fractional values. Use format_value to apply your units to the ticks, visible readout, native plot value and table cells:

let state = cx.new(|cx| ChartState::new(
    ["Search", "Cart", "Pay"],
    [
        ChartSeries::new("Median", [0.12, 0.08, 0.18]),
        ChartSeries::new("P95", [0.32, 0.2, 0.4]),
    ],
    cx,
));

ChartRecipe::new("latency", &state, ChartKind::Line, Direction::Ltr,
    "Request latency", "All latency measurements", "Route")
    .format_value(|value| format!("{value} s"))