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 interactive(&self) -> bool { ... }
    fn appear(
        &mut self,
        _appear: PlotAppear,
        _window: &mut Window,
        _cx: &mut App,
    ) { ... }
    fn appear_generation(&self) -> Option<u64> { ... }
    fn tooltip_state(
        &self,
        _position: Point<Pixels>,
        _bounds: Bounds<Pixels>,
        _cx: &App,
    ) -> Option<TooltipState> { ... }
    fn hover(
        &mut self,
        _hover: Option<&PlotHover>,
        _window: &mut Window,
        _cx: &mut App,
    ) { ... }
    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 keeps this plot’s state across frames.

Return Some(id) to opt in to appear motion and, unless Plot::interactive says otherwise, tooltips and hover motion; the id must be unique among sibling elements. Returning None (the default for a hand-written plot) leaves the plot a pure element that neither appears nor tracks hover.

The charts in GPUI Component always return Some: their id defaults to the source location they were constructed at, and id renames it.

Source

fn interactive(&self) -> bool

Whether a plot with an Plot::id tracks hover and shows its tooltip.

false keeps the id’s state — appear motion and path caches — without the hitbox, hover tracking or overlay. The default is true, so a plot opts in to tooltips by returning an id.

Source

fn appear(&mut self, _appear: PlotAppear, _window: &mut Window, _cx: &mut App)

Receive how far the plot’s data marks have appeared this frame, before Plot::hover and Plot::paint run.

Called on every frame the plot has an Plot::id; see PlotAppear. Without an Plot::appear_generation the appear is always complete. The default ignores it.

Source

fn appear_generation(&self) -> Option<u64>

Opt in to appear motion: Some draws the plot in the first time its id is painted, and again whenever the value changes, such as when a chart switches to another symbol or period.

The default, None, tracks no appear, keeps no state for it and asks for no frames, so a plot that does not draw in costs nothing.

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), or None to show nothing. Only called while the cursor is inside bounds.

The default returns None.

Source

fn hover( &mut self, _hover: Option<&PlotHover>, _window: &mut Window, _cx: &mut App, )

Receive the hovered datum this frame, before Plot::tooltip and Plot::paint run.

hover carries the TooltipState the cursor resolved to, and it lingers after the cursor leaves while PlotHover::progress eases back to zero, so a hover-driven presentation can fade out over the last datum instead of vanishing. None means nothing is hovered and nothing is fading.

Called on every frame the plot has an Plot::id, so this is where a plot samples its hover motion (crate::motion::transition, PlotHover::glide) and keeps the result for the other two methods. The default ignores the hover.

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 the styled layer’s tooltip). Return the overlay element; it is painted absolutely positioned above the plot graphics but below sibling content drawn after the plot (a box that may overflow the plot should deferred itself). The default returns None.

Also called while the hover fades out, with the lingering state and the last cursor; the overlay renders within the plot’s element scope, so it can fade with hover_progress.

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: PlotValue,

Source§

impl<T, X, Y> Plot for AreaChart<T, X, Y>
where X: Clone + PartialEq + Into<SharedString> + 'static, Y: PlotValue,

Source§

impl<T, X, Y> Plot for CandlestickChart<T, X, Y>
where X: Eq + Hash + Into<SharedString> + 'static, Y: PlotValue,

Source§

impl<T, X, Y> Plot for LineChart<T, X, Y>
where X: PartialEq + Into<SharedString> + 'static, Y: PlotValue,

Source§

impl<T, Y> Plot for RadarChart<T, Y>
where Y: PlotValue,

Source§

impl<T> Plot for PieChart<T>

Source§

impl<T> Plot for SankeyChart<T>