pub struct BoxPlotState { /* private fields */ }Expand description
State for a BoxPlot component.
Contains the datasets, display configuration, and interaction state.
§Example
use envision::component::{BoxPlotState, BoxPlotData, BoxPlotOrientation};
let state = BoxPlotState::new(vec![
BoxPlotData::new("Service A", 10.0, 20.0, 30.0, 40.0, 50.0),
BoxPlotData::new("Service B", 15.0, 25.0, 35.0, 45.0, 55.0),
])
.with_title("Latency Distribution")
.with_show_outliers(true);
assert_eq!(state.datasets().len(), 2);
assert_eq!(state.title(), Some("Latency Distribution"));
assert!(state.show_outliers());Implementations§
Source§impl BoxPlotState
impl BoxPlotState
Sourcepub fn new(datasets: Vec<BoxPlotData>) -> Self
pub fn new(datasets: Vec<BoxPlotData>) -> Self
Creates a new box plot state with the given datasets.
§Example
use envision::component::{BoxPlotState, BoxPlotData};
let state = BoxPlotState::new(vec![
BoxPlotData::new("A", 1.0, 2.0, 3.0, 4.0, 5.0),
]);
assert_eq!(state.datasets().len(), 1);Sourcepub fn with_title(self, title: impl Into<String>) -> Self
pub fn with_title(self, title: impl Into<String>) -> Self
Sets the title (builder pattern).
§Example
use envision::component::{BoxPlotState, BoxPlotData};
let state = BoxPlotState::new(vec![
BoxPlotData::new("Test", 1.0, 2.0, 3.0, 4.0, 5.0),
])
.with_title("My Box Plot");
assert_eq!(state.title(), Some("My Box Plot"));Sourcepub fn with_show_outliers(self, show: bool) -> Self
pub fn with_show_outliers(self, show: bool) -> Self
Sets whether to show outliers (builder pattern).
§Example
use envision::component::BoxPlotState;
let state = BoxPlotState::default().with_show_outliers(false);
assert!(!state.show_outliers());Sourcepub fn with_orientation(self, orientation: BoxPlotOrientation) -> Self
pub fn with_orientation(self, orientation: BoxPlotOrientation) -> Self
Sets the orientation (builder pattern).
§Example
use envision::component::{BoxPlotState, BoxPlotOrientation};
let state = BoxPlotState::default()
.with_orientation(BoxPlotOrientation::Horizontal);
assert_eq!(state.orientation(), &BoxPlotOrientation::Horizontal);Sourcepub fn datasets(&self) -> &[BoxPlotData]
pub fn datasets(&self) -> &[BoxPlotData]
Returns the datasets.
§Example
use envision::component::{BoxPlotState, BoxPlotData};
let state = BoxPlotState::new(vec![
BoxPlotData::new("A", 1.0, 2.0, 3.0, 4.0, 5.0),
BoxPlotData::new("B", 2.0, 3.0, 4.0, 5.0, 6.0),
]);
assert_eq!(state.datasets().len(), 2);Sourcepub fn datasets_mut(&mut self) -> &mut [BoxPlotData]
pub fn datasets_mut(&mut self) -> &mut [BoxPlotData]
Returns a mutable reference to the datasets.
§Example
use envision::component::{BoxPlotState, BoxPlotData};
use ratatui::style::Color;
let mut state = BoxPlotState::new(vec![
BoxPlotData::new("A", 1.0, 2.0, 3.0, 4.0, 5.0),
]);
state.datasets_mut()[0].set_color(Color::Red);
assert_eq!(state.datasets()[0].color(), Color::Red);Sourcepub fn get_dataset(&self, index: usize) -> Option<&BoxPlotData>
pub fn get_dataset(&self, index: usize) -> Option<&BoxPlotData>
Returns the dataset at the given index.
§Example
use envision::component::{BoxPlotState, BoxPlotData};
let state = BoxPlotState::new(vec![
BoxPlotData::new("Service A", 1.0, 2.0, 3.0, 4.0, 5.0),
]);
assert_eq!(state.get_dataset(0).unwrap().label(), "Service A");
assert!(state.get_dataset(99).is_none());Sourcepub fn get_dataset_mut(&mut self, index: usize) -> Option<&mut BoxPlotData>
pub fn get_dataset_mut(&mut self, index: usize) -> Option<&mut BoxPlotData>
Returns a mutable reference to the dataset at the given index.
§Example
use envision::component::{BoxPlotState, BoxPlotData};
let mut state = BoxPlotState::new(vec![
BoxPlotData::new("Service A", 1.0, 2.0, 3.0, 4.0, 5.0),
]);
if let Some(ds) = state.get_dataset_mut(0) {
ds.set_label("Service B");
}
assert_eq!(state.datasets()[0].label(), "Service B");Sourcepub fn title(&self) -> Option<&str>
pub fn title(&self) -> Option<&str>
Returns the title.
§Example
use envision::component::BoxPlotState;
let state = BoxPlotState::default().with_title("Latency");
assert_eq!(state.title(), Some("Latency"));Sourcepub fn set_title(&mut self, title: Option<String>)
pub fn set_title(&mut self, title: Option<String>)
Sets the title.
§Example
use envision::component::BoxPlotState;
let mut state = BoxPlotState::default();
state.set_title(Some("Response Times".to_string()));
assert_eq!(state.title(), Some("Response Times"));Sourcepub fn show_outliers(&self) -> bool
pub fn show_outliers(&self) -> bool
Returns whether outliers are shown.
§Example
use envision::component::BoxPlotState;
let state = BoxPlotState::default();
assert!(state.show_outliers());Sourcepub fn set_show_outliers(&mut self, show: bool)
pub fn set_show_outliers(&mut self, show: bool)
Sets whether outliers are shown.
§Example
use envision::component::BoxPlotState;
let mut state = BoxPlotState::default();
state.set_show_outliers(false);
assert!(!state.show_outliers());Sourcepub fn orientation(&self) -> &BoxPlotOrientation
pub fn orientation(&self) -> &BoxPlotOrientation
Returns the orientation.
§Example
use envision::component::{BoxPlotState, BoxPlotOrientation};
let state = BoxPlotState::default().with_orientation(BoxPlotOrientation::Horizontal);
assert_eq!(state.orientation(), &BoxPlotOrientation::Horizontal);Sourcepub fn set_orientation(&mut self, orientation: BoxPlotOrientation)
pub fn set_orientation(&mut self, orientation: BoxPlotOrientation)
Sets the orientation.
§Example
use envision::component::{BoxPlotState, BoxPlotOrientation};
let mut state = BoxPlotState::default();
state.set_orientation(BoxPlotOrientation::Horizontal);
assert_eq!(state.orientation(), &BoxPlotOrientation::Horizontal);Sourcepub fn selected(&self) -> usize
pub fn selected(&self) -> usize
Returns the currently selected dataset index.
§Example
use envision::component::{BoxPlotState, BoxPlotData};
let state = BoxPlotState::new(vec![
BoxPlotData::new("A", 1.0, 2.0, 3.0, 4.0, 5.0),
]);
assert_eq!(state.selected(), 0);Sourcepub fn set_selected(&mut self, index: usize)
pub fn set_selected(&mut self, index: usize)
Sets the selected dataset index.
§Example
use envision::component::{BoxPlotState, BoxPlotData};
let mut state = BoxPlotState::new(vec![
BoxPlotData::new("A", 1.0, 2.0, 3.0, 4.0, 5.0),
BoxPlotData::new("B", 2.0, 3.0, 4.0, 5.0, 6.0),
]);
state.set_selected(1);
assert_eq!(state.selected(), 1);Sourcepub fn dataset_count(&self) -> usize
pub fn dataset_count(&self) -> usize
Returns the number of datasets.
§Example
use envision::component::{BoxPlotState, BoxPlotData};
let state = BoxPlotState::new(vec![
BoxPlotData::new("A", 1.0, 2.0, 3.0, 4.0, 5.0),
BoxPlotData::new("B", 2.0, 3.0, 4.0, 5.0, 6.0),
]);
assert_eq!(state.dataset_count(), 2);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if there are no datasets.
§Example
use envision::component::BoxPlotState;
assert!(BoxPlotState::default().is_empty());Sourcepub fn add_dataset(&mut self, dataset: BoxPlotData)
pub fn add_dataset(&mut self, dataset: BoxPlotData)
Adds a dataset.
§Example
use envision::component::{BoxPlotState, BoxPlotData};
let mut state = BoxPlotState::default();
state.add_dataset(BoxPlotData::new("A", 1.0, 2.0, 3.0, 4.0, 5.0));
assert_eq!(state.dataset_count(), 1);Sourcepub fn clear_datasets(&mut self)
pub fn clear_datasets(&mut self)
Clears all datasets.
§Example
use envision::component::{BoxPlotState, BoxPlotData};
let mut state = BoxPlotState::new(vec![
BoxPlotData::new("A", 1.0, 2.0, 3.0, 4.0, 5.0),
]);
state.clear_datasets();
assert!(state.is_empty());Sourcepub fn global_min(&self) -> f64
pub fn global_min(&self) -> f64
Computes the global minimum value across all datasets (including outliers if show_outliers is enabled).
§Example
use envision::component::{BoxPlotState, BoxPlotData};
let state = BoxPlotState::new(vec![
BoxPlotData::new("A", 5.0, 10.0, 20.0, 30.0, 40.0),
BoxPlotData::new("B", 8.0, 15.0, 25.0, 35.0, 50.0),
]);
assert_eq!(state.global_min(), 5.0);Sourcepub fn global_max(&self) -> f64
pub fn global_max(&self) -> f64
Computes the global maximum value across all datasets (including outliers if show_outliers is enabled).
§Example
use envision::component::{BoxPlotState, BoxPlotData};
let state = BoxPlotState::new(vec![
BoxPlotData::new("A", 5.0, 10.0, 20.0, 30.0, 40.0),
BoxPlotData::new("B", 8.0, 15.0, 25.0, 35.0, 50.0),
]);
assert_eq!(state.global_max(), 50.0);Sourcepub fn update(&mut self, msg: BoxPlotMessage) -> Option<()>
pub fn update(&mut self, msg: BoxPlotMessage) -> Option<()>
Updates the state with a message, returning any output.
Trait Implementations§
Source§impl Clone for BoxPlotState
impl Clone for BoxPlotState
Source§fn clone(&self) -> BoxPlotState
fn clone(&self) -> BoxPlotState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BoxPlotState
impl Debug for BoxPlotState
Source§impl Default for BoxPlotState
impl Default for BoxPlotState
Source§impl<'de> Deserialize<'de> for BoxPlotState
impl<'de> Deserialize<'de> for BoxPlotState
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for BoxPlotState
impl PartialEq for BoxPlotState
Source§impl Serialize for BoxPlotState
impl Serialize for BoxPlotState
impl StructuralPartialEq for BoxPlotState
Auto Trait Implementations§
impl Freeze for BoxPlotState
impl RefUnwindSafe for BoxPlotState
impl Send for BoxPlotState
impl Sync for BoxPlotState
impl Unpin for BoxPlotState
impl UnsafeUnpin for BoxPlotState
impl UnwindSafe for BoxPlotState
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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