diff --git a/crates/store/re_types/definitions/rerun/archetypes/graph_nodes.fbs b/crates/store/re_types/definitions/rerun/archetypes/graph_nodes.fbs index 1687fb424f461..e7648d1599d68 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/graph_nodes.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/graph_nodes.fbs @@ -4,8 +4,8 @@ namespace rerun.archetypes; /// A list of nodes in a graph with optional labels, colors, etc. /// -/// \example archetypes/graph_undirected !api title="Simple undirected graph" image="https://static.rerun.io/graph_undirected/15f46bec77452a8c6220558e4403b99cac188e2e/1200w.png" -/// \example archetypes/graph_directed !api title="Simple directed graph" image="https://static.rerun.io/graph_directed/ca29a37b65e1e0b6482251dce401982a0bc568fa/1200w.png" +/// \example archetypes/graph_undirected title="Simple undirected graph" image="https://static.rerun.io/graph_undirected/15f46bec77452a8c6220558e4403b99cac188e2e/1200w.png" +/// \example archetypes/graph_directed title="Simple directed graph" image="https://static.rerun.io/graph_directed/ca29a37b65e1e0b6482251dce401982a0bc568fa/1200w.png" table GraphNodes ( "attr.docs.category": "Graph", "attr.docs.view_types": "GraphView", diff --git a/crates/store/re_types/src/archetypes/graph_nodes.rs b/crates/store/re_types/src/archetypes/graph_nodes.rs index 047fe92708fae..abeb477ca3d4f 100644 --- a/crates/store/re_types/src/archetypes/graph_nodes.rs +++ b/crates/store/re_types/src/archetypes/graph_nodes.rs @@ -19,6 +19,68 @@ use ::re_types_core::{ComponentDescriptor, ComponentName}; use ::re_types_core::{DeserializationError, DeserializationResult}; /// **Archetype**: A list of nodes in a graph with optional labels, colors, etc. +/// +/// ## Examples +/// +/// ### Simple undirected graph +/// ```ignore +/// fn main() -> Result<(), Box> { +/// let rec = rerun::RecordingStreamBuilder::new("rerun_example_graph_undirected").spawn()?; +/// +/// rec.log( +/// "simple", +/// &rerun::GraphNodes::new(["a", "b", "c"]) +/// .with_positions([(0.0, 100.0), (-100.0, 0.0), (100.0, 0.0)]) +/// .with_labels(["A", "B", "C"]), +/// )?; +/// // Note: We log to the same entity here. +/// rec.log( +/// "simple", +/// &rerun::GraphEdges::new([("a", "b"), ("b", "c"), ("c", "a")]).with_undirected_edges(), // Optional: graphs are undirected by default. +/// )?; +/// +/// Ok(()) +/// } +/// ``` +///
+/// +/// +/// +/// +/// +/// +/// +///
+/// +/// ### Simple directed graph +/// ```ignore +/// fn main() -> Result<(), Box> { +/// let rec = rerun::RecordingStreamBuilder::new("rerun_example_graph_directed").spawn()?; +/// +/// rec.log( +/// "simple", +/// &rerun::GraphNodes::new(["a", "b", "c"]) +/// .with_positions([(0.0, 100.0), (-100.0, 0.0), (100.0, 0.0)]) +/// .with_labels(["A", "B", "C"]), +/// )?; +/// // Note: We log to the same entity here. +/// rec.log( +/// "simple", +/// &rerun::GraphEdges::new([("a", "b"), ("b", "c"), ("c", "a")]).with_directed_edges(), +/// )?; +/// +/// Ok(()) +/// } +/// ``` +///
+/// +/// +/// +/// +/// +/// +/// +///
#[derive(Clone, Debug, PartialEq)] pub struct GraphNodes { /// A list of node IDs. diff --git a/rerun_cpp/src/rerun/archetypes/graph_nodes.hpp b/rerun_cpp/src/rerun/archetypes/graph_nodes.hpp index 78f7971447b8b..c3721f81b4183 100644 --- a/rerun_cpp/src/rerun/archetypes/graph_nodes.hpp +++ b/rerun_cpp/src/rerun/archetypes/graph_nodes.hpp @@ -22,6 +22,62 @@ namespace rerun::archetypes { /// **Archetype**: A list of nodes in a graph with optional labels, colors, etc. + /// + /// ## Examples + /// + /// ### Simple undirected graph + /// ![image](https://static.rerun.io/graph_undirected/15f46bec77452a8c6220558e4403b99cac188e2e/full.png) + /// + /// ```cpp + /// #include + /// + /// int main() { + /// const auto rec = rerun::RecordingStream("rerun_example_graph_undirected"); + /// rec.spawn().exit_on_failure(); + /// + /// rec.log( + /// "simple", + /// rerun::GraphNodes({"a", "b", "c"}) + /// .with_positions({{0.0, 100.0}, {-100.0, 0.0}, {100.0, 0.0}}) + /// .with_labels({"A", "B", "C"}) + /// ); + /// + /// // Note: We log to the same entity here. + /// rec.log( + /// "simple", + /// rerun::GraphEdges({{"a", "b"}, {"b", "c"}, {"c", "a"}}) + /// // Optional: graphs are undirected by default. + /// .with_graph_type(rerun::components::GraphType::Undirected) + /// ); + /// } + /// ``` + /// + /// ### Simple directed graph + /// ![image](https://static.rerun.io/graph_directed/ca29a37b65e1e0b6482251dce401982a0bc568fa/full.png) + /// + /// ```cpp + /// #include + /// + /// int main() { + /// const auto rec = rerun::RecordingStream("rerun_example_graph_directed"); + /// rec.spawn().exit_on_failure(); + /// + /// rec.log( + /// "simple", + /// rerun::GraphNodes({"a", "b", "c"}) + /// .with_positions({{0.0, 100.0}, {-100.0, 0.0}, {100.0, 0.0}}) + /// .with_labels({"A", "B", "C"}) + /// ); + /// + /// // Note: We log to the same entity here. + /// rec.log( + /// "simple", + /// rerun::GraphEdges({{"a", "b"}, {"b", "c"}, {"c", "a"}}) + /// // Graphs are undirected by default. + /// .with_graph_type(rerun::components::GraphType::Directed) + /// ); + /// } + /// ``` struct GraphNodes { /// A list of node IDs. Collection node_ids; diff --git a/rerun_py/rerun_sdk/rerun/archetypes/graph_nodes.py b/rerun_py/rerun_sdk/rerun/archetypes/graph_nodes.py index f24600107e4da..e42639c60a518 100644 --- a/rerun_py/rerun_sdk/rerun/archetypes/graph_nodes.py +++ b/rerun_py/rerun_sdk/rerun/archetypes/graph_nodes.py @@ -20,7 +20,66 @@ @define(str=False, repr=False, init=False) class GraphNodes(Archetype): - """**Archetype**: A list of nodes in a graph with optional labels, colors, etc.""" + """ + **Archetype**: A list of nodes in a graph with optional labels, colors, etc. + + Examples + -------- + ### Simple undirected graph: + ```python + import rerun as rr + + rr.init("rerun_example_graph_undirected", spawn=True) + + rr.log( + "simple", + rr.GraphNodes( + node_ids=["a", "b", "c"], positions=[(0.0, 100.0), (-100.0, 0.0), (100.0, 0.0)], labels=["A", "B", "C"] + ), + ) + rr.log( + "simple", + rr.GraphEdges(edges=[("a", "b"), ("b", "c"), ("c", "a")], graph_type="undirected"), + ) + ``` +
+ + + + + + + +
+ + ### Simple directed graph: + ```python + import rerun as rr + + rr.init("rerun_example_graph_directed", spawn=True) + + rr.log( + "simple", + rr.GraphNodes( + node_ids=["a", "b", "c"], positions=[(0.0, 100.0), (-100.0, 0.0), (100.0, 0.0)], labels=["A", "B", "C"] + ), + ) + rr.log( + "simple", + rr.GraphEdges(edges=[("a", "b"), ("b", "c"), ("c", "a")], graph_type="directed"), + ) + ``` +
+ + + + + + + +
+ + """ def __init__( self: Any,