Skip to main content

flow_plots/options/
density.rs

1use crate::colormap::ColorMaps;
2use crate::options::{AxisOptions, BasePlotOptions, PlotOptions};
3use crate::plots::PlotType;
4use derive_builder::Builder;
5
6/// Options for density plots
7///
8/// Configuration for creating density plots, including base layout options,
9/// axis configurations, and color map selection.
10///
11/// # Example
12///
13/// ```rust,no_run
14/// use flow_plots::options::{DensityPlotOptions, BasePlotOptions};
15/// use flow_plots::colormap::ColorMaps;
16///
17/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
18/// let options = DensityPlotOptions::new()
19///     .base(BasePlotOptions::new().width(800u32).height(600u32).build()?)
20///     .colormap(ColorMaps::Viridis)
21///     .build()?;
22/// # Ok(())
23/// # }
24/// ```
25///
26/// @deprecated The old PlotOptions struct has been removed. Use DensityPlotOptions with builder pattern instead.
27#[derive(Builder, Clone, Debug)]
28#[builder(setter(into, strip_option), default)]
29pub struct DensityPlotOptions {
30    /// Base plot options (layout, dimensions, etc.)
31    #[builder(default)]
32    pub base: BasePlotOptions,
33
34    /// X-axis configuration
35    #[builder(default)]
36    pub x_axis: AxisOptions,
37
38    /// Y-axis configuration
39    #[builder(default)]
40    pub y_axis: AxisOptions,
41
42    /// Color map to use for density visualization
43    #[builder(default = "ColorMaps::Viridis")]
44    pub colormap: ColorMaps,
45
46    /// Plot type (density, scatter, contour, etc.)
47    #[builder(default)]
48    pub plot_type: PlotType,
49
50    /// Point size in pixels for scatter plots (0.5–4.0)
51    #[builder(default = "1.0")]
52    pub point_size: f32,
53
54    /// Contour line thickness in pixels (when plot_type is Contour)
55    #[builder(default = "1.0")]
56    pub contour_line_thickness: f32,
57
58    /// Number of contour levels (when plot_type is Contour)
59    #[builder(default = "5")]
60    pub contour_level_count: u32,
61}
62
63impl Default for DensityPlotOptions {
64    fn default() -> Self {
65        Self {
66            base: BasePlotOptions::default(),
67            x_axis: AxisOptions::default(),
68            y_axis: AxisOptions::default(),
69            colormap: ColorMaps::Viridis,
70            plot_type: PlotType::Density,
71            point_size: 1.0,
72            contour_line_thickness: 1.0,
73            contour_level_count: 5,
74        }
75    }
76}
77
78impl PlotOptions for DensityPlotOptions {
79    fn base(&self) -> &BasePlotOptions {
80        &self.base
81    }
82}
83
84impl DensityPlotOptions {
85    /// Create a new builder for DensityPlotOptions
86    pub fn new() -> DensityPlotOptionsBuilder {
87        DensityPlotOptionsBuilder::default()
88    }
89}