Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the remaining space views and name them consistently #5498

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading
Loading