Skip to main content

Plot

Trait Plot 

Source
pub trait Plot: IntoElement {
    // Required method
    fn paint(
        &mut self,
        bounds: Bounds<Pixels>,
        window: &mut Window,
        cx: &mut App,
    );

    // Provided methods
    fn prepaint(
        &mut self,
        _bounds: Bounds<Pixels>,
        _window: &mut Window,
        _cx: &mut App,
    ) -> Vec<AnyElement> { ... }
    fn id(&self) -> Option<ElementId> { ... }
    fn tooltip_state(
        &self,
        _position: Point<Pixels>,
        _bounds: Bounds<Pixels>,
        _cx: &App,
    ) -> Option<TooltipState> { ... }
    fn tooltip(
        &self,
        _state: &TooltipState,
        _cursor: Point<Pixels>,
        _bounds: Bounds<Pixels>,
        _window: &mut Window,
        _cx: &mut App,
    ) -> Option<AnyElement> { ... }
}

Required Methods§

Source

fn paint(&mut self, bounds: Bounds<Pixels>, window: &mut Window, cx: &mut App)

Provided Methods§

Source

fn prepaint( &mut self, _bounds: Bounds<Pixels>, _window: &mut Window, _cx: &mut App, ) -> Vec<AnyElement>

Lay out and place the child elements this plot hosts (e.g. element labels).

Called during the element’s prepaint phase, so implementations may use AnyElement::layout_as_root / AnyElement::prepaint_at to measure and position children — neither is legal from Plot::paint. The returned elements are painted right after paint, below the tooltip overlay.

Runs before Plot::tooltip_state and Plot::tooltip, so anything resolved here can be reused by them.

The default returns no children.

Source

fn id(&self) -> Option<ElementId>

A stable element id that enables interactive tooltip support for this plot.

Return Some(id) to opt in to tooltips; the id must be unique among sibling elements. Returning None (the default) disables all tooltip behavior, leaving the plot a pure, non-interactive element identical to the pre-tooltip behavior.

Source

fn tooltip_state( &self, _position: Point<Pixels>, _bounds: Bounds<Pixels>, _cx: &App, ) -> Option<TooltipState>

Map the cursor to the tooltip state to display.

position is the cursor position relative to the plot’s top-left origin (already origin-subtracted), and bounds is the painted area. Return the TooltipState to display (highlighted index, crosshair point, dots, side), or None to show nothing. Only called while the cursor is inside bounds.

The default returns None.

Source

fn tooltip( &self, _state: &TooltipState, _cursor: Point<Pixels>, _bounds: Bounds<Pixels>, _window: &mut Window, _cx: &mut App, ) -> Option<AnyElement>

Render the tooltip overlay for the active TooltipState.

cursor is the live cursor position (relative to the plot origin) and bounds is the plot’s painted area, so the tooltip box can follow the cursor (pass cursor and bounds.size to tooltip::Tooltip::new). Return the overlay element; it is painted absolutely positioned above the plot graphics but below sibling content drawn after the plot (tooltip::Tooltip defers its box to paint above everything). The default returns None.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T, B, V> Plot for BarChart<T, B, V>
where B: Eq + Hash + Into<SharedString> + 'static, V: Copy + PartialOrd + Num + ToPrimitive + Sealed + 'static,

Source§

impl<T, X, Y> Plot for AreaChart<T, X, Y>
where X: Clone + PartialEq + Into<SharedString> + 'static, Y: Clone + Copy + PartialOrd + Num + ToPrimitive + Sealed + 'static,

Source§

impl<T, X, Y> Plot for CandlestickChart<T, X, Y>
where X: Eq + Hash + Into<SharedString> + 'static, Y: Copy + PartialOrd + Num + ToPrimitive + Sealed + 'static,

Source§

impl<T, X, Y> Plot for LineChart<T, X, Y>
where X: PartialEq + Into<SharedString> + 'static, Y: Copy + PartialOrd + Num + ToPrimitive + Sealed + 'static,

Source§

impl<T, Y> Plot for RadarChart<T, Y>
where Y: Clone + Copy + PartialOrd + Num + ToPrimitive + Sealed + 'static,

Source§

impl<T> Plot for PieChart<T>

Source§

impl<T> Plot for SankeyChart<T>