Skip to content

Commit a61243e

Browse files
committed
doc: How to create ASCII charts
1 parent 73eba49 commit a61243e

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/data_tree.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ use super::size::Size;
88

99
/// Disk usage data of a filesystem tree.
1010
///
11+
/// **Visualization:** Use the [`Visualizer`](crate::visualizer::Visualizer) struct to create an
12+
/// ASCII chart that visualizes `DataTree`.
13+
///
1114
/// **Serialization and deserialization:** _(feature: `json`)_ `DataTree` does not implement
1215
/// `Serialize` and `Deserialize` traits directly, instead, it can be converted into/from a
1316
/// [`Reflection`] which implements these traits.

src/visualizer.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,30 @@ use super::{data_tree::DataTree, size::Size};
1616
use std::{fmt::Display, num::NonZeroUsize};
1717

1818
/// Visualize a [`DataTree`].
19+
///
20+
/// The fields of the struct are the construction parameters of the ASCII chart.
21+
/// The [`Display`] trait can be used to create the ASCII chart.
22+
///
23+
/// **Example:**
24+
///
25+
/// ```no_run
26+
/// # use parallel_disk_usage::data_tree::DataTree;
27+
/// # use parallel_disk_usage::os_string_display::OsStringDisplay;
28+
/// # use parallel_disk_usage::size::Bytes;
29+
/// # use parallel_disk_usage::bytes_format::BytesFormat;
30+
/// # use parallel_disk_usage::visualizer::{Visualizer, Direction, ColumnWidthDistribution};
31+
/// # fn _wrapper(create_data_tree: fn() -> DataTree<OsStringDisplay, Bytes>) {
32+
/// let data_tree: DataTree<OsStringDisplay, Bytes> = create_data_tree();
33+
/// let visualizer = Visualizer {
34+
/// data_tree: &data_tree,
35+
/// bytes_format: BytesFormat::MetricUnits,
36+
/// direction: Direction::BottomUp,
37+
/// column_width_distribution: ColumnWidthDistribution::total(100),
38+
/// max_depth: std::num::NonZeroUsize::new(10).unwrap(),
39+
/// };
40+
/// println!("{}", visualizer);
41+
/// # }
42+
/// ```
1943
#[derive(Debug)]
2044
pub struct Visualizer<'a, Name, Data>
2145
where

src/visualizer/display.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ where
77
Name: Display,
88
Data: Size + Into<u64>,
99
{
10+
/// Create the ASCII chart.
1011
fn fmt(&self, formatter: &mut Formatter<'_>) -> Result<(), Error> {
1112
let write = |line: &String| writeln!(formatter, "{}", line);
1213
match self.direction {

0 commit comments

Comments
 (0)