use super::types::{BoxStats, WhiskerStyle};
use crate::style::Color;
#[derive(Clone, Debug)]
pub struct BoxGroup {
pub label: String,
pub data: Vec<f64>,
pub stats: Option<BoxStats>,
pub color: Option<Color>,
}
impl BoxGroup {
pub fn new(label: impl Into<String>, data: &[f64]) -> Self {
Self {
label: label.into(),
data: data.to_vec(),
stats: None,
color: None,
}
}
pub fn from_stats(label: impl Into<String>, stats: BoxStats) -> Self {
Self {
label: label.into(),
data: Vec::new(),
stats: Some(stats),
color: None,
}
}
pub fn color(mut self, color: Color) -> Self {
self.color = Some(color);
self
}
pub fn get_stats(&self, whisker_style: WhiskerStyle) -> Option<BoxStats> {
self.stats
.clone()
.or_else(|| BoxStats::from_data(&self.data, whisker_style))
}
}