1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
pub mod bar_alignment;
pub mod child_position;
pub mod column_width_distribution;
pub mod direction;
pub mod parenthood;
pub mod proportion_bar;
pub mod tree;

pub use bar_alignment::BarAlignment;
pub use child_position::ChildPosition;
pub use column_width_distribution::ColumnWidthDistribution;
pub use direction::Direction;
pub use parenthood::Parenthood;
pub use proportion_bar::{ProportionBar, ProportionBarBlock};
pub use tree::{TreeHorizontalSlice, TreeSkeletalComponent};

use super::{data_tree::DataTree, size::Size};
use std::{fmt::Display, num::NonZeroUsize};

/// Visualize a [`DataTree`].
///
/// The fields of the struct are the construction parameters of the ASCII chart.
/// The [`Display`] trait can be used to create the ASCII chart.
///
/// **Example:**
///
/// ```no_run
/// # use parallel_disk_usage::data_tree::DataTree;
/// # use parallel_disk_usage::os_string_display::OsStringDisplay;
/// # use parallel_disk_usage::size::Bytes;
/// # use parallel_disk_usage::bytes_format::BytesFormat;
/// # use parallel_disk_usage::visualizer::{Visualizer, Direction, BarAlignment, ColumnWidthDistribution};
/// # fn _wrapper(create_data_tree: fn() -> DataTree<OsStringDisplay, Bytes>) {
/// let data_tree: DataTree<OsStringDisplay, Bytes> = create_data_tree();
/// let visualizer = Visualizer {
///     data_tree: &data_tree,
///     bytes_format: BytesFormat::MetricUnits,
///     direction: Direction::BottomUp,
///     bar_alignment: BarAlignment::Right,
///     column_width_distribution: ColumnWidthDistribution::total(100),
///     max_depth: std::num::NonZeroUsize::new(10).unwrap(),
/// };
/// println!("{}", visualizer);
/// # }
/// ```
#[derive(Debug)]
pub struct Visualizer<'a, Name, Data>
where
    Name: Display,
    Data: Size,
{
    /// The tree to visualize.
    pub data_tree: &'a DataTree<Name, Data>,
    /// Format to be used to [`display`](Size::display) the data.
    pub bytes_format: Data::DisplayFormat,
    /// The direction of the visualization of the tree.
    pub direction: Direction,
    /// The alignment of the bars.
    pub bar_alignment: BarAlignment,
    /// Distribution and total number of characters/blocks can be placed in a line.
    pub column_width_distribution: ColumnWidthDistribution,
    /// Maximum number of levels that should be visualized.
    pub max_depth: NonZeroUsize,
}

mod copy;
mod display;
mod methods;