pub struct ScatterGraph {
pub title: String,
pub x_label: String,
pub y_label: String,
pub datasets: Vec<ScatterGraphDataset>,
pub config: FigureConfig,
}
Expand description
Represents a scatter graph, including title, axis labels, datasets, and configuration settings.
Fields§
§title: String
Title of the scatter graph.
x_label: String
Label for the X-axis.
y_label: String
Label for the Y-axis.
datasets: Vec<ScatterGraphDataset>
A collection of datasets to be visualized on the scatter graph.
config: FigureConfig
Configuration settings for rendering the graph (e.g., colors, fonts, grid).
Implementations§
source§impl ScatterGraph
impl ScatterGraph
sourcepub fn new(
title: &str,
x_label: &str,
y_label: &str,
config: FigureConfig,
) -> Self
pub fn new( title: &str, x_label: &str, y_label: &str, config: FigureConfig, ) -> Self
Creates a new ScatterGraph
instance with the specified title, labels, and configuration.
§Parameters
title
: The title of the scatter graph.x_label
: The label for the X-axis.y_label
: The label for the Y-axis.config
: TheFigureConfig
containing appearance and behavior settings.
§Returns
A new ScatterGraph
instance with an empty dataset.
§Example
use crate::figure::configuration::figureconfig::FigureConfig;
use crate::figure::scattergraph::ScatterGraph;
let config = FigureConfig::default();
let scatter_graph = ScatterGraph::new("Data Points", "X Axis", "Y Axis", config);
sourcepub fn add_dataset(&mut self, dataset: ScatterGraphDataset)
pub fn add_dataset(&mut self, dataset: ScatterGraphDataset)
Adds a dataset to the scatter graph.
§Parameters
dataset
: TheScatterGraphDataset
to be added to the graph.
§Example
use crate::figure::datasets::scattergraphdataset::ScatterGraphDataset;
use crate::figure::utilities::scatterdottype::ScatterDotType;
let dataset = ScatterGraphDataset {
points: vec![(1.0, 2.0), (3.0, 4.0)],
color: [255, 0, 0],
label: "Dataset 1".to_string(),
dot_type: ScatterDotType::Circle(5),
};
scatter_graph.add_dataset(dataset);
sourcepub fn draw_dot(
&self,
canvas: &mut PixelCanvas,
x: i32,
y: i32,
dot_type: ScatterDotType,
color: [u8; 3],
)
pub fn draw_dot( &self, canvas: &mut PixelCanvas, x: i32, y: i32, dot_type: ScatterDotType, color: [u8; 3], )
Draws a single dot on the canvas using the specified dot type and color.
§Parameters
canvas
: ThePixelCanvas
to draw the dot on.x
: The x-coordinate of the dot’s center on the canvas.y
: The y-coordinate of the dot’s center on the canvas.dot_type
: The shape and size of the dot (ScatterDotType
).color
: The RGB color of the dot.
§Details
Supports different dot types:
Circle
: A circular dot with a specified radius.Square
: A square-shaped dot with a specified size.Cross
: A cross-shaped dot with a specified thickness.Triangle
: An upward-pointing triangular dot with a specified base width.
§Example
scatter_graph.draw_dot(&mut canvas, 100, 100, ScatterDotType::Circle(5), [255, 0, 0]);
Trait Implementations§
source§impl Drawer for ScatterGraph
impl Drawer for ScatterGraph
source§fn draw_svg(&mut self, svg_canvas: &mut SvgCanvas)
fn draw_svg(&mut self, svg_canvas: &mut SvgCanvas)
Draws the plot content on an
SvgCanvas
. Read moresource§fn draw(&mut self, canvas: &mut PixelCanvas)
fn draw(&mut self, canvas: &mut PixelCanvas)
Draws the main content of the plot on a
PixelCanvas
. Read moresource§fn draw_legend(&self, canvas: &mut PixelCanvas)
fn draw_legend(&self, canvas: &mut PixelCanvas)
Draws the legend for the plot on a
PixelCanvas
. Read moresource§fn draw_grid(&self, canvas: &mut PixelCanvas, config: &FigureConfig)
fn draw_grid(&self, canvas: &mut PixelCanvas, config: &FigureConfig)
Draws the grid for the plot based on the provided configuration. Read more
source§fn draw_axis(
&self,
canvas: &mut PixelCanvas,
config: &FigureConfig,
x1: i32,
y1: i32,
x2: i32,
y2: i32,
)
fn draw_axis( &self, canvas: &mut PixelCanvas, config: &FigureConfig, x1: i32, y1: i32, x2: i32, y2: i32, )
Draws an axis line on the canvas. Read more
source§fn draw_label(
&self,
canvas: &mut PixelCanvas,
config: &FigureConfig,
x: u32,
y: u32,
text: &str,
)
fn draw_label( &self, canvas: &mut PixelCanvas, config: &FigureConfig, x: u32, y: u32, text: &str, )
Draws a text label on the canvas. Read more
source§fn draw_title(
&self,
canvas: &mut PixelCanvas,
config: &FigureConfig,
x: u32,
y: u32,
text: &str,
)
fn draw_title( &self, canvas: &mut PixelCanvas, config: &FigureConfig, x: u32, y: u32, text: &str, )
Draws the plot title on the canvas. Read more
source§fn draw_axis_value(
&self,
canvas: &mut PixelCanvas,
config: &FigureConfig,
x: u32,
y: u32,
text: &str,
axis: AxisType,
)
fn draw_axis_value( &self, canvas: &mut PixelCanvas, config: &FigureConfig, x: u32, y: u32, text: &str, axis: AxisType, )
Draws a value on the axis (tick label) based on its type. Read more
source§impl Hover for ScatterGraph
impl Hover for ScatterGraph
source§fn 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. Read more
source§fn 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. Read more
source§fn 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. Read more
Auto Trait Implementations§
impl Freeze for ScatterGraph
impl RefUnwindSafe for ScatterGraph
impl Send for ScatterGraph
impl Sync for ScatterGraph
impl Unpin for ScatterGraph
impl UnwindSafe for ScatterGraph
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.