|
1 | | -use egui::util::hash; |
| 1 | +use egui::{ahash::HashMap, util::hash}; |
2 | 2 | use re_entity_db::{EditableAutoValue, EntityProperties, LegendCorner}; |
3 | 3 | use re_log_types::EntityPath; |
4 | 4 | use re_space_view::{controls, suggest_space_view_for_each_entity}; |
@@ -132,11 +132,11 @@ impl SpaceViewClass for BarChartSpaceView { |
132 | 132 |
|
133 | 133 | fn ui( |
134 | 134 | &self, |
135 | | - _ctx: &ViewerContext<'_>, |
| 135 | + ctx: &ViewerContext<'_>, |
136 | 136 | ui: &mut egui::Ui, |
137 | 137 | _state: &mut Self::State, |
138 | 138 | root_entity_properties: &EntityProperties, |
139 | | - _query: &ViewQuery<'_>, |
| 139 | + query: &ViewQuery<'_>, |
140 | 140 | system_output: re_viewer_context::SystemExecutionOutput, |
141 | 141 | ) -> Result<(), SpaceViewSystemExecutionError> { |
142 | 142 | use egui_plot::{Bar, BarChart, Legend, Plot}; |
@@ -164,7 +164,13 @@ impl SpaceViewClass for BarChartSpaceView { |
164 | 164 | ); |
165 | 165 | } |
166 | 166 |
|
167 | | - plot.show(ui, |plot_ui| { |
| 167 | + let mut plot_item_id_to_entity_path = HashMap::default(); |
| 168 | + |
| 169 | + let egui_plot::PlotResponse { |
| 170 | + response, |
| 171 | + hovered_plot_item, |
| 172 | + .. |
| 173 | + } = plot.show(ui, |plot_ui| { |
168 | 174 | fn create_bar_chart<N: Into<f64>>( |
169 | 175 | ent_path: &EntityPath, |
170 | 176 | values: impl Iterator<Item = N>, |
@@ -251,9 +257,26 @@ impl SpaceViewClass for BarChartSpaceView { |
251 | 257 | } |
252 | 258 | }; |
253 | 259 |
|
| 260 | + let id = egui::Id::new(ent_path.hash()); |
| 261 | + plot_item_id_to_entity_path.insert(id, ent_path.clone()); |
| 262 | + let chart = chart.id(id); |
| 263 | + |
254 | 264 | plot_ui.bar_chart(chart); |
255 | 265 | } |
256 | 266 | }); |
| 267 | + |
| 268 | + // Interact with the plot items. |
| 269 | + if let Some(entity_path) = hovered_plot_item |
| 270 | + .and_then(|hovered_plot_item| plot_item_id_to_entity_path.get(&hovered_plot_item)) |
| 271 | + { |
| 272 | + ctx.select_hovered_on_click( |
| 273 | + &response, |
| 274 | + re_viewer_context::Item::InstancePath( |
| 275 | + Some(query.space_view_id), |
| 276 | + entity_path.clone().into(), |
| 277 | + ), |
| 278 | + ); |
| 279 | + } |
257 | 280 | }); |
258 | 281 |
|
259 | 282 | Ok(()) |
|
0 commit comments