chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<!--[metadata]
|
||||
title = "Graph lattice"
|
||||
tags = ["Graph", "Layout"]
|
||||
thumbnail = "https://static.rerun.io/graph_lattice/f9169da9c3f35b7260c9d74cd5be5fe710aec6a8/480w.png"
|
||||
thumbnail_dimensions = [480, 269]
|
||||
-->
|
||||
|
||||
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/graph_lattice/f9169da9c3f35b7260c9d74cd5be5fe710aec6a8/full.png" alt="">
|
||||
<source media="(max-width: 480px)" srcset="https://static.rerun.io/graph_lattice/f9169da9c3f35b7260c9d74cd5be5fe710aec6a8/480w.png">
|
||||
<source media="(max-width: 768px)" srcset="https://static.rerun.io/graph_lattice/f9169da9c3f35b7260c9d74cd5be5fe710aec6a8/768w.png">
|
||||
<source media="(max-width: 1024px)" srcset="https://static.rerun.io/graph_lattice/f9169da9c3f35b7260c9d74cd5be5fe710aec6a8/1024w.png">
|
||||
<source media="(max-width: 1200px)" srcset="https://static.rerun.io/graph_lattice/f9169da9c3f35b7260c9d74cd5be5fe710aec6a8/1200w.png">
|
||||
</picture>
|
||||
|
||||
## Used Rerun types
|
||||
[`GraphNodes`](https://www.rerun.io/docs/reference/types/archetypes/graph_nodes),
|
||||
[`GraphEdges`](https://www.rerun.io/docs/reference/types/archetypes/graph_edges)
|
||||
|
||||
## Run the code
|
||||
|
||||
```bash
|
||||
pip install -e examples/python/graph_lattice
|
||||
python -m graph_lattice
|
||||
```
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Examples of logging graph data to Rerun and performing a force-based layout."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import itertools
|
||||
|
||||
import rerun as rr
|
||||
|
||||
NUM_NODES = 10
|
||||
|
||||
DESCRIPTION = """
|
||||
# Graph Lattice
|
||||
This is a minimal example that logs a graph (node-link diagram) that represents a lattice.
|
||||
|
||||
In this example, the node positions — and therefore the graph layout — are computed by Rerun internally.
|
||||
|
||||
The full source code for this example is available
|
||||
[on GitHub](https://github.com/rerun-io/rerun/blob/latest/examples/python/graph_lattice).
|
||||
""".strip()
|
||||
|
||||
|
||||
def log_data() -> None:
|
||||
rr.log("description", rr.TextDocument(DESCRIPTION, media_type=rr.MediaType.MARKDOWN), static=True)
|
||||
|
||||
coordinates = itertools.product(range(NUM_NODES), range(NUM_NODES))
|
||||
|
||||
nodes, colors = zip(
|
||||
*[
|
||||
(
|
||||
str(i),
|
||||
rr.components.Color([round((x / (NUM_NODES - 1)) * 255), round((y / (NUM_NODES - 1)) * 255), 0]),
|
||||
)
|
||||
for i, (x, y) in enumerate(coordinates)
|
||||
],
|
||||
strict=False,
|
||||
)
|
||||
|
||||
rr.log(
|
||||
"/lattice",
|
||||
rr.GraphNodes(
|
||||
nodes,
|
||||
colors=colors,
|
||||
labels=[f"({x}, {y})" for x, y in itertools.product(range(NUM_NODES), range(NUM_NODES))],
|
||||
),
|
||||
static=True,
|
||||
)
|
||||
|
||||
edges = []
|
||||
for x, y in itertools.product(range(NUM_NODES), range(NUM_NODES)):
|
||||
if y > 0:
|
||||
source = (y - 1) * NUM_NODES + x
|
||||
target = y * NUM_NODES + x
|
||||
edges.append((str(source), str(target)))
|
||||
if x > 0:
|
||||
source = y * NUM_NODES + (x - 1)
|
||||
target = y * NUM_NODES + x
|
||||
edges.append((str(source), str(target)))
|
||||
|
||||
rr.log("/lattice", rr.GraphEdges(edges, graph_type="directed"), static=True)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(description="Logs a graph lattice using the Rerun SDK.")
|
||||
rr.script_add_args(parser)
|
||||
args = parser.parse_args()
|
||||
|
||||
rr.script_setup(args, "rerun_example_graph_lattice")
|
||||
log_data()
|
||||
rr.script_teardown(args)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,12 @@
|
||||
[project]
|
||||
name = "graph_lattice"
|
||||
version = "0.1.0"
|
||||
readme = "README.md"
|
||||
dependencies = ["rerun-sdk"]
|
||||
|
||||
[project.scripts]
|
||||
graph_lattice = "graph_lattice:main"
|
||||
|
||||
[build-system]
|
||||
requires = ["hatchling"]
|
||||
build-backend = "hatchling.build"
|
||||
Reference in New Issue
Block a user