Skip to content

Commit fd848ee

Browse files
authored
Display array stats when looking at flat layouts (#2835)
Thought I pushed this change into #2833 🤦. Display isn't perfect yet but its a step in the right direction. <img width="1559" alt="Screenshot 2025-03-28 at 17 47 19" src="https://github.com/user-attachments/assets/e5133a64-672b-4c32-a0c6-d1f239955583" />
1 parent 6c1801f commit fd848ee

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

vortex-tui/src/browse/ui/layouts.rs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use humansize::{DECIMAL, format_size, make_format};
1+
use humansize::{DECIMAL, make_format};
22
use ratatui::buffer::Buffer;
3-
use ratatui::layout::{Constraint, Layout, Rect};
3+
use ratatui::layout::{Constraint, Direction, Layout, Rect};
44
use ratatui::style::{Color, Style, Stylize};
55
use ratatui::text::Text;
66
use ratatui::widgets::{
@@ -42,7 +42,8 @@ pub fn render_layouts(app_state: &mut AppState, area: Rect, buf: &mut Buffer) {
4242
fn render_layout_header(cursor: &LayoutCursor, area: Rect, buf: &mut Buffer) {
4343
let layout_kind = cursor.layout().id().to_string();
4444
let row_count = cursor.layout().row_count();
45-
let size = format_size(cursor.total_size(), DECIMAL);
45+
let size_formatter = make_format(DECIMAL);
46+
let size = size_formatter(cursor.total_size());
4647

4748
let mut rows = vec![
4849
Text::from(format!("Kind: {layout_kind}")).bold(),
@@ -56,8 +57,8 @@ fn render_layout_header(cursor: &LayoutCursor, area: Rect, buf: &mut Buffer) {
5657

5758
if cursor.encoding().id() == FLAT_LAYOUT_ID {
5859
rows.push(Text::from(format!(
59-
"FlatBuffer Size: {} bytes",
60-
cursor.flatbuffer_size()
60+
"FlatBuffer Size: {}",
61+
size_formatter(cursor.flatbuffer_size())
6162
)));
6263
}
6364

@@ -162,8 +163,30 @@ fn render_array(app: &AppState, area: Rect, buf: &mut Buffer, is_stats_table: bo
162163
buf,
163164
);
164165
} else {
166+
let header = ["Name", "Value"]
167+
.into_iter()
168+
.map(Cell::from)
169+
.collect::<Row>()
170+
.style(Style::new().bold())
171+
.height(1);
172+
173+
let rows = array.statistics().into_iter().map(|(stat, value)| {
174+
let stat = Cell::from(Text::from(format!("{stat}")));
175+
let value = Cell::from(Text::from(format!("{value}")));
176+
Row::new(vec![stat, value])
177+
});
178+
179+
let layout = Layout::default()
180+
.direction(Direction::Horizontal)
181+
.constraints(vec![Constraint::Percentage(50), Constraint::Percentage(50)])
182+
.split(widget_area);
183+
let table = Table::new(rows, [Constraint::Min(4), Constraint::Min(4)]).header(header);
165184
// Tree-display the active array
166-
Paragraph::new(array.tree_display().to_string()).render(widget_area, buf);
185+
let tree = Paragraph::new(array.tree_display().to_string());
186+
187+
Widget::render(tree, layout[0], buf);
188+
Widget::render(table, layout[1], buf);
189+
167190
// Split view, show information about the child arrays (metadata, count, etc.)
168191
};
169192
}

0 commit comments

Comments
 (0)