Skip to content

Commit 477d97e

Browse files
authored
Improve the blueprint API for the map view (#8027)
### What - Fixes #7903 In passing, I noticed we didn't have an easy way to test view blueprint for equality, e.g. to verify the various way they can be constructed. I've added an `__eq__` implementation on both `SpaceView` and `Container` that ignores the `id` field (which is always unique). - [x] add snippet/screenshot ### 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/8027?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/8027?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)! * [x] If have noted any breaking changes to the log API in `CHANGELOG.md` and the migration guide - [PR Build Summary](https://build.rerun.io/pr/8027) - [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`.
1 parent d25133a commit 477d97e

File tree

9 files changed

+74
-14
lines changed

9 files changed

+74
-14
lines changed

crates/store/re_types/definitions/rerun/blueprint/archetypes/map_background.fbs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ namespace rerun.blueprint.archetypes;
44
/// Configuration for the background map of the map view.
55
table MapBackground (
66
"attr.rerun.scope": "blueprint",
7+
"attr.python.aliases": "blueprint_components.MapProviderLike",
78
"attr.docs.unreleased"
89
) {
910
// --- Optional ---

crates/store/re_types/definitions/rerun/blueprint/archetypes/map_zoom.fbs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace rerun.blueprint.archetypes;
55
//TODO(ab): Turn this archetype into `MapArea` and include a `center: LatLon` componnent or similar
66
table MapZoom (
77
"attr.rerun.scope": "blueprint",
8+
"attr.python.aliases": "datatypes.Float64Like",
89
"attr.docs.unreleased"
910
) {
1011
// --- Optional ---

crates/store/re_types/definitions/rerun/blueprint/views/map.fbs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ namespace rerun.blueprint.views;
22

33
/// A 2D map view to display geospatial primitives.
44
///
5-
/// \example views/map title="Use a blueprint to create a map view."
6-
//TODO(ab): add a screenshot
5+
/// \example views/map title="Use a blueprint to create a map view." image="https://static.rerun.io/map-view/8b2cc15e3f3313e2181667f6c29816ebe75e16e6/1200w.png"
76
table MapView (
87
"attr.rerun.view_identifier": "Map",
98
"attr.docs.unreleased"

docs/content/reference/types/views/map_view.md

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/snippets/all/views/map.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
"""Use a blueprint to show a map."""
1+
"""Use a blueprint to customize a map view."""
22

33
import rerun as rr
44
import rerun.blueprint as rrb
55

66
rr.init("rerun_example_map_view", spawn=True)
77

8-
rr.log("points", rr.GeoPoints(lat_lon=[[47.6344, 19.1397], [47.6334, 19.1399]]))
8+
rr.log("points", rr.GeoPoints(lat_lon=[[47.6344, 19.1397], [47.6334, 19.1399]], radii=rr.Radius.ui_points(20.0)))
99

1010
# Create a map view to display the chart.
11-
# TODO(#7903): cleanup the blueprint API for the map view
1211
blueprint = rrb.Blueprint(
1312
rrb.MapView(
1413
origin="points",
1514
name="MapView",
16-
zoom=rrb.archetypes.MapZoom(16.0),
17-
background=rrb.archetypes.MapBackground(rrb.components.MapProvider.OpenStreetMap),
15+
zoom=16.0,
16+
background=rrb.MapProvider.OpenStreetMap,
1817
),
1918
collapse_panels=True,
2019
)

rerun_py/rerun_sdk/rerun/blueprint/__init__.py

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rerun_py/rerun_sdk/rerun/blueprint/views/map_view.py

+15-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from __future__ import annotations
2+
3+
from typing import Any
4+
5+
import rerun.blueprint as rrb
6+
7+
8+
def assert_blueprint_contents_are_equal(*contents: rrb.SpaceView | rrb.Container) -> None:
9+
"""
10+
Check for equivalence between blueprint contents (views and containers).
11+
12+
This is done by checking equality between all fields, _except_ the `id` field, which is always unique.
13+
"""
14+
15+
def strip_id_field(d: dict[str, Any]) -> dict[str, Any]:
16+
return {k: v for k, v in d.items() if k != "id"}
17+
18+
for i, (c1, c2) in enumerate(zip(contents, contents[1:])):
19+
assert strip_id_field(c1.__dict__) == strip_id_field(c2.__dict__), f"View {i} and {i + 1} are not equal"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from __future__ import annotations
2+
3+
import rerun.blueprint as rrb
4+
5+
from .blueprint_utils import assert_blueprint_contents_are_equal
6+
7+
8+
def test_map_view_blueprint() -> None:
9+
"""Various ways to create a `MapView` blueprint."""
10+
11+
bp1 = rrb.MapView(origin="point", name="MapView", zoom=16, background="openstreetmap")
12+
bp2 = rrb.MapView(origin="point", name="MapView", zoom=rrb.components.ZoomLevel(16), background="openstreetmap")
13+
bp3 = rrb.MapView(
14+
origin="point", name="MapView", zoom=rrb.archetypes.MapZoom(16), background=rrb.MapProvider.OpenStreetMap
15+
)
16+
bp4 = rrb.MapView(
17+
origin="point",
18+
name="MapView",
19+
zoom=rrb.archetypes.MapZoom(rrb.components.ZoomLevel(16)),
20+
background=rrb.archetypes.MapBackground(rrb.MapProvider.OpenStreetMap),
21+
)
22+
23+
# assert bp1 == bp2 == bp3 == bp4
24+
assert_blueprint_contents_are_equal(bp1, bp2, bp3, bp4)

0 commit comments

Comments
 (0)