flat/dagchart/api.rs
1// We use this in the doc strings.
2#[allow(unused_imports)]
3use super::super::Aggregate;
4// We use this in the doc strings.
5#[allow(unused_imports)]
6use super::super::Render;
7// We use this in the doc strings.
8#[allow(unused_imports)]
9use super::DagChart;
10
11/// Render configuration specific to [`DagChart`]s.
12///
13/// ### Example
14/// ```
15/// # use flat::DagChartConfig;
16/// let dagchart_config = DagChartConfig {
17/// abbreviate: true,
18/// show_aggregate: true,
19/// ..DagChartConfig::default()
20/// };
21/// ```
22#[derive(Debug, Default)]
23pub struct DagChartConfig {
24 /// Whether to abbreviate the dimensional values in the rendering or not.
25 /// Use this option when the dimensions have long [`std::fmt::Display`] forms.
26 /// Abbreviation is attempted irrespective of the `width_hint`.
27 ///
28 /// **Notice**, abbreviation is performed on values only, and not on the column headers.
29 /// Moreover, the abbreviation is bounded by the column header width.
30 /// If you want shorter abbreviations, be sure to shorten the headers as well!
31 ///
32 /// Default: `false`.
33 pub abbreviate: bool,
34 /// Whether to show the aggregated result for the *non-primary* dimension(s) of the dataset.
35 /// Notice, this is different from `show_aggregate` in the root [`Render`] configuration (which shows the *primary* dimension).
36 ///
37 /// The aggregate always represents the matched columns from the *primary* towards the *non-primary*.
38 /// Consequently, the result at each level shows the aggregate across the previous level - that is, the aggregates "cascade".
39 ///
40 /// For example, consider the following `Dataset`.
41 /// ```ignore
42 /// r#"
43 /// A (primary) | B | C | value
44 /// a1 | b1 | c1 | 1
45 /// a1 | b2 | c1 | 2
46 /// a1 | b2 | c2 | 3"#
47 /// ```
48 ///
49 /// Then, the aggregate computation for each level is as follows:
50 /// ```ignore
51 /// r#"
52 /// Dimensional Combinations | Show Aggregate
53 /// (a1,) | aggregate([1, 2, 3])
54 /// (a1, b1) | aggregate([1])
55 /// (a1, b2) | aggregate([2, 3])
56 /// (a1, b1, c1) | aggregate([1])
57 /// (a1, b2, c1) | aggregate([2])
58 /// (a1, b2, c2) | aggregate([3])"#
59 /// ```
60 ///
61 /// In `flat`, the above dataset as [`Aggregate::Sum`] will render as follows:
62 /// ```ignore
63 /// // Output (modified for alignment)
64 /// // Observe the cascade (ex: `b2 [5] = c1 [2] + c2 [3]`).
65 /// r#"
66 /// C Sum B Sum A Sum
67 /// c1 [1] - b1 [1] ┐
68 /// c1 [2] - b2 [5] - a1 [6]
69 /// c2 [3] ┘ ┘"#
70 /// ```
71 ///
72 /// Default: `false`.
73 pub show_aggregate: bool,
74}