pub trait Hover {
// Required methods
fn find_closest_point(
&self,
mouse_x: u32,
mouse_y: u32,
canvas: &PixelCanvas,
) -> Option<((f64, f64), f64)>;
fn to_canvas_coordinates(
&self,
x: f64,
y: f64,
canvas: &PixelCanvas,
) -> (u32, u32);
fn get_font<'a>(&self, font_data: &'a [u8]) -> FontRef<'a>;
fn handle_hover(
&self,
mouse_x: u32,
mouse_y: u32,
canvas: &PixelCanvas,
) -> Option<Vec<u32>>;
}
Expand description
A trait for plots that support hover functionality, allowing interactive features like highlighting and displaying information about data points.
Required Methods§
sourcefn find_closest_point(
&self,
mouse_x: u32,
mouse_y: u32,
canvas: &PixelCanvas,
) -> Option<((f64, f64), f64)>
fn find_closest_point( &self, mouse_x: u32, mouse_y: u32, canvas: &PixelCanvas, ) -> Option<((f64, f64), f64)>
Finds the closest point to the mouse position on the plot.
§Parameters
mouse_x
: The x-coordinate of the mouse position in canvas space.mouse_y
: The y-coordinate of the mouse position in canvas space.canvas
: ThePixelCanvas
being used for rendering the plot.
§Returns
An optional tuple containing:
((f64, f64), f64)
:- The
(x, y)
coordinates of the closest point. - The distance from the mouse position to the point.
- The
Returns None
if no points are found.
sourcefn to_canvas_coordinates(
&self,
x: f64,
y: f64,
canvas: &PixelCanvas,
) -> (u32, u32)
fn to_canvas_coordinates( &self, x: f64, y: f64, canvas: &PixelCanvas, ) -> (u32, u32)
Converts plot coordinates into canvas pixel coordinates.
§Parameters
x
: The x-coordinate in the plot’s coordinate system.y
: The y-coordinate in the plot’s coordinate system.canvas
: ThePixelCanvas
being used for rendering the plot.
§Returns
A tuple (u32, u32)
representing the corresponding pixel coordinates on the canvas.
sourcefn handle_hover(
&self,
mouse_x: u32,
mouse_y: u32,
canvas: &PixelCanvas,
) -> Option<Vec<u32>>
fn handle_hover( &self, mouse_x: u32, mouse_y: u32, canvas: &PixelCanvas, ) -> Option<Vec<u32>>
Handles hover functionality and returns an updated buffer if applicable.
This method is used to modify the canvas buffer in response to hover events, such as highlighting a data point or displaying additional information.
§Parameters
mouse_x
: The x-coordinate of the mouse position in canvas space.mouse_y
: The y-coordinate of the mouse position in canvas space.canvas
: ThePixelCanvas
being used for rendering the plot.
§Returns
An optional vector of u32
representing the updated pixel buffer.
If no changes are made, returns None
.