#[derive(Debug, Clone)]
pub struct RidgelinePlot {
pub groups: Vec<RidgelineGroup>,
pub filled: bool,
pub opacity: f64,
pub bandwidth: Option<f64>,
pub kde_samples: usize,
pub stroke_width: f64,
pub overlap: f64,
pub normalize: bool,
pub show_legend: bool,
pub line_dash: Option<String>,
pub show_baseline: bool,
}
#[derive(Debug, Clone)]
pub struct RidgelineGroup {
pub label: String,
pub values: Vec<f64>,
pub color: Option<String>,
}
impl Default for RidgelinePlot {
fn default() -> Self { Self::new() }
}
impl RidgelinePlot {
pub fn new() -> Self {
Self {
groups: vec![],
filled: true,
opacity: 0.7,
bandwidth: None,
kde_samples: 200,
stroke_width: 1.5,
overlap: 0.5,
normalize: false,
show_legend: false,
line_dash: None,
show_baseline: true,
}
}
pub fn with_group<S, T, I>(mut self, label: S, data: I) -> Self
where
S: Into<String>,
I: IntoIterator<Item = T>,
T: Into<f64>,
{
self.groups.push(RidgelineGroup {
label: label.into(),
values: data.into_iter().map(|x| x.into()).collect(),
color: None,
});
self
}
pub fn with_group_color<S, C, T, I>(mut self, label: S, data: I, color: C) -> Self
where
S: Into<String>,
C: Into<String>,
I: IntoIterator<Item = T>,
T: Into<f64>,
{
self.groups.push(RidgelineGroup {
label: label.into(),
values: data.into_iter().map(|x| x.into()).collect(),
color: Some(color.into()),
});
self
}
pub fn with_groups<S, T, I, II>(mut self, groups: II) -> Self
where
S: Into<String>,
T: Into<f64>,
I: IntoIterator<Item = T>,
II: IntoIterator<Item = (S, I)>,
{
for (label, data) in groups {
self.groups.push(RidgelineGroup {
label: label.into(),
values: data.into_iter().map(|x| x.into()).collect(),
color: None,
});
}
self
}
pub fn with_baseline(mut self, show: bool) -> Self { self.show_baseline = show; self }
pub fn with_filled(mut self, filled: bool) -> Self { self.filled = filled; self }
pub fn with_opacity(mut self, opacity: f64) -> Self { self.opacity = opacity; self }
pub fn with_bandwidth(mut self, bw: f64) -> Self { self.bandwidth = Some(bw); self }
pub fn with_kde_samples(mut self, samples: usize) -> Self { self.kde_samples = samples; self }
pub fn with_stroke_width(mut self, width: f64) -> Self { self.stroke_width = width; self }
pub fn with_overlap(mut self, overlap: f64) -> Self { self.overlap = overlap; self }
pub fn with_normalize(mut self, normalize: bool) -> Self { self.normalize = normalize; self }
pub fn with_legend(mut self, show: bool) -> Self { self.show_legend = show; self }
pub fn with_line_dash<S: Into<String>>(mut self, dash: S) -> Self { self.line_dash = Some(dash.into()); self }
}