Skip to content

Interaction ​

Live demo
Try it: drag selects, the toolbar switches between pan, box zoom, and select, double-click resets.Open in a tab ↗

Pointer gestures ​

GestureAction
Drag with the pan toolMove the view
WheelZoom around the cursor; Shift = x only, Alt = y only
Alt + wheel with two y axesLeft half of the frame: the left y axis; right half: the right y axis
Wheel over an axis's ticksZoom that axis alone (outside the frame, inside the plot; corners do nothing)
Right-dragZoom to a box
Drag with the zoom toolZoom to a box; a thin box zooms one axis
Drag with the select toolSelect an area
Shift-dragSelect an area regardless of the active tool
Double-clickFit the data
ClickReport the nearest point within 12 pt as clicked and clear the selection
HoverRing, dashed guides, and a popup with series/x/y

The wheel is consumed by the plot, so a surrounding scroll area stays put while the cursor is over the frame or an axis.

Cursors ​

The cursor says what a gesture will do:

WhereCursor
Over the data areaCrosshair, whatever the tool
Pressing or dragging to panClosed hand
Drawing a zoom or selection boxCrosshair
Over an axis's tick labelsHorizontal (x) or vertical (y) resize arrows: the wheel zooms that axis
Over the legend or the toolbarThe ordinary pointer; the hovered row is shaded, its series animates, and that series draws above the others
Moving the legendClosed hand

Tools ​

PlotState::tool is PlotTool::{Pan, Zoom, Select}. The toolbar in the top-right corner switches tools, zooms in/out, and fits the data. Plot::toolbar(false) hides it.

rust
let mut state = PlotState::default();
state.tool = PlotTool::Select;

Selection ​

rust
let response = plot.show(ui, &mut icons, &mut state);
if response.selection_changed {
    if let Some(bounds) = state.selection {
        let inside = points_in(&data, &bounds);
        self.selected = inside;
    }
}

PlotState::selection is in data coordinates. A click clears it and sets selection_changed. The selection is painted with the selection color from the theme or PlotConfig::colors.selection.

Hover ​

PlotResponse::hovered holds the nearest point within 12 pt:

rust
pub struct PlotHover {
    pub series: String,
    pub index: usize,
    pub point: [f64; 2],
    pub axis: YAxis, // the y axis the series is measured on
}

The popup and the dashed guides can be disabled with PlotConfig::hover_popup and hover_guides. PlotResponse::pointer is the cursor in data coordinates while it is inside the frame.

Response ​

rust
pub struct PlotResponse {
    pub response: egui::Response,
    pub pointer: Option<[f64; 2]>,
    pub hovered: Option<PlotHover>,
    pub clicked: Option<PlotHover>,
    pub selection_changed: bool,
    pub view: Bounds,
    pub y2_view: Option<[f64; 2]>, // the right y axis, when shown
    pub frame: egui::Rect,
    pub settings_requested: bool,
    pub export_requested: Option<ExportFormat>,
    // private transform
}

screen_pos(point) and data_pos(pos) convert for overlays (left y axis); screen_pos_on(YAxis::Right, point) places a point measured on the right axis. view is the visible range in data coordinates.

Annotations ​

Draw on top of the plot after it returns, using the response transform:

rust
let response = plot.show(ui, &mut icons, &mut state);
if let Some(peak) = data.iter().max_by(|a, b| a[1].total_cmp(&b[1])) {
    let pos = response.screen_pos(*peak);
    ui.painter().circle_stroke(pos, 5.0, Stroke::new(1.5, theme.focus));
    ui.painter().text(
        pos + egui::vec2(8.0, -8.0),
        egui::Align2::LEFT_BOTTOM,
        "peak",
        egui_workbench::style::get(ui.ctx()).font(11.0), // follows the text scale
        ui.visuals().text_color(),
    );
}

This works because the plot does not repaint the whole UI; the annotation is painted in the same frame, in the same paint layer, after the plot's own shapes.

Legend ​

Clicking a legend row toggles that series. PlotState::is_hidden(name) and set_hidden(name, hidden) read and write the state; the application can persist it. PlotConfig::legend chooses the corner or hides the legend; legend_frame controls its background.

Dragging the legend moves it anywhere inside the frame. The position lives in the PlotState as fractions of the free room (legend_position()), so it holds while the application runs, survives resizes, and is used by exports too. set_legend_position(None) returns the legend to its configured corner.

3D interaction ​

Plot3D uses the same legend and toolbar behavior with a different camera:

GestureAction
DragOrbit around the data
Shift-drag, right-drag, or the pan toolMove the camera target
WheelZoom toward or away from the target
Double-click or the fit buttonFit the data again

The camera lives in Plot3DState; reset_view() fits the data and set_camera(camera) places it explicitly. Hovering a point draws a ring and a dashed drop line to the floor.

Focus and keyboard ​

The plot is a pointer-first component. The toolbar buttons are real IconButtons and therefore keyboard accessible. If your screen needs keyboard shortcuts for zoom or selection, bind them in the application keymap and mutate PlotState before show.

Repaint behavior ​

The plot requests repaint only while a drag, an animation, or live-data streaming is active. A still pointer on a still plot costs no frames.

Released under MIT OR Apache-2.0. Icons: Lucide (ISC) and Material Icon Theme (MIT).