Skip to main content

BoxPlotState

Struct BoxPlotState 

Source
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

Source

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);
Source

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"));
Source

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());
Source

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);
Source

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);
Source

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);
Source

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());
Source

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");
Source

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"));
Source

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"));
Source

pub fn show_outliers(&self) -> bool

Returns whether outliers are shown.

§Example
use envision::component::BoxPlotState;

let state = BoxPlotState::default();
assert!(state.show_outliers());
Source

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());
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

pub fn is_empty(&self) -> bool

Returns true if there are no datasets.

§Example
use envision::component::BoxPlotState;

assert!(BoxPlotState::default().is_empty());
Source

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);
Source

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());
Source

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);
Source

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);
Source

pub fn update(&mut self, msg: BoxPlotMessage) -> Option<()>

Updates the state with a message, returning any output.

Trait Implementations§

Source§

impl Clone for BoxPlotState

Source§

fn clone(&self) -> BoxPlotState

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BoxPlotState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BoxPlotState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for BoxPlotState

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for BoxPlotState

Source§

fn eq(&self, other: &BoxPlotState) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for BoxPlotState

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for BoxPlotState

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> StateExt for T

Source§

fn updated(self, cmd: Command<impl Clone>) -> UpdateResult<Self, impl Clone>

Updates self and returns a command.
Source§

fn unchanged(self) -> UpdateResult<Self, ()>

Returns self with no command.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,