Skip to content

Commit

Permalink
Create a more convincing example of the graph view (#8421)
Browse files Browse the repository at this point in the history
### What

This PR tries to create a more convincing example for the graph view.

It consists of 4 views:

* A tree that randomly grows over time
* A bubble chart with new bubbles coming in over time
* The lattice, which is logged statically but without positions
* And finally a Markov-Chain with fixed positions

There are still some minor things to fix:

* [x] That one weird edge in the Markov-Chain
* [x] It would be nice if the viewer would fit the resulting graphs to
the view.

<img width="1775" alt="image"
src="https://github.com/user-attachments/assets/806f7408-9b4d-435b-80da-dacb680a8d93"
/>

<!--
Make sure the PR title and labels are set to maximize their usefulness
for the CHANGELOG,
and our `git log`.

If you have noticed any breaking changes, include them in the migration
guide.

We track various metrics at <https://build.rerun.io>.

For maintainers:
* To run all checks from `main`, comment on the PR with `@rerun-bot
full-check`.
* To deploy documentation changes immediately after merging this PR, add
the `deploy docs` label.
-->

---------

Co-authored-by: Clement Rey <cr.rey.clement@gmail.com>
  • Loading branch information
grtlr and teh-cmc authored Dec 12, 2024
1 parent 7b76958 commit 776aa4f
Show file tree
Hide file tree
Showing 16 changed files with 268 additions and 461 deletions.
9 changes: 0 additions & 9 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2915,15 +2915,6 @@ dependencies = [
"bitflags 2.6.0",
]

[[package]]
name = "graph_binary_tree"
version = "0.21.0-alpha.1+dev"
dependencies = [
"anyhow",
"clap",
"rerun",
]

[[package]]
name = "graph_lattice"
version = "0.21.0-alpha.1+dev"
Expand Down
2 changes: 1 addition & 1 deletion crates/viewer/re_view_graph/src/layout/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl ForceLayoutProvider {
let c1_base = source_pos + delta * 0.25;
let c2_base = source_pos + delta * 0.75;

let base_n = Vec2::new(-c1_base.y, c1_base.x).normalized();
let base_n = Vec2::new(-delta.y, delta.x).normalized();

let c1_left = c1_base + base_n * (fan_amount / 2.);
let c2_left = c2_base + base_n * (fan_amount / 2.);
Expand Down
3 changes: 1 addition & 2 deletions crates/viewer/re_view_graph/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ Display a graph of nodes and edges.

// Perform all layout-related tasks.
let request = LayoutRequest::from_graphs(graphs.iter());
let layout_was_empty = state.layout_state.is_none();
let layout = state.layout_state.get(request, params);

// Prepare the view and the transformations.
Expand Down Expand Up @@ -216,7 +215,7 @@ Display a graph of nodes and edges.
// Update blueprint if changed
let updated_rect_in_scene =
blueprint::components::VisualBounds2D::from(ui_from_world.inverse() * rect_in_ui);
if resp.double_clicked() || layout_was_empty {
if resp.double_clicked() {
bounds_property.reset_blueprint_component::<blueprint::components::VisualBounds2D>(ctx);
state.ui_from_world = None;
} else if rect_in_scene != updated_rect_in_scene {
Expand Down
5 changes: 3 additions & 2 deletions examples/manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ examples = [
"notebook",
"clock",
"dna",
"graphs",
"log_file",
"openstreetmap_data",
"minimal",
Expand All @@ -150,8 +151,6 @@ examples = [
"plots",
"live_scrolling_plot",
"raw_mesh",
"graph_lattice",
"graph_binary_tree",
"air_traffic_data",
]

Expand All @@ -169,6 +168,8 @@ examples = [
"drone_lidar",
"extend_viewer_ui",
"external_data_loader",
"graph_binary_tree",
"graph_lattice",
"incremental_logging",
"minimal_serve",
"shared_recording",
Expand Down
28 changes: 0 additions & 28 deletions examples/python/graph_binary_tree/README.md

This file was deleted.

108 changes: 0 additions & 108 deletions examples/python/graph_binary_tree/graph_binary_tree.py

This file was deleted.

8 changes: 4 additions & 4 deletions examples/python/graph_lattice/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Since no explicit positions are passed for the nodes, Rerun will layout the grap

## Run the code

```bash
pip install -e examples/python/graph_lattice
python -m graph_lattice
```
```bash
pip install -e examples/python/graph_lattice
python -m graph_lattice
```
29 changes: 29 additions & 0 deletions examples/python/graphs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!--[metadata]
title = "Graphs"
tags = ["Graph", "Layout"]
thumbnail = "https://static.rerun.io/graphs/19e6ca2e0752cdc7107c10b0cb79a4b7192d9e0b/480w.png"
thumbnail_dimensions = [480, 399]
channel = "main"
-->

This example shows different attributes that you can associate with nodes in a graph.
Since no explicit positions are passed for the nodes, Rerun will layout the graph automatically.

<picture>
<img src="https://static.rerun.io/graphs/19e6ca2e0752cdc7107c10b0cb79a4b7192d9e0b/full.png" alt="">
<source media="(max-width: 480px)" srcset="https://static.rerun.io/graphs/19e6ca2e0752cdc7107c10b0cb79a4b7192d9e0b/480w.png">
<source media="(max-width: 768px)" srcset="https://static.rerun.io/graphs/19e6ca2e0752cdc7107c10b0cb79a4b7192d9e0b/768w.png">
<source media="(max-width: 1024px)" srcset="https://static.rerun.io/graphs/19e6ca2e0752cdc7107c10b0cb79a4b7192d9e0b/1024w.png">
<source media="(max-width: 1200px)" srcset="https://static.rerun.io/graphs/19e6ca2e0752cdc7107c10b0cb79a4b7192d9e0b/1200w.png">
</picture>

## Used Rerun types
[`GraphNodes`](https://www.rerun.io/docs/reference/types/archetypes/graph_nodes?speculative-link),
[`GraphEdges`](https://www.rerun.io/docs/reference/types/archetypes/graph_edges?speculative-link)

## Run the code

```bash
pip install -e examples/python/graphs
python -m graphs
```
Loading

0 comments on commit 776aa4f

Please sign in to comment.