Skip to main content

Module plot

Module plot 

Source
Expand description

Charts: time series, scatters and bars, on egui_plot.

Experimental: may change in any release (docs/stability.md).

It wraps egui_plot (MIT OR Apache-2.0), which draws the axes, the grid, the legend and the series and takes the zoom, the pan and the box zoom, and adds what an egui-pop view has:

  • the kit’s look: the plot component’s background, frame, axis text and grid, the plot-cursor component’s time cursor (its line, its head, its colour under the pointer), and each series in its slot of the categorical palette (palette.category.*, DataPalette), or in the slot an entity’s path hashes to (Series::entity);
  • an accessible summary: the plot is one node, named by its label, described by its series (their names, kinds, point counts and ranges) and its time cursor;
  • the point under the pointer, nearest within HOVER_RADIUS, in the output and marked on the plot;
  • time: an x axis in a timeline’s TimeScale (seconds, timecode, bars and beats, Plot::time_scale), a time cursor the application gives (Plot::time_cursor) or a timeline’s playhead, dragged both ways (Plot::timeline), its range highlighted, and every series’ value at the pointer in a tooltip (Plot::values_tooltip);
  • stepped lines (Kind::Steps) and error bands (Band);
  • decimation: a line, a stepped line or a band with more points in view than DECIMATION_THRESHOLD is drawn from the points the pixels can show (four a pixel column at most), read in the time range in view only when sorted by x (Plot::decimation);
  • the plots collector (PlotPlugin): every plot drawn with its series, ranges and hovered point, for agents.
use egui_pop_views::plot::{Plot, Series};

fn ui(ui: &mut egui::Ui, now: f64) {
    let series = [
        Series::line("Temperature", (0..100).map(|i| [i as f64, (i as f64 / 10.0).sin()])),
        Series::points("Samples", [[10.0, 0.5], [40.0, -0.3]]),
    ];
    let out = Plot::new("sensors", &series)
        .label("Sensors")
        .time_cursor(Some(now))
        .height(200.0)
        .show(ui);
    if let Some(h) = out.hovered {
        // `h.series`, `h.index`, `h.x`, `h.y`.
    }
}

Over a timeline’s time:

use egui_pop_views::plot::{Band, Plot, Series};
use egui_pop_views::timeline::{TimeScale, TimelineState};

fn ui(ui: &mut egui::Ui, timeline: &mut TimelineState) {
    let series = [
        Series::line("speed", (0..=40).map(|i| [i as f64 / 2.0, (i as f64 / 6.0).sin()]))
            .entity("/robot/speed"),
        Series::steps("gear", [[0.0, 1.0], [6.0, 2.0], [12.0, 3.0]]),
    ];
    let bands = [Band::new(0, (0..=40).map(|i| {
        let y = (i as f64 / 6.0).sin();
        [i as f64 / 2.0, y - 0.2, y + 0.2]
    }))];
    // The playhead is the cursor; dragging the cursor moves the playhead.
    Plot::new("robot", &series).bands(&bands).timeline(timeline).show(ui);
}

Structs§

Band
An error band: a fill between a minimum and a maximum along x, in the colour of a series of the plot, under the lines.
CursorLook
The time cursor’s look beyond the kit’s box: its head and its size.
GridLook
The plot’s grid (plot.grid-color, plot.grid-fade).
Hovered
The point under the pointer.
Plot
A plot widget.
PlotOutput
What Plot::show returns.
PlotPlugin
Declares the plots collector. Connect it when an application’s plots should be read by agents; the widgets draw without it.
Plots
The plots drawn in a context, by id: what the plots collector shows.
Series
A series of a plot: a name, a kind and its points.
ValueAt
A series’ value at an x.
ValuesAt
Every line’s and stepped line’s value at an x: a line’s between its two points around it, a stepped line’s the last point’s at or before it. Scatters and bars have none.

Enums§

CursorHead
The time cursor’s head (plot-cursor.head).
Kind
How a series is drawn.

Constants§

DECIMATION_THRESHOLD
Above how many points in view a line, a stepped line or a band is decimated by default (Plot::decimation).
HOVER_RADIUS
How far from a point, in points on screen, the pointer still hovers it.
PLUGIN
The plugin’s id.

Functions§

entity_slot
The categorical palette’s slot for an entity, from its path: a stable hash (FNV-1a), the same on every platform and in every run. The idea of colouring an entity by a hash of its path is Rerun’s automatic colour; here it lands on the palette’s slots rather than on a hue, so a kit’s palette still holds. Two paths may share a slot: give one a slot of its own (Series::slot) when they meet in a plot.
summary
The accessible description: each series, then the time cursor.
values_at
Each line’s and stepped line’s value at x (their points sorted by x); none outside a series’ x range. The points around x are found by binary search.