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 and density plots (0.1–4.0).
51 /// For scatter: radius of each point; values below 0.5 draw single-pixel dots.
52 /// For density: radius of each point's contribution to the heatmap.
53 #[builder(default = "1.0")]
54 pub point_size: f32,
55
56 /// Contour line thickness in pixels (when plot_type is Contour)
57 #[builder(default = "1.0")]
58 pub contour_line_thickness: f32,
59
60 /// Number of contour levels (when plot_type is Contour)
61 #[builder(default = "5")]
62 pub contour_level_count: u32,
63
64 /// KDE bandwidth adjustment factor (when plot_type is Contour).
65 /// Higher values = more smoothing. Default 1.0. Typical range 0.5–2.0.
66 #[builder(default = "1.0")]
67 pub contour_smoothing: f64,
68
69 /// Draw scatter points outside contour regions as outliers (when plot_type is Contour)
70 #[builder(default = "false")]
71 pub draw_outliers: bool,
72
73 /// Colors for discrete gate overlay (ScatterOverlay, ContourOverlay).
74 /// gate_ids in data index into this slice. Default palette used if empty.
75 #[builder(default)]
76 pub gate_colors: Vec<(u8, u8, u8)>,
77
78 /// Z-axis range for continuous coloring (ScatterColoredContinuous).
79 /// If None, min/max of z_values is used.
80 #[builder(default)]
81 pub z_range: Option<(f32, f32)>,
82}
83
84impl Default for DensityPlotOptions {
85 fn default() -> Self {
86 Self {
87 base: BasePlotOptions::default(),
88 x_axis: AxisOptions::default(),
89 y_axis: AxisOptions::default(),
90 colormap: ColorMaps::Viridis,
91 plot_type: PlotType::Density,
92 point_size: 1.0,
93 contour_line_thickness: 1.0,
94 contour_level_count: 5,
95 contour_smoothing: 1.0,
96 draw_outliers: false,
97 gate_colors: Vec::new(),
98 z_range: None,
99 }
100 }
101}
102
103/// Default palette for gate overlay (green, orange, blue, etc.)
104pub fn default_gate_colors() -> Vec<(u8, u8, u8)> {
105 vec![
106 (34, 139, 34), // forest green
107 (255, 165, 0), // orange
108 (31, 119, 180), // blue
109 (214, 39, 40), // red
110 (148, 103, 189), // purple
111 (140, 86, 75), // brown
112 (227, 119, 194), // pink
113 (127, 127, 127), // gray
114 ]
115}
116
117impl PlotOptions for DensityPlotOptions {
118 fn base(&self) -> &BasePlotOptions {
119 &self.base
120 }
121}
122
123impl DensityPlotOptions {
124 /// Create a new builder for DensityPlotOptions
125 pub fn new() -> DensityPlotOptionsBuilder {
126 DensityPlotOptionsBuilder::default()
127 }
128}