Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ pub struct App {
args: Args,
}

/// Geometry options that control how the chart is laid out.
#[derive(Clone, Copy)]
struct ChartLayout {
/// How the available width is distributed across the columns.
column_width_distribution: ColumnWidthDistribution,
/// Whether the tree grows from the top down or from the bottom up.
direction: Direction,
/// Whether the bars are aligned to the left or to the right.
bar_alignment: BarAlignment,
}

/// Tree-shaping options applied to a deserialized `--json-input` tree before visualization.
#[derive(Clone, Copy)]
struct JsonInputShaping {
Expand Down Expand Up @@ -74,8 +85,11 @@ impl App {
no_sort,
..
} = self.args;
let direction = Direction::from_top_down(top_down);
let bar_alignment = BarAlignment::from_align_right(align_right);
let layout = ChartLayout {
column_width_distribution,
direction: Direction::from_top_down(top_down),
bar_alignment: BarAlignment::from_align_right(align_right),
};
let shaping = JsonInputShaping {
max_depth: max_depth.get(),
min_ratio: min_ratio.into(),
Expand All @@ -91,12 +105,15 @@ impl App {
fn visualize_json_tree(
tree: JsonTree<Self>,
bytes_format: Self::DisplayFormat,
column_width_distribution: ColumnWidthDistribution,
direction: Direction,
bar_alignment: BarAlignment,
layout: ChartLayout,
shaping: JsonInputShaping,
) -> Result<String, RuntimeError> {
let JsonTree { tree, shared } = tree;
let ChartLayout {
column_width_distribution,
direction,
bar_alignment,
} = layout;
let JsonInputShaping {
max_depth,
min_ratio,
Expand Down Expand Up @@ -140,14 +157,7 @@ impl App {

macro_rules! visualize {
($tree:expr, $bytes_format:expr) => {
VisualizeJsonTree::visualize_json_tree(
$tree,
$bytes_format,
column_width_distribution,
direction,
bar_alignment,
shaping,
)
VisualizeJsonTree::visualize_json_tree($tree, $bytes_format, layout, shaping)
};
}

Expand Down
Loading