Skip to content

Commit

Permalink
Introduce API for setting view defaults from python (rerun-io#6545)
Browse files Browse the repository at this point in the history
### What
- Resolves: rerun-io#6539
- Builds on top of: rerun-io#6543
(no-merge until that lands)

Just a bit of plumbing to write all the provided defaults to the correct
location in the blueprint.

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested the web demo (if applicable):
* Using examples from latest `main` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/6545?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/6545?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG
* [x] If applicable, add a new check to the [release
checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)!

- [PR Build Summary](https://build.rerun.io/pr/6545)
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)

To run all checks from `main`, comment on the PR with `@rerun-bot
full-check`.
  • Loading branch information
jleibs authored Jun 12, 2024
1 parent b12df49 commit 3010d2f
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 16 deletions.
11 changes: 9 additions & 2 deletions crates/re_types_builder/src/codegen/python/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ from .. import archetypes as blueprint_archetypes
from .. import components as blueprint_components
from ... import datatypes
from ... import components
from ..._baseclasses import AsComponents
from ..._baseclasses import AsComponents, ComponentBatchLike
from ...datatypes import EntityPathLike, Utf8Like
from ..api import SpaceView, SpaceViewContentsLike
",
Expand All @@ -41,6 +41,7 @@ fn init_method(reporter: &Reporter, objects: &Objects, obj: &Object) -> String {
contents: SpaceViewContentsLike = "$origin/**",
name: Utf8Like | None = None,
visible: blueprint_components.VisibleLike | None = None,
defaults: list[Union[AsComponents, ComponentBatchLike]] = [],
"#
.to_owned();

Expand Down Expand Up @@ -109,6 +110,12 @@ See [rerun.blueprint.archetypes.SpaceViewContents][]."
Defaults to true if not specified."
.to_owned(),
),
(
"defaults",
"List of default components or component batches to add to the space view. When an archetype
in the view is missing a component included in this set, the value of default will be used
instead of the normal fallback for the visualizer.".to_owned(),
)
];
for field in &obj.fields {
let doc_content = field.docs.doc_lines_for_untagged_and("py");
Expand Down Expand Up @@ -174,7 +181,7 @@ Defaults to true if not specified."
}
code.push_indented(
1,
&format!(r#"super().__init__(class_identifier="{identifier}", origin=origin, contents=contents, name=name, visible=visible, properties=properties)"#),
&format!(r#"super().__init__(class_identifier="{identifier}", origin=origin, contents=contents, name=name, visible=visible, properties=properties, defaults=defaults)"#),
1,
);

Expand Down
4 changes: 3 additions & 1 deletion examples/python/blueprint/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def main() -> None:
blueprint = Blueprint(
Grid(
Spatial2DView(name="Rect 0", origin="/", contents=["image", "rect/0"]),
Spatial2DView(name="Rect 1", origin="/", contents=["image", "rect/1"]),
Spatial2DView(
name="Rect 1", origin="/", contents=["image", "rect/1"], defaults=[rr.components.Radius(2)]
),
),
BlueprintPanel(state="collapsed"),
SelectionPanel(state="collapsed"),
Expand Down
16 changes: 15 additions & 1 deletion rerun_py/rerun_sdk/rerun/blueprint/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import rerun_bindings as bindings

from .._baseclasses import AsComponents
from .._baseclasses import AsComponents, ComponentBatchLike
from .._spawn import _spawn_viewer
from ..datatypes import EntityPathLike, Utf8ArrayLike, Utf8Like
from ..memory import MemoryRecording
Expand Down Expand Up @@ -44,6 +44,7 @@ def __init__(
name: Utf8Like | None,
visible: VisibleLike | None = None,
properties: dict[str, AsComponents] = {},
defaults: list[Union[AsComponents, ComponentBatchLike]] = [],
):
"""
Construct a blueprint for a new space view.
Expand All @@ -67,6 +68,10 @@ def __init__(
Defaults to true if not specified.
properties
Dictionary of property archetypes to add to space view's internal hierarchy.
defaults:
List of default components or component batches to add to the space view. When an archetype
in the view is missing a component included in this set, the value of default will be used
instead of the normal fallback for the visualizer.
"""
self.id = uuid.uuid4()
Expand All @@ -76,6 +81,7 @@ def __init__(
self.contents = contents
self.visible = visible
self.properties = properties
self.defaults = defaults

def blueprint_path(self) -> str:
"""
Expand Down Expand Up @@ -119,6 +125,14 @@ def _log_to_stream(self, stream: RecordingStream) -> None:
for prop_name, prop in self.properties.items():
stream.log(f"{self.blueprint_path()}/{prop_name}", prop, recording=stream) # type: ignore[attr-defined]

for default in self.defaults:
if hasattr(default, "as_component_batches"):
stream.log(f"{self.blueprint_path()}/defaults", default, recording=stream) # type: ignore[attr-defined]
elif hasattr(default, "component_name"):
stream.log(f"{self.blueprint_path()}/defaults", [default], recording=stream) # type: ignore[attr-defined]
else:
raise ValueError(f"Provided default: {default} is neither a component nor a component batch.")

def _repr_html_(self) -> Any:
"""IPython interface to conversion to html."""
return as_html(blueprint=self)
Expand Down
10 changes: 9 additions & 1 deletion rerun_py/rerun_sdk/rerun/blueprint/views/bar_chart_view.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions rerun_py/rerun_sdk/rerun/blueprint/views/spatial2d_view.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions rerun_py/rerun_sdk/rerun/blueprint/views/spatial3d_view.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion rerun_py/rerun_sdk/rerun/blueprint/views/tensor_view.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion rerun_py/rerun_sdk/rerun/blueprint/views/text_document_view.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion rerun_py/rerun_sdk/rerun/blueprint/views/text_log_view.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions rerun_py/rerun_sdk/rerun/blueprint/views/time_series_view.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3010d2f

Please sign in to comment.