pub struct Histogram {
pub title: String,
pub x_label: String,
pub y_label: String,
pub bins: usize,
pub data: Vec<f64>,
pub color: [u8; 3],
pub min: f64,
pub max: f64,
pub bin_counts: Vec<f64>,
pub bin_width: f64,
pub config: FigureConfig,
}
Expand description
Represents a histogram, including title, axis labels, bin configuration, and cached data.
Fields§
§title: String
Title of the histogram.
x_label: String
Label for the X-axis.
y_label: String
Label for the Y-axis.
bins: usize
Number of bins in the histogram.
data: Vec<f64>
Raw data values to be represented in the histogram.
color: [u8; 3]
Color of the histogram bars in RGB format.
min: f64
Cached minimum value in the dataset.
max: f64
Cached maximum value in the dataset.
bin_counts: Vec<f64>
Cached frequencies for each bin.
bin_width: f64
Cached width of each bin.
config: FigureConfig
Configuration settings for rendering the histogram.
Implementations§
source§impl Histogram
impl Histogram
sourcepub fn new(
title: &str,
x_label: &str,
y_label: &str,
bins: usize,
color: [u8; 3],
config: FigureConfig,
) -> Self
pub fn new( title: &str, x_label: &str, y_label: &str, bins: usize, color: [u8; 3], config: FigureConfig, ) -> Self
Creates a new Histogram
instance with the specified configuration.
§Parameters
title
: The title of the histogram.x_label
: The label for the X-axis.y_label
: The label for the Y-axis.bins
: The number of bins in the histogram.color
: The RGB color of the histogram bars.config
: TheFigureConfig
containing appearance and behavior settings.
§Returns
A new Histogram
instance with empty data and initialized bins.
§Example
use crate::figure::configuration::figureconfig::FigureConfig;
use crate::figure::histogram::Histogram;
let config = FigureConfig::default();
let histogram = Histogram::new("Data Distribution", "Values", "Frequency", 10, [255, 0, 0], config);
sourcepub fn add_data_vec(&mut self, values: Vec<f64>)
pub fn add_data_vec(&mut self, values: Vec<f64>)
sourcepub fn calculate_bins(&self) -> Vec<(f64, f64)>
pub fn calculate_bins(&self) -> Vec<(f64, f64)>
Calculates the bin ranges and frequencies for the histogram.
§Returns
A vector of tuples where each tuple contains:
- The starting value of the bin.
- The frequency count for that bin.
§Example
let bins = histogram.calculate_bins();
for (start, count) in bins {
println!("Bin starts at {}, count is {}", start, count);
}
Trait Implementations§
source§impl Drawer for Histogram
impl Drawer for Histogram
source§fn draw_svg(&mut self, svg_canvas: &mut SvgCanvas)
fn draw_svg(&mut self, svg_canvas: &mut SvgCanvas)
SvgCanvas
. Read moresource§fn draw(&mut self, canvas: &mut PixelCanvas)
fn draw(&mut self, canvas: &mut PixelCanvas)
PixelCanvas
. Read moresource§fn draw_legend(&self, _canvas: &mut PixelCanvas)
fn draw_legend(&self, _canvas: &mut PixelCanvas)
PixelCanvas
. Read moresource§fn draw_grid(&self, canvas: &mut PixelCanvas, config: &FigureConfig)
fn draw_grid(&self, canvas: &mut PixelCanvas, config: &FigureConfig)
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, )
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, )
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, )
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, )
source§impl Hover for Histogram
impl Hover for Histogram
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>>
Handle hover functionality and return updated buffer if applicable
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)>
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)
Auto Trait Implementations§
impl Freeze for Histogram
impl RefUnwindSafe for Histogram
impl Send for Histogram
impl Sync for Histogram
impl Unpin for Histogram
impl UnwindSafe for Histogram
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
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>
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>
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>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
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
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.