Skip to content

Commit

Permalink
Initial draft for DataSpaceView
Browse files Browse the repository at this point in the history
  • Loading branch information
abey79 committed Dec 11, 2023
1 parent a6a8db1 commit 08923a8
Show file tree
Hide file tree
Showing 9 changed files with 305 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ re_sdk_comms = { path = "crates/re_sdk_comms", version = "=0.12.0-alpha.1", defa
re_smart_channel = { path = "crates/re_smart_channel", version = "=0.12.0-alpha.1", default-features = false }
re_space_view = { path = "crates/re_space_view", version = "=0.12.0-alpha.1", default-features = false }
re_space_view_bar_chart = { path = "crates/re_space_view_bar_chart", version = "=0.12.0-alpha.1", default-features = false }
re_space_view_data = { path = "crates/re_space_view_data", version = "=0.12.0-alpha.1", default-features = false }
re_space_view_spatial = { path = "crates/re_space_view_spatial", version = "=0.12.0-alpha.1", default-features = false }
re_space_view_tensor = { path = "crates/re_space_view_tensor", version = "=0.12.0-alpha.1", default-features = false }
re_space_view_text_log = { path = "crates/re_space_view_text_log", version = "=0.12.0-alpha.1", default-features = false }
Expand Down
33 changes: 33 additions & 0 deletions crates/re_space_view_data/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[package]
authors.workspace = true
description = "A Space View that shows the data contained in entities in a table."
edition.workspace = true
homepage.workspace = true
license.workspace = true
name = "re_space_view_data"
publish = true
readme = "README.md"
repository.workspace = true
rust-version.workspace = true
version.workspace = true
include = ["../../LICENSE-APACHE", "../../LICENSE-MIT", "**/*.rs", "Cargo.toml"]

[package.metadata.docs.rs]
all-features = true

[dependencies]
re_arrow_store.workspace = true
re_data_store.workspace = true
re_data_ui.workspace = true
re_log.workspace = true
re_log_types.workspace = true
re_query.workspace = true
re_renderer.workspace = true
re_tracing.workspace = true
re_types.workspace = true
re_ui.workspace = true
re_viewer_context.workspace = true

egui_extras.workspace = true
egui.workspace = true
itertools.workspace = true
10 changes: 10 additions & 0 deletions crates/re_space_view_data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# re_space_view_data

Part of the [`rerun`](https://github.com/rerun-io/rerun) family of crates.

[![Latest version](https://img.shields.io/crates/v/re_space_view_data.svg)](https://crates.io/crates/re_space_view_data)
[![Documentation](https://docs.rs/re_space_view_data/badge.svg)](https://docs.rs/re_space_view_data)
![MIT](https://img.shields.io/badge/license-MIT-blue.svg)
![Apache](https://img.shields.io/badge/license-Apache-blue.svg)

A Space View that shows the data contained in entities in a table.
8 changes: 8 additions & 0 deletions crates/re_space_view_data/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//! Rerun `Data` Space View
//!
//! A Space View that shows the data contained in entities in a table.
mod space_view_class;
mod view_part_system;

pub use space_view_class::DataSpaceView;
192 changes: 192 additions & 0 deletions crates/re_space_view_data/src/space_view_class.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
use crate::view_part_system::EmptySystem;
use egui_extras::Column;
use itertools::Itertools;
use re_data_store::{EntityProperties, InstancePath};
use re_log_types::EntityPath;
use re_query::get_component_with_instances;
use re_viewer_context::{
AutoSpawnHeuristic, PerSystemEntities, SpaceViewClass, SpaceViewClassRegistryError,
SpaceViewId, SpaceViewSystemExecutionError, UiVerbosity, ViewContextCollection,
ViewPartCollection, ViewQuery, ViewerContext,
};

#[derive(Default)]
pub struct DataSpaceView;

impl SpaceViewClass for DataSpaceView {
type State = ();

const IDENTIFIER: &'static str = "Data";
const DISPLAY_NAME: &'static str = "Data";

fn icon(&self) -> &'static re_ui::Icon {
//TODO(ab): fix that icon
&re_ui::icons::SPACE_VIEW_TEXTBOX
}

fn help_text(&self, _re_ui: &re_ui::ReUi) -> egui::WidgetText {
"Show the data contained in entities in a table.".into()
}

fn on_register(
&self,
system_registry: &mut re_viewer_context::SpaceViewSystemRegistry,
) -> Result<(), SpaceViewClassRegistryError> {
system_registry.register_part_system::<EmptySystem>()
}

fn preferred_tile_aspect_ratio(&self, _state: &Self::State) -> Option<f32> {
None
}

fn layout_priority(&self) -> re_viewer_context::SpaceViewClassLayoutPriority {
re_viewer_context::SpaceViewClassLayoutPriority::Low
}

fn auto_spawn_heuristic(
&self,
_ctx: &ViewerContext<'_>,
_space_origin: &EntityPath,
_ent_paths: &PerSystemEntities,
) -> re_viewer_context::AutoSpawnHeuristic {
AutoSpawnHeuristic::NeverSpawn
}

fn selection_ui(
&self,
_ctx: &ViewerContext<'_>,
_ui: &mut egui::Ui,
_state: &mut Self::State,
_space_origin: &EntityPath,
_space_view_id: SpaceViewId,
_root_entity_properties: &mut EntityProperties,
) {
}

fn ui(
&self,
ctx: &ViewerContext<'_>,
ui: &mut egui::Ui,
_state: &mut Self::State,
_root_entity_properties: &EntityProperties,
_view_ctx: &ViewContextCollection,
_parts: &ViewPartCollection,
query: &ViewQuery<'_>,
_draw_data: Vec<re_renderer::QueueableDrawData>,
) -> Result<(), SpaceViewSystemExecutionError> {
re_tracing::profile_function!();

let entities: Vec<_> = query
.iter_all_data_results()
.filter(|data_result| data_result.resolved_properties.visible)
.map(|data_result| &data_result.entity_path)
.unique()
.cloned()
.collect();

let store = ctx.store_db.store();
let latest_at_query = query.latest_at_query();

// for each entity, this does the union of all instance keys of all components
let all_instances: Vec<_> = entities
.iter()
.flat_map(|entity| {
store
.all_components(&query.timeline, entity)
.unwrap_or_default()
.into_iter()
.filter(|comp| !comp.is_indicator_component())
.flat_map(|comp| {
get_component_with_instances(store, &latest_at_query, entity, comp)
.map(|(_, comp_inst)| comp_inst.instance_keys())
.unwrap_or_default()
})
.filter(|instance_key| !instance_key.is_splat())
.map(|instance_key| InstancePath::instance(entity.clone(), instance_key))
})
.unique()
.collect();

let all_components: Vec<_> = entities
.iter()
.flat_map(|entity| {
store
.all_components(&query.timeline, entity)
.unwrap_or_default()
})
.unique()
.filter(|comp| !comp.is_indicator_component())
.collect();

egui::ScrollArea::both()
.auto_shrink([false, false])
.show(ui, |ui| {
egui::Frame {
inner_margin: egui::Margin::same(5.0),
..Default::default()
}
.show(ui, |ui| {
egui_extras::TableBuilder::new(ui)
.columns(
Column::auto_with_initial_suggestion(200.0),
all_components.len() + 1,
)
.resizable(true)
.vscroll(false)
.auto_shrink([false, true])
.striped(true)
.header(re_ui::ReUi::table_line_height(), |mut row| {
row.col(|ui| {
ui.strong("Entity");
});

for comp in &all_components {
row.col(|ui| {
ui.strong(comp.short_name());
});
}
})
.body(|body| {
body.rows(
re_ui::ReUi::table_line_height(),
all_instances.len(),
|idx, mut row| {
let instance = &all_instances[idx];

row.col(|ui| {
ui.label(format!("{instance}"));
});

for comp in &all_components {
row.col(|ui| {
if let Some((_, comp_inst)) =
get_component_with_instances(
store,
&latest_at_query,
&instance.entity_path,
*comp,
)
{
ctx.component_ui_registry.ui(
ctx,
ui,
UiVerbosity::Small,
&latest_at_query,
&instance.entity_path,
&comp_inst,
&instance.instance_key,
);
} else {
ui.weak("-");
}
});
}
},
);
});
});
});

Ok(())
}
}
38 changes: 38 additions & 0 deletions crates/re_space_view_data/src/view_part_system.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use re_types::ComponentNameSet;
use re_viewer_context::{
IdentifiedViewSystem, SpaceViewSystemExecutionError, ViewContextCollection, ViewPartSystem,
ViewQuery, ViewerContext,
};

/// An empty system to accept all entities in the space view
#[derive(Default)]
pub struct EmptySystem {}

impl IdentifiedViewSystem for EmptySystem {
fn identifier() -> re_viewer_context::ViewSystemIdentifier {
"Empty".into()
}
}

impl ViewPartSystem for EmptySystem {
fn required_components(&self) -> ComponentNameSet {
std::iter::empty().collect()
}

fn indicator_components(&self) -> ComponentNameSet {
std::iter::empty().collect()
}

fn execute(
&mut self,
_ctx: &ViewerContext<'_>,
_query: &ViewQuery<'_>,
_view_ctx: &ViewContextCollection,
) -> Result<Vec<re_renderer::QueueableDrawData>, SpaceViewSystemExecutionError> {
Ok(vec![])
}

fn as_any(&self) -> &dyn std::any::Any {
self
}
}
1 change: 1 addition & 0 deletions crates/re_viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ re_renderer = { workspace = true, default-features = false }
re_smart_channel.workspace = true
re_space_view.workspace = true
re_space_view_bar_chart.workspace = true
re_space_view_data.workspace = true
re_space_view_spatial.workspace = true
re_space_view_tensor.workspace = true
re_space_view_text_document = { workspace = true, features = ["markdown"] }
Expand Down
1 change: 1 addition & 0 deletions crates/re_viewer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,7 @@ fn populate_space_view_class_registry_with_builtin(
) -> Result<(), SpaceViewClassRegistryError> {
re_tracing::profile_function!();
space_view_class_registry.add_class::<re_space_view_bar_chart::BarChartSpaceView>()?;
space_view_class_registry.add_class::<re_space_view_data::DataSpaceView>()?;
space_view_class_registry.add_class::<re_space_view_spatial::SpatialSpaceView2D>()?;
space_view_class_registry.add_class::<re_space_view_spatial::SpatialSpaceView3D>()?;
space_view_class_registry.add_class::<re_space_view_tensor::TensorSpaceView>()?;
Expand Down

0 comments on commit 08923a8

Please sign in to comment.