Skip to content

Commit

Permalink
Add the remaining space views and name them consistently (#5498)
Browse files Browse the repository at this point in the history
### What
Just lots of boiler plate with some name changes.

Also split the apy.py file into a few sub-modules because it was getting
large.

All SpaceViews now end in View.
 - Spatial2DView
 - Spatial3DView
 - BarChartView
 - TensorView
 - TextDocumentView
 - TextLogView
 - TimeSeriesView

Testing it out on the plots example:

![image](https://github.com/rerun-io/rerun/assets/3312232/97890949-de50-464e-b640-014f151177b5)


### 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 newly built examples:
[app.rerun.io](https://app.rerun.io/pr/5498/index.html)
* Using examples from latest `main` build:
[app.rerun.io](https://app.rerun.io/pr/5498/index.html?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[app.rerun.io](https://app.rerun.io/pr/5498/index.html?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/5498)
- [Docs
preview](https://rerun.io/preview/bcbce7510db61092c96237a2668518ba564f0227/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/bcbce7510db61092c96237a2668518ba564f0227/examples)
<!--EXAMPLES-PREVIEW-->
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)
  • Loading branch information
jleibs committed Mar 14, 2024
1 parent fad5244 commit d77e025
Show file tree
Hide file tree
Showing 6 changed files with 317 additions and 161 deletions.
6 changes: 3 additions & 3 deletions examples/python/blueprint/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import numpy as np
import rerun as rr # pip install rerun-sdk
from rerun.blueprint.api import Blueprint, BlueprintPanel, Grid, SelectionPanel, Spatial2D, TimePanel, Viewport
from rerun.blueprint import Blueprint, BlueprintPanel, Grid, SelectionPanel, Spatial2DView, TimePanel, Viewport


def main() -> None:
Expand All @@ -28,8 +28,8 @@ def main() -> None:
blueprint = Blueprint(
Viewport(
Grid(
Spatial2D(name="Rect 0", origin="/", contents=["image", "rect/0"]),
Spatial2D(name="Rect 1", origin="/", contents=["image", "rect/1"]),
Spatial2DView(name="Rect 0", origin="/", contents=["image", "rect/0"]),
Spatial2DView(name="Rect 1", origin="/", contents=["image", "rect/1"]),
),
auto_space_views=args.auto_space_views,
),
Expand Down
25 changes: 17 additions & 8 deletions rerun_py/rerun_sdk/rerun/blueprint/__init__.py

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

144 changes: 3 additions & 141 deletions rerun_py/rerun_sdk/rerun/blueprint/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ..recording_stream import RecordingStream
from .archetypes import ContainerBlueprint, PanelBlueprint, SpaceViewBlueprint, SpaceViewContents, ViewportBlueprint
from .components import ColumnShareArrayLike, RowShareArrayLike
from .components.container_kind import ContainerKind, ContainerKindLike
from .components.container_kind import ContainerKindLike

SpaceViewContentsLike = Union[str, Sequence[str], Utf8Like, SpaceViewContents]

Expand Down Expand Up @@ -70,6 +70,8 @@ def blueprint_path(self) -> str:

def to_viewport(self) -> Viewport:
"""Convert this space view to a viewport."""
from .containers import Grid

return Viewport(Grid(self))

def to_blueprint(self) -> Blueprint:
Expand Down Expand Up @@ -112,56 +114,6 @@ def _iter_space_views(self) -> Iterable[bytes]:
return [self.id.bytes]


class Spatial3D(SpaceView):
"""A Spatial 3D space view."""

def __init__(
self, *, origin: EntityPathLike = "/", contents: SpaceViewContentsLike = "/**", name: Utf8Like | None = None
):
"""
Construct a blueprint for a new 3D space view.
Parameters
----------
origin
The `EntityPath` to use as the origin of this space view. All other entities will be transformed
to be displayed relative to this origin.
contents
The contents of the space view. Most commonly specified as a query expression. The individual
sub-expressions must either be newline separate, or provided as a list of strings.
See: [rerun.blueprint.components.QueryExpression][].
name
The name of the space view.
"""
super().__init__(class_identifier="3D", origin=origin, contents=contents, name=name)


class Spatial2D(SpaceView):
"""A Spatial 2D space view."""

def __init__(
self, *, origin: EntityPathLike = "/", contents: SpaceViewContentsLike = "/**", name: Utf8Like | None = None
):
"""
Construct a blueprint for a new 2D space view.
Parameters
----------
origin
The `EntityPath` to use as the origin of this space view. All other entities will be transformed
to be displayed relative to this origin.
contents
The contents of the space view. Most commonly specified as a query expression. The individual
sub-expressions must either be newline separate, or provided as a list of strings.
See: [rerun.blueprint.components.QueryExpression][].
name
The name of the space view.
"""
super().__init__(class_identifier="2D", origin=origin, contents=contents, name=name)


class Container:
"""
Base class for all container types.
Expand Down Expand Up @@ -252,96 +204,6 @@ def _iter_space_views(self) -> Iterable[bytes]:
return itertools.chain.from_iterable(sub._iter_space_views() for sub in self.contents)


class Horizontal(Container):
"""A horizontal container."""

def __init__(self, *contents: Container | SpaceView, column_shares: Optional[ColumnShareArrayLike] = None):
"""
Construct a new horizontal container.
Parameters
----------
*contents:
All positional arguments are the contents of the container, which may be either other containers or space views.
column_shares
The layout shares of the columns in the container. The share is used to determine what fraction of the total width each
column should take up. The column with index `i` will take up the fraction `shares[i] / total_shares`.
"""
super().__init__(*contents, kind=ContainerKind.Horizontal, column_shares=column_shares)


class Vertical(Container):
"""A vertical container."""

def __init__(self, *contents: Container | SpaceView, row_shares: Optional[RowShareArrayLike] = None):
"""
Construct a new vertical container.
Parameters
----------
*contents:
All positional arguments are the contents of the container, which may be either other containers or space views.
row_shares
The layout shares of the rows in the container. The share is used to determine what fraction of the total height each
row should take up. The ros with index `i` will take up the fraction `shares[i] / total_shares`.
"""
super().__init__(*contents, kind=ContainerKind.Vertical, row_shares=row_shares)


class Grid(Container):
"""A grid container."""

def __init__(
self,
*contents: Container | SpaceView,
column_shares: Optional[ColumnShareArrayLike] = None,
row_shares: Optional[RowShareArrayLike] = None,
grid_columns: Optional[int] = None,
):
"""
Construct a new grid container.
Parameters
----------
*contents:
All positional arguments are the contents of the container, which may be either other containers or space views.
column_shares
The layout shares of the columns in the container. The share is used to determine what fraction of the total width each
column should take up. The column with index `i` will take up the fraction `shares[i] / total_shares`.
row_shares
The layout shares of the rows in the container. The share is used to determine what fraction of the total height each
row should take up. The ros with index `i` will take up the fraction `shares[i] / total_shares`.
grid_columns
The number of columns in the grid.
"""
super().__init__(
*contents,
kind=ContainerKind.Grid,
column_shares=column_shares,
row_shares=row_shares,
grid_columns=grid_columns,
)


class Tabs(Container):
"""A tab container."""

def __init__(self, *contents: Container | SpaceView):
"""
Construct a new tab container.
Parameters
----------
*contents:
All positional arguments are the contents of the container, which may be either other containers or space views.
"""
super().__init__(*contents, kind=ContainerKind.Tabs)


class Viewport:
"""
The top-level description of the Viewport.
Expand Down
97 changes: 97 additions & 0 deletions rerun_py/rerun_sdk/rerun/blueprint/containers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
from __future__ import annotations

from typing import Optional

from .api import Container, SpaceView
from .components import ColumnShareArrayLike, RowShareArrayLike
from .components.container_kind import ContainerKind


class Horizontal(Container):
"""A horizontal container."""

def __init__(self, *contents: Container | SpaceView, column_shares: Optional[ColumnShareArrayLike] = None):
"""
Construct a new horizontal container.
Parameters
----------
*contents:
All positional arguments are the contents of the container, which may be either other containers or space views.
column_shares
The layout shares of the columns in the container. The share is used to determine what fraction of the total width each
column should take up. The column with index `i` will take up the fraction `shares[i] / total_shares`.
"""
super().__init__(*contents, kind=ContainerKind.Horizontal, column_shares=column_shares)


class Vertical(Container):
"""A vertical container."""

def __init__(self, *contents: Container | SpaceView, row_shares: Optional[RowShareArrayLike] = None):
"""
Construct a new vertical container.
Parameters
----------
*contents:
All positional arguments are the contents of the container, which may be either other containers or space views.
row_shares
The layout shares of the rows in the container. The share is used to determine what fraction of the total height each
row should take up. The ros with index `i` will take up the fraction `shares[i] / total_shares`.
"""
super().__init__(*contents, kind=ContainerKind.Vertical, row_shares=row_shares)


class Grid(Container):
"""A grid container."""

def __init__(
self,
*contents: Container | SpaceView,
column_shares: Optional[ColumnShareArrayLike] = None,
row_shares: Optional[RowShareArrayLike] = None,
grid_columns: Optional[int] = None,
):
"""
Construct a new grid container.
Parameters
----------
*contents:
All positional arguments are the contents of the container, which may be either other containers or space views.
column_shares
The layout shares of the columns in the container. The share is used to determine what fraction of the total width each
column should take up. The column with index `i` will take up the fraction `shares[i] / total_shares`.
row_shares
The layout shares of the rows in the container. The share is used to determine what fraction of the total height each
row should take up. The ros with index `i` will take up the fraction `shares[i] / total_shares`.
grid_columns
The number of columns in the grid.
"""
super().__init__(
*contents,
kind=ContainerKind.Grid,
column_shares=column_shares,
row_shares=row_shares,
grid_columns=grid_columns,
)


class Tabs(Container):
"""A tab container."""

def __init__(self, *contents: Container | SpaceView):
"""
Construct a new tab container.
Parameters
----------
*contents:
All positional arguments are the contents of the container, which may be either other containers or space views.
"""
super().__init__(*contents, kind=ContainerKind.Tabs)

0 comments on commit d77e025

Please sign in to comment.