Skip to content

Commit c3b5261

Browse files
KSXGitHubclaude
andauthored
refactor: extract chart-layout arguments of visualize_json_tree into a struct (#429)
Co-authored-by: Claude <noreply@anthropic.com>
1 parent ef65884 commit c3b5261

1 file changed

Lines changed: 23 additions & 13 deletions

File tree

src/app.rs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ pub struct App {
3030
args: Args,
3131
}
3232

33+
/// Geometry options that control how the chart is laid out.
34+
#[derive(Clone, Copy)]
35+
struct ChartLayout {
36+
/// How the available width is distributed across the columns.
37+
column_width_distribution: ColumnWidthDistribution,
38+
/// Whether the tree grows from the top down or from the bottom up.
39+
direction: Direction,
40+
/// Whether the bars are aligned to the left or to the right.
41+
bar_alignment: BarAlignment,
42+
}
43+
3344
/// Tree-shaping options applied to a deserialized `--json-input` tree before visualization.
3445
#[derive(Clone, Copy)]
3546
struct JsonInputShaping {
@@ -74,8 +85,11 @@ impl App {
7485
no_sort,
7586
..
7687
} = self.args;
77-
let direction = Direction::from_top_down(top_down);
78-
let bar_alignment = BarAlignment::from_align_right(align_right);
88+
let layout = ChartLayout {
89+
column_width_distribution,
90+
direction: Direction::from_top_down(top_down),
91+
bar_alignment: BarAlignment::from_align_right(align_right),
92+
};
7993
let shaping = JsonInputShaping {
8094
max_depth: max_depth.get(),
8195
min_ratio: min_ratio.into(),
@@ -91,12 +105,15 @@ impl App {
91105
fn visualize_json_tree(
92106
tree: JsonTree<Self>,
93107
bytes_format: Self::DisplayFormat,
94-
column_width_distribution: ColumnWidthDistribution,
95-
direction: Direction,
96-
bar_alignment: BarAlignment,
108+
layout: ChartLayout,
97109
shaping: JsonInputShaping,
98110
) -> Result<String, RuntimeError> {
99111
let JsonTree { tree, shared } = tree;
112+
let ChartLayout {
113+
column_width_distribution,
114+
direction,
115+
bar_alignment,
116+
} = layout;
100117
let JsonInputShaping {
101118
max_depth,
102119
min_ratio,
@@ -140,14 +157,7 @@ impl App {
140157

141158
macro_rules! visualize {
142159
($tree:expr, $bytes_format:expr) => {
143-
VisualizeJsonTree::visualize_json_tree(
144-
$tree,
145-
$bytes_format,
146-
column_width_distribution,
147-
direction,
148-
bar_alignment,
149-
shaping,
150-
)
160+
VisualizeJsonTree::visualize_json_tree($tree, $bytes_format, layout, shaping)
151161
};
152162
}
153163

0 commit comments

Comments
 (0)