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 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 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 hover( &mut self, _hover: Option<&PlotHover>, _window: &mut Window, _cx: &mut App, )

Receive the datum in focus 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::focus 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 (gpui_base::transition, gpui_base::spring) 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 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.

Also called while the hover fades out, with the lingering state and the last cursor; a tooltip::Tooltip returned here fades with the hover on its own.

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>