#[derive(Debug, Clone)]
pub struct DensityPlot {
pub data: Vec<f64>,
pub color: String,
pub filled: bool,
pub opacity: f64,
pub bandwidth: Option<f64>,
pub kde_samples: usize,
pub stroke_width: f64,
pub legend_label: Option<String>,
pub line_dash: Option<String>,
pub precomputed: Option<(Vec<f64>, Vec<f64>)>,
}
impl Default for DensityPlot {
fn default() -> Self { Self::new() }
}
impl DensityPlot {
pub fn new() -> Self {
Self {
data: vec![],
color: "steelblue".to_string(),
filled: false,
opacity: 0.2,
bandwidth: None,
kde_samples: 200,
stroke_width: 1.5,
legend_label: None,
line_dash: None,
precomputed: None,
}
}
pub fn from_curve(x: Vec<f64>, y: Vec<f64>) -> Self {
Self {
precomputed: Some((x, y)),
..Self::new()
}
}
pub fn with_data<T, I>(mut self, data: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<f64>,
{
self.data = data.into_iter().map(|x| x.into()).collect();
self
}
pub fn with_color<S: Into<String>>(mut self, color: S) -> Self {
self.color = color.into();
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, bandwidth: f64) -> Self {
self.bandwidth = Some(bandwidth);
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_legend<S: Into<String>>(mut self, label: S) -> Self {
self.legend_label = Some(label.into());
self
}
pub fn with_line_dash<S: Into<String>>(mut self, dash: S) -> Self {
self.line_dash = Some(dash.into());
self
}
}