diff --git a/src/app.rs b/src/app.rs index f48e9870..58c6ff0f 100644 --- a/src/app.rs +++ b/src/app.rs @@ -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 { @@ -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(), @@ -91,12 +105,15 @@ impl App { fn visualize_json_tree( tree: JsonTree, bytes_format: Self::DisplayFormat, - column_width_distribution: ColumnWidthDistribution, - direction: Direction, - bar_alignment: BarAlignment, + layout: ChartLayout, shaping: JsonInputShaping, ) -> Result { let JsonTree { tree, shared } = tree; + let ChartLayout { + column_width_distribution, + direction, + bar_alignment, + } = layout; let JsonInputShaping { max_depth, min_ratio, @@ -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) }; }