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

Fix setting fallback Position2D and geometry improvements #8505

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions crates/viewer/re_view_graph/src/layout/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,17 @@ impl ForceLayoutProvider {
layout: &Layout,
params: &ForceLayoutParams,
) -> Self {
let nodes = request.all_nodes().map(|(id, v)| {
if let Some(rect) = layout.get_node(&id) {
let pos = rect.center();
fj::Node::from(v).position(pos.x as f64, pos.y as f64)
} else {
fj::Node::from(v)
let nodes = request.all_nodes().map(|(id, template)| {
let node = fj::Node::from(template);

if template.fixed_position.is_none() {
if let Some(rect) = layout.get_node(&id) {
let pos = rect.center();
return node.position(pos.x as f64, pos.y as f64);
}
}

node
});
let radii = request
.all_nodes()
Expand Down Expand Up @@ -207,13 +211,17 @@ impl ForceLayoutProvider {
target: edge.target,
})
.or_default();
geometries.push(EdgeGeometry {
target_arrow,
path: line_segment(
layout.nodes[&edge.source],
layout.nodes[&edge.target],
),
});

let source = layout.nodes[&edge.source];
let target = layout.nodes[&edge.target];

// We only draw edges if they can be displayed meaningfully.
if source.center() != target.center() && !source.intersects(target) {
geometries.push(EdgeGeometry {
target_arrow,
path: line_segment(source, target),
});
}
} else {
// Multiple edges occupy the same space, so we fan them out.
let num_edges = edges.len();
Expand All @@ -222,6 +230,14 @@ impl ForceLayoutProvider {
let source_rect = layout.nodes[slot_source];
let target_rect = layout.nodes[slot_target];

if source_rect.center() == target_rect.center()
|| source_rect.intersects(target_rect)
{
// There is no meaningful geometry to draw here.
// Keep in mind that self-edges are handled separately above.
continue;
}

let d = (target_rect.center() - source_rect.center()).normalized();

let source_pos = source_rect.intersects_ray_from_center(d);
Expand Down
11 changes: 11 additions & 0 deletions tests/python/release_checklist/check_graph_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@
* `graph` has directed edges, while `graph2` has undirected edges.
* `graph` and `graph2` are shown in two different viewers.
* There is a third viewer, `Both`, that shows both `graph` and `graph2` in the same viewer.
* The `coincident` viewer shows two nodes, `A` and `B`, at the same position
"""


def log_readme() -> None:
rr.log("readme", rr.TextDocument(README, media_type=rr.MediaType.MARKDOWN), static=True)


def log_coincident_nodes() -> None:
rr.log("coincident", rr.GraphNodes(["A", "B"], labels=["A", "B"], positions=[[-150, 0], [150, 0]]))


def log_graphs() -> None:
DATA = [
("A", None),
Expand Down Expand Up @@ -51,13 +56,19 @@ def run(args: Namespace) -> None:

log_readme()
log_graphs()
log_coincident_nodes()

rr.send_blueprint(
rrb.Blueprint(
rrb.Grid(
rrb.GraphView(origin="graph", name="Graph 1"),
rrb.GraphView(origin="graph2", name="Graph 2"),
rrb.GraphView(name="Both", contents=["/graph", "/graph2"]),
rrb.GraphView(
origin="coincident",
name="Coincident nodes",
overrides={"coincident": [rr.components.Position2D([0, 0])]},
Copy link
Member

Choose a reason for hiding this comment

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

nice!

),
rrb.TextDocumentView(origin="readme", name="Instructions"),
)
)
Expand Down
Loading