1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use crate::DataContainer;
use egui::{Color32, Frame, Grid, Stroke, Ui};
use polars::prelude::*;
/// Represents file information.
pub struct FileInfo {
/// Number of rows in the dataset.
row_count: usize,
/// Number of columns in the dataset.
col_count: usize,
/// Schema of the dataset. Used for both Parquet and CSV.
schema: SchemaRef,
}
impl FileInfo {
/// Creates `FileInfo` from a `DataContainer`.
pub fn from_container(container: &DataContainer) -> Option<Self> {
let row_count = container.df.height();
let col_count = container.df.width();
let schema = container.df.schema().clone();
Some(FileInfo {
row_count,
col_count,
schema,
})
}
/// Renders the file file_info (row count, column count) to the UI.
pub fn render_metadata(&self, ui: &mut Ui) {
Frame::default()
.stroke(Stroke::new(1.0, Color32::GRAY))
.outer_margin(2.0)
.inner_margin(10.0)
.show(ui, |ui| {
Grid::new("metadata_grid")
.num_columns(2)
.spacing([10.0, 20.0])
.striped(true)
.show(ui, |ui| {
ui.label("Columns:");
ui.label(self.col_count.to_string());
ui.end_row();
ui.label("Rows:");
ui.label(self.row_count.to_string());
ui.end_row();
});
});
}
/// Renders the file schema information to the UI.
/// Each column's name is displayed as a collapsing header,
/// and the column's index and data type are shown within the collapsed section.
/// Adds copy-to-clipboard functionality on right-click of the column name.
pub fn render_schema(&self, ui: &mut Ui) {
// Add a hint to inform the user about copy functionality.
ui.label("Tip: Right-click a column name to copy it to the clipboard.");
for (index, (name, dtype)) in self.schema.iter().enumerate() {
// Create a collapsing header for each column. The header displays the column name.
let header_response = ui.collapsing(name.to_string(), |ui| {
// Inside the collapsing section, display the column index and data type.
ui.label(format!("index: {index}"));
ui.label(format!("type: {dtype}"));
});
// Check if the header was clicked (specifically with the right mouse button).
if header_response
.header_response
.clicked_by(egui::PointerButton::Secondary)
{
// If the right mouse button was clicked, copy the column name to the clipboard.
ui.ctx().copy_text(name.to_string());
}
}
}
}