Skip to main content

ggplot_rs/guide/
config.rs

1/// Configuration for legend guides.
2/// Analogous to R's `guide_legend()` and `guides()`.
3#[derive(Clone, Debug, Default)]
4pub struct GuideLegend {
5    /// Override the legend title. None = use scale name.
6    pub title: Option<String>,
7    /// Number of columns in the legend layout.
8    pub ncol: Option<usize>,
9    /// Number of rows in the legend layout.
10    pub nrow: Option<usize>,
11    /// Reverse the order of legend keys.
12    pub reverse: bool,
13}
14
15impl GuideLegend {
16    pub fn new() -> Self {
17        Self::default()
18    }
19
20    pub fn with_title(mut self, title: &str) -> Self {
21        self.title = Some(title.to_string());
22        self
23    }
24
25    pub fn with_ncol(mut self, ncol: usize) -> Self {
26        self.ncol = Some(ncol);
27        self
28    }
29
30    pub fn with_nrow(mut self, nrow: usize) -> Self {
31        self.nrow = Some(nrow);
32        self
33    }
34
35    pub fn reverse(mut self) -> Self {
36        self.reverse = true;
37        self
38    }
39}