flow_plots/options/
histogram.rs1use crate::options::density::default_gate_colors;
4use crate::options::{AxisOptions, BasePlotOptions, PlotOptions};
5use derive_builder::Builder;
6
7#[derive(Builder, Clone, Debug)]
26#[builder(setter(into, strip_option), default)]
27pub struct HistogramPlotOptions {
28 #[builder(default)]
30 pub base: BasePlotOptions,
31
32 #[builder(default)]
34 pub x_axis: AxisOptions,
35
36 #[builder(default = "true")]
38 pub histogram_filled: bool,
39
40 #[builder(default = "50")]
42 pub num_bins: usize,
43
44 #[builder(default)]
46 pub gate_colors: Vec<(u8, u8, u8)>,
47
48 #[builder(default = "0.0")]
50 pub baseline_separation: f32,
51
52 #[builder(default = "false")]
54 pub scale_to_peak: bool,
55
56 #[builder(default = "2.0")]
58 pub line_width: f64,
59}
60
61impl Default for HistogramPlotOptions {
62 fn default() -> Self {
63 Self {
64 base: BasePlotOptions::default(),
65 x_axis: AxisOptions::default(),
66 histogram_filled: true,
67 num_bins: 50,
68 gate_colors: Vec::new(),
69 baseline_separation: 0.0,
70 scale_to_peak: false,
71 line_width: 2.0,
72 }
73 }
74}
75
76impl PlotOptions for HistogramPlotOptions {
77 fn base(&self) -> &BasePlotOptions {
78 &self.base
79 }
80}
81
82impl HistogramPlotOptions {
83 pub fn new() -> HistogramPlotOptionsBuilder {
85 HistogramPlotOptionsBuilder::default()
86 }
87
88 pub fn gate_color(&self, gate_id: u32) -> (u8, u8, u8) {
90 let colors = if self.gate_colors.is_empty() {
91 default_gate_colors()
92 } else {
93 self.gate_colors.clone()
94 };
95 colors
96 .get(gate_id as usize)
97 .copied()
98 .unwrap_or((60, 60, 60))
99 }
100}