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

Simplify graph viewer rendering logic #8227

Merged
merged 32 commits into from
Nov 29, 2024
Merged

Simplify graph viewer rendering logic #8227

merged 32 commits into from
Nov 29, 2024

Conversation

grtlr
Copy link
Contributor

@grtlr grtlr commented Nov 27, 2024

Related

What

It changes two things:

  1. Instead of using multiple egui::Areas, we now only have a single top-level area.
  2. We compute the sizes of the nodes (information that is important to the layout) in a single preprocessing path instead of the weird frame-to-frame computation that we did before.

Overall this will improve code quality, performance, and will unlock new GraphViz-like layout algorithms (which require defined label size from the beginning) down the road.

@grtlr grtlr changed the title Simplify graph viewer Simplify graph viewer rendering logic Nov 27, 2024
Copy link

github-actions bot commented Nov 27, 2024

Web viewer built successfully. If applicable, you should also test it:

  • I have tested the web viewer
Result Commit Link
95e12e3 https://rerun.io/viewer/pr/8227

Note: This comment is updated whenever you push a commit.

@grtlr grtlr changed the title Simplify graph viewer rendering logic [skip ci] Simplify graph viewer rendering logic Nov 27, 2024
@grtlr grtlr changed the title [skip ci] Simplify graph viewer rendering logic Simplify graph viewer rendering logic Nov 27, 2024
@grtlr grtlr force-pushed the grtlr/simplify-graph-viewer branch from a800af0 to 22b5489 Compare November 27, 2024 11:00
@grtlr grtlr force-pushed the grtlr/simplify-graph-viewer branch from e0adeab to 2a1535c Compare November 27, 2024 13:05
@grtlr grtlr force-pushed the grtlr/simplify-graph-viewer branch from 3034d55 to f50d698 Compare November 28, 2024 08:41
@grtlr grtlr marked this pull request as ready for review November 28, 2024 09:09
@emilk emilk self-requested a review November 28, 2024 11:57
Copy link
Member

@emilk emilk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good cleanup!

crates/viewer/re_space_view_graph/src/graph/index.rs Outdated Show resolved Hide resolved
Comment on lines 19 to 26
Explicit {
id: NodeId,
instance: Instance,
node: ArrowString,
position: Option<Pos2>,
label: DrawableLabel,
},
Implicit {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docstring these! I would not expect a reader to understand what an implicit node is (I don't)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added doc comments, maybe this makes it clearer. Because Node::Implicit only has a very limited subset of information, I chose to introduce the enum at the top level to avoid any confusion. This is also the reason wy I opted against an enum NodeCategory { Explicit, Implicit }.

We could also introduce a mixture of both approaches, but that would introduce another level of indirection, which I think can be avoided by a little redundancy.

crates/viewer/re_space_view_graph/src/graph/mod.rs Outdated Show resolved Hide resolved
Comment on lines 102 to 106
nodes.push(Node::Implicit {
id: edge.source_index,
node: edge.source.0 .0.clone(),
label: DrawableLabel::implicit_circle(),
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would make more sense with a enum NodeCategory { Implicit, Explicit } and struct Node { category: NodeCategory, id: … } ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

crates/viewer/re_space_view_graph/src/graph/mod.rs Outdated Show resolved Hide resolved
crates/viewer/re_space_view_graph/src/layout/result.rs Outdated Show resolved Hide resolved
Comment on lines +15 to +17
// Sorry for the pun, could not resist 😎.
// On a serious note, is there no other way to create a `Sense` that does nothing?
const NON_SENSE: Sense = Sense {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently not… PRs welcome :)
(Puns too)

Copy link
Contributor Author

@grtlr grtlr Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've looked at the code, and apparently hover is equal to setting everything to false:

/// Senses no clicks or drags. Only senses mouse hover.
#[doc(alias = "none")]
#[inline]
pub fn hover() -> Self {
    Self {
        click: false,
        drag: false,
        focusable: false,
    }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the outside (not knowing the implementation details) it's a bit weird that egui does not have a hover: false here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re hover: false: all widgets in egui sense hover, i.e. can have a tooltip

// For now we compute the entity rectangles on the fly.
let mut current_rect = egui::Rect::NOTHING;

for node in graph.nodes() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is becoming both long and deep. Any chance we can break out one of the inner scopes to its own function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try to break it down a bit.

}

/// Helper function to find the point where the line intersects the border of a rectangle
fn find_border_point(rect: Rect, direction: Vec2) -> Pos2 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice with a unit-test for this.

Also: what is the line defined by the direction?

Btw, this is all pretty similar to https://docs.rs/emath/latest/src/emath/rect.rs.html#652-674 - maybe we can lift in the function into emath

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! If you like the code as it is, I'm happy to uptream to emath! I tried to give it a name similar to Rect::intersects_ray.

Copy link
Member

@emilk emilk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@grtlr grtlr added the exclude from changelog PRs with this won't show up in CHANGELOG.md label Nov 29, 2024
@grtlr grtlr merged commit 0e6c186 into main Nov 29, 2024
32 checks passed
@grtlr grtlr deleted the grtlr/simplify-graph-viewer branch November 29, 2024 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exclude from changelog PRs with this won't show up in CHANGELOG.md
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants