Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use arrow1 for formatting of arrow data in UI #8592

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6535,7 +6535,6 @@ dependencies = [
"parking_lot",
"rand",
"re_arrow2",
"re_byte_size",
"re_entity_db",
"re_format",
"re_log",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion crates/viewer/re_ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ arrow = ["dep:arrow", "dep:arrow2"]

[dependencies]
re_entity_db.workspace = true # syntax-highlighting for InstancePath. TODO(emilk): move InstancePath
re_byte_size.workspace = true
re_format.workspace = true
re_log.workspace = true
re_log_types.workspace = true # syntax-highlighting for EntityPath
Expand Down
73 changes: 31 additions & 42 deletions crates/viewer/re_ui/src/arrow_ui.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
use arrow2::array::Utf8Array;
use arrow::util::display::{ArrayFormatter, FormatOptions};
use itertools::Itertools as _;

use re_byte_size::SizeBytes as _;

use crate::{UiExt as _, UiLayout};
use crate::UiLayout;

pub fn arrow_ui(ui: &mut egui::Ui, ui_layout: UiLayout, array: &dyn arrow::array::Array) {
arrow2_ui(
ui,
ui_layout,
Box::<dyn arrow2::array::Array>::from(array).as_ref(),
);
}
use arrow::array::{LargeStringArray, StringArray};

pub fn arrow2_ui(ui: &mut egui::Ui, ui_layout: UiLayout, array: &dyn arrow2::array::Array) {
ui.scope(|ui| {
ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Truncate);

Expand All @@ -24,51 +16,44 @@ pub fn arrow2_ui(ui: &mut egui::Ui, ui_layout: UiLayout, array: &dyn arrow2::arr

// Special-treat text.
// Note: we match on the raw data here, so this works for any component containing text.
if let Some(utf8) = array.as_any().downcast_ref::<Utf8Array<i32>>() {
if utf8.len() == 1 {
if let Some(utf8) = array.as_any().downcast_ref::<StringArray>() {
if utf8.values().len() == 1 {
let string = utf8.value(0);
ui_layout.data_label(ui, string);
return;
}
}
if let Some(utf8) = array.as_any().downcast_ref::<Utf8Array<i64>>() {
if utf8.len() == 1 {
if let Some(utf8) = array.as_any().downcast_ref::<LargeStringArray>() {
if utf8.values().len() == 1 {
let string = utf8.value(0);
ui_layout.data_label(ui, string);
return;
}
}

let num_bytes = array.total_size_bytes();
if num_bytes < 3000 {
let num_bytes = array.get_array_memory_size();
if num_bytes < 3_000 {
let instance_count = array.len();
let display = arrow2::array::get_display(array, "null");

if instance_count == 1 {
let mut string = String::new();
match display(&mut string, 0) {
Ok(_) => ui.monospace(&string),
Err(err) => ui.error_with_details_on_hover(err.to_string()),
};
return;
} else {
ui_layout
.label(ui, format!("{instance_count} items"))
.on_hover_ui(|ui| {
ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Wrap);
ui.monospace(format!(
"[{}]",
(0..instance_count)
.filter_map(|index| {
let mut s = String::new();
//TODO(ab): should we care about errors here?
display(&mut s, index).ok().map(|_| s)
})
.join(", ")
));
});
let options = FormatOptions::default();
if let Ok(formatter) = ArrayFormatter::try_new(array, &options) {
if instance_count == 1 {
ui.monospace(formatter.value(0).to_string());
return;
} else {
ui_layout
.label(ui, format!("{instance_count} items"))
.on_hover_ui(|ui| {
ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Wrap);
ui.monospace(format!(
"[{}]",
(0..instance_count)
.map(|index| formatter.value(index).to_string())
.join(", ")
));
});
}
}

return;
}

Expand All @@ -87,3 +72,7 @@ pub fn arrow2_ui(ui: &mut egui::Ui, ui_layout: UiLayout, array: &dyn arrow2::arr
}
});
}

pub fn arrow2_ui(ui: &mut egui::Ui, ui_layout: UiLayout, array: &dyn arrow2::array::Array) {
arrow_ui(ui, ui_layout, &arrow::array::ArrayRef::from(array));
}
4 changes: 2 additions & 2 deletions crates/viewer/re_ui/tests/snapshots/arrow_ui.png
Loading