-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate crate for bar chart space view (#2322)
<!-- Open the PR up as a draft until you feel it is ready for a proper review. Do not make PR:s from your own `main` branch, as that makes it difficult for reviewers to add their own fixes. Add any improvements to the branch as new commits to make it easier for reviewers to follow the progress. All commits will be squashed to a single commit once the PR is merged into `main`. Make sure you mention any issues that this PR closes in the description, as well as any other related issues. To get an auto-generated PR description you can put "copilot:summary" or "copilot:walkthrough" anywhere. --> ### What Moves bar chart into its own crate. Remove some general unused crates. Add generic `ScenePartCollection` impl for single element scenes. ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) <!-- This line will get updated when the PR build summary job finishes. --> PR Build Summary: https://build.rerun.io/pr/2322 <!-- pr-link-docs:start --> Docs preview: https://rerun.io/preview/b42f4f0/docs Examples preview: https://rerun.io/preview/b42f4f0/examples <!-- pr-link-docs:end -->
- Loading branch information
Showing
21 changed files
with
263 additions
and
181 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
[package] | ||
authors.workspace = true | ||
description = "A Space View that shows a single bar chart." | ||
edition.workspace = true | ||
homepage.workspace = true | ||
license.workspace = true | ||
name = "re_space_view_bar_chart" | ||
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_components.workspace = true | ||
re_data_store.workspace = true | ||
re_log_types.workspace = true | ||
re_log.workspace = true | ||
re_renderer.workspace = true | ||
re_space_view.workspace = true | ||
re_tracing.workspace = true | ||
re_ui.workspace = true | ||
re_viewer_context.workspace = true | ||
|
||
egui.workspace = true | ||
vec1.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# re_space_view_bar_chart | ||
|
||
Part of the [`rerun`](https://github.com/rerun-io/rerun) family of crates. | ||
|
||
[![Latest version](https://img.shields.io/crates/v/re_space_view_bar_chart.svg)](https://crates.io/crates/re_space_view_bar_chart) | ||
[![Documentation](https://docs.rs/re_space_view_bar_chart/badge.svg)](https://docs.rs/re_space_view_bar_chart) | ||
![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 a single bar chart. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
//! Rerun bar chart Space View. | ||
//! | ||
//! A Space View that shows a single bar chart. | ||
mod scene_part; | ||
mod space_view_class; | ||
|
||
pub use space_view_class::BarChartSpaceView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
use egui::util::hash; | ||
use re_components::TensorData; | ||
use re_log_types::EntityPath; | ||
use re_space_view::{controls, EmptySpaceViewState}; | ||
use re_viewer_context::{ | ||
auto_color, SpaceViewClass, SpaceViewClassName, SpaceViewId, TypedScene, ViewerContext, | ||
}; | ||
|
||
use super::scene_part::SceneBarChart; | ||
|
||
#[derive(Default)] | ||
pub struct BarChartSpaceView; | ||
|
||
impl SpaceViewClass for BarChartSpaceView { | ||
type State = EmptySpaceViewState; | ||
type Context = re_space_view::EmptySceneContext; | ||
type SceneParts = SceneBarChart; | ||
type ScenePartData = (); | ||
|
||
fn name(&self) -> SpaceViewClassName { | ||
"Bar Chart".into() | ||
} | ||
|
||
fn icon(&self) -> &'static re_ui::Icon { | ||
&re_ui::icons::SPACE_VIEW_HISTOGRAM | ||
} | ||
|
||
fn help_text(&self, re_ui: &re_ui::ReUi, _state: &Self::State) -> egui::WidgetText { | ||
let mut layout = re_ui::LayoutJobBuilder::new(re_ui); | ||
|
||
layout.add("Pan by dragging, or scroll (+ "); | ||
layout.add(controls::HORIZONTAL_SCROLL_MODIFIER); | ||
layout.add(" for horizontal).\n"); | ||
|
||
layout.add("Zoom with pinch gesture or scroll + "); | ||
layout.add(controls::ZOOM_SCROLL_MODIFIER); | ||
layout.add(".\n"); | ||
|
||
layout.add("Drag "); | ||
layout.add(controls::SELECTION_RECT_ZOOM_BUTTON); | ||
layout.add(" to zoom in/out using a selection.\n\n"); | ||
|
||
layout.add_button_text("double-click"); | ||
layout.add(" to reset the view."); | ||
|
||
layout.layout_job.into() | ||
} | ||
|
||
fn preferred_tile_aspect_ratio(&self, _state: &Self::State) -> Option<f32> { | ||
None | ||
} | ||
|
||
fn selection_ui( | ||
&self, | ||
_ctx: &mut ViewerContext<'_>, | ||
_ui: &mut egui::Ui, | ||
_state: &mut Self::State, | ||
_space_origin: &EntityPath, | ||
_space_view_id: SpaceViewId, | ||
) { | ||
} | ||
|
||
fn ui( | ||
&self, | ||
_ctx: &mut ViewerContext<'_>, | ||
ui: &mut egui::Ui, | ||
_state: &mut Self::State, | ||
scene: &mut TypedScene<Self>, | ||
_space_origin: &EntityPath, | ||
_space_view_id: SpaceViewId, | ||
) { | ||
use egui::plot::{Bar, BarChart, Legend, Plot}; | ||
|
||
ui.scope(|ui| { | ||
Plot::new("bar_chart_plot") | ||
.legend(Legend::default()) | ||
.clamp_grid(true) | ||
.show(ui, |plot_ui| { | ||
fn create_bar_chart<N: Into<f64>>( | ||
ent_path: &EntityPath, | ||
values: impl Iterator<Item = N>, | ||
) -> BarChart { | ||
let color = auto_color(hash(ent_path) as _); | ||
let fill = color.gamma_multiply(0.75).additive(); // make sure overlapping bars are obvious | ||
BarChart::new( | ||
values | ||
.enumerate() | ||
.map(|(i, value)| { | ||
Bar::new(i as f64 + 0.5, value.into()) | ||
.width(0.95) | ||
.name(format!("{ent_path} #{i}")) | ||
.fill(fill) | ||
.stroke(egui::Stroke::NONE) | ||
}) | ||
.collect(), | ||
) | ||
.name(ent_path.to_string()) | ||
.color(color) | ||
} | ||
|
||
for (ent_path, tensor) in &scene.parts.charts { | ||
let chart = match &tensor.data { | ||
TensorData::U8(data) => { | ||
create_bar_chart(ent_path, data.iter().copied()) | ||
} | ||
TensorData::U16(data) => { | ||
create_bar_chart(ent_path, data.iter().copied()) | ||
} | ||
TensorData::U32(data) => { | ||
create_bar_chart(ent_path, data.iter().copied()) | ||
} | ||
TensorData::U64(data) => { | ||
create_bar_chart(ent_path, data.iter().copied().map(|v| v as f64)) | ||
} | ||
TensorData::I8(data) => { | ||
create_bar_chart(ent_path, data.iter().copied()) | ||
} | ||
TensorData::I16(data) => { | ||
create_bar_chart(ent_path, data.iter().copied()) | ||
} | ||
TensorData::I32(data) => { | ||
create_bar_chart(ent_path, data.iter().copied()) | ||
} | ||
TensorData::I64(data) => { | ||
create_bar_chart(ent_path, data.iter().copied().map(|v| v as f64)) | ||
} | ||
TensorData::F16(data) => { | ||
create_bar_chart(ent_path, data.iter().map(|f| f.to_f32())) | ||
} | ||
TensorData::F32(data) => { | ||
create_bar_chart(ent_path, data.iter().copied()) | ||
} | ||
TensorData::F64(data) => { | ||
create_bar_chart(ent_path, data.iter().copied()) | ||
} | ||
TensorData::JPEG(_) => { | ||
re_log::warn_once!( | ||
"trying to display JPEG data as a bar chart ({:?})", | ||
ent_path | ||
); | ||
continue; | ||
} | ||
}; | ||
|
||
plot_ui.bar_chart(chart); | ||
} | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
56437db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible performance regression was detected for benchmark 'Rust Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
1.25
.batch_points_arrow/encode_log_msg
126176
ns/iter (± 724
)92390
ns/iter (± 1005
)1.37
batch_points_arrow/decode_log_msg
85988
ns/iter (± 258
)68497
ns/iter (± 527
)1.26
arrow_batch_vecs/insert
35971
ns/iter (± 83
)27367
ns/iter (± 327
)1.31
This comment was automatically generated by workflow using github-action-benchmark.