Skip to content

Commit

Permalink
WIP: descriminate on entities as well
Browse files Browse the repository at this point in the history
  • Loading branch information
grtlr committed Nov 21, 2024
1 parent 8ebd1d9 commit 4a1282a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
28 changes: 19 additions & 9 deletions crates/viewer/re_space_view_graph/src/ui/state.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use egui::Rect;
use re_chunk::{TimeInt, Timeline};
use re_chunk::{EntityPath, TimeInt, Timeline};
use re_format::format_f32;
use re_types::blueprint::components::VisualBounds2D;
use re_ui::UiExt;
Expand Down Expand Up @@ -63,14 +63,23 @@ impl SpaceViewState for GraphSpaceViewState {

/// Used to determine if a layout is up-to-date or outdated.
#[derive(Debug, PartialEq, Eq)]
pub struct Timestamp {
pub struct Discriminator {
timeline: Timeline,
time: TimeInt,
entities: ahash::HashSet<EntityPath>,
}

impl Timestamp {
pub fn new(timeline: Timeline, time: TimeInt) -> Self {
Self { timeline, time }
impl Discriminator {
pub fn new(
timeline: Timeline,
time: TimeInt,
entities: impl IntoIterator<Item = EntityPath>,
) -> Self {
Self {
timeline,
time,
entities: entities.into_iter().collect(),
}
}
}

Expand All @@ -82,12 +91,12 @@ pub enum LayoutState {
#[default]
None,
InProgress {
timestamp: Timestamp,
timestamp: Discriminator,
layout: Layout,
provider: ForceLayout,
},
Finished {
timestamp: Timestamp,
timestamp: Discriminator,
layout: Layout,
_provider: ForceLayout,
},
Expand Down Expand Up @@ -118,7 +127,7 @@ impl LayoutState {
/// A simple state machine that keeps track of the different stages and if the layout needs to be recomputed.
fn update<'a>(
self,
requested: Timestamp,
requested: Discriminator,
graphs: impl Iterator<Item = &'a Graph<'a>> + Clone,
) -> Self {
match self {
Expand Down Expand Up @@ -172,9 +181,10 @@ impl LayoutState {
&'a mut self,
timeline: Timeline,
time: TimeInt,
entities: impl IntoIterator<Item = EntityPath>,
graphs: impl Iterator<Item = &'a Graph<'a>> + Clone,
) -> &'a mut Layout {
*self = std::mem::take(self).update(Timestamp::new(timeline, time), graphs);
*self = std::mem::take(self).update(Discriminator::new(timeline, time, entities), graphs);

match self {
Self::Finished { layout, .. } | Self::InProgress { layout, .. } => layout,
Expand Down
1 change: 1 addition & 0 deletions crates/viewer/re_space_view_graph/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ Display a graph of nodes and edges.
let layout = state.layout_state.get(
query.timeline,
query.latest_at,
graphs.iter().map(|g| (g.0).clone()),
graphs.iter().map(|(_, graph)| graph),
);
let needs_remeasure = layout.has_zero_size();
Expand Down

0 comments on commit 4a1282a

Please sign in to comment.