diff --git a/examples/python/blueprint/main.py b/examples/python/blueprint/main.py index 51fd984dd1a1..401cc955fdfa 100755 --- a/examples/python/blueprint/main.py +++ b/examples/python/blueprint/main.py @@ -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: @@ -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, ), diff --git a/rerun_py/rerun_sdk/rerun/blueprint/__init__.py b/rerun_py/rerun_sdk/rerun/blueprint/__init__.py index 6a5d18c1059d..84a4b7063359 100644 --- a/rerun_py/rerun_sdk/rerun/blueprint/__init__.py +++ b/rerun_py/rerun_sdk/rerun/blueprint/__init__.py @@ -2,6 +2,7 @@ __all__ = [ "archetypes", + "BarChartView", "Blueprint", "BlueprintLike", "BlueprintPanel", @@ -10,10 +11,14 @@ "Grid", "Horizontal", "SelectionPanel", - "Spatial2D", - "Spatial3D", + "Spatial2DView", + "Spatial3DView", "Tabs", + "TensorView", + "TextDocumentView", + "TextLogView", "TimePanel", + "TimeSeriesView", "Vertical", "Viewport", ] @@ -23,13 +28,17 @@ Blueprint, BlueprintLike, BlueprintPanel, - Grid, - Horizontal, SelectionPanel, - Spatial2D, - Spatial3D, - Tabs, TimePanel, - Vertical, Viewport, ) +from .containers import Grid, Horizontal, Vertical +from .space_views import ( + BarChartView, + Spatial2DView, + Spatial3DView, + TensorView, + TextDocumentView, + TextLogView, + TimeSeriesView, +) diff --git a/rerun_py/rerun_sdk/rerun/blueprint/api.py b/rerun_py/rerun_sdk/rerun/blueprint/api.py index 5b76a5ed9621..6bea25e2a582 100644 --- a/rerun_py/rerun_sdk/rerun/blueprint/api.py +++ b/rerun_py/rerun_sdk/rerun/blueprint/api.py @@ -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] @@ -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: @@ -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. @@ -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. diff --git a/rerun_py/rerun_sdk/rerun/blueprint/containers.py b/rerun_py/rerun_sdk/rerun/blueprint/containers.py new file mode 100644 index 000000000000..db47f5a1fdba --- /dev/null +++ b/rerun_py/rerun_sdk/rerun/blueprint/containers.py @@ -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) diff --git a/rerun_py/rerun_sdk/rerun/blueprint/space_views.py b/rerun_py/rerun_sdk/rerun/blueprint/space_views.py new file mode 100644 index 000000000000..80df3a462adf --- /dev/null +++ b/rerun_py/rerun_sdk/rerun/blueprint/space_views.py @@ -0,0 +1,179 @@ +from __future__ import annotations + +from ..datatypes import EntityPathLike, Utf8Like +from .api import SpaceView, SpaceViewContentsLike + + +class BarChartView(SpaceView): + """A bar chart view.""" + + def __init__( + self, *, origin: EntityPathLike = "/", contents: SpaceViewContentsLike = "/**", name: Utf8Like | None = None + ): + """ + Construct a blueprint for a new bar chart view. + + Parameters + ---------- + origin + The `EntityPath` to use as the origin of this view. All other entities will be transformed + to be displayed relative to this origin. + contents + The contents of the 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 view. + + """ + super().__init__(class_identifier="Bar Chart", origin=origin, contents=contents, name=name) + + +class Spatial2DView(SpaceView): + """A Spatial 2D view.""" + + def __init__( + self, *, origin: EntityPathLike = "/", contents: SpaceViewContentsLike = "/**", name: Utf8Like | None = None + ): + """ + Construct a blueprint for a new spatial 2D view. + + Parameters + ---------- + origin + The `EntityPath` to use as the origin of this view. All other entities will be transformed + to be displayed relative to this origin. + contents + The contents of the 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 view. + + """ + super().__init__(class_identifier="2D", origin=origin, contents=contents, name=name) + + +class Spatial3DView(SpaceView): + """A Spatial 3D view.""" + + def __init__( + self, *, origin: EntityPathLike = "/", contents: SpaceViewContentsLike = "/**", name: Utf8Like | None = None + ): + """ + Construct a blueprint for a new spatial 3D view. + + Parameters + ---------- + origin + The `EntityPath` to use as the origin of this view. All other entities will be transformed + to be displayed relative to this origin. + contents + The contents of the 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 view. + + """ + super().__init__(class_identifier="3D", origin=origin, contents=contents, name=name) + + +class TensorView(SpaceView): + """A tensor view.""" + + def __init__( + self, *, origin: EntityPathLike = "/", contents: SpaceViewContentsLike = "/**", name: Utf8Like | None = None + ): + """ + Construct a blueprint for a new tensor view. + + Parameters + ---------- + origin + The `EntityPath` to use as the origin of this view. All other entities will be transformed + to be displayed relative to this origin. + contents + The contents of the 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 view. + + """ + super().__init__(class_identifier="Tensor", origin=origin, contents=contents, name=name) + + +class TextDocumentView(SpaceView): + """A text document view.""" + + def __init__( + self, *, origin: EntityPathLike = "/", contents: SpaceViewContentsLike = "/**", name: Utf8Like | None = None + ): + """ + Construct a blueprint for a new text document view. + + Parameters + ---------- + origin + The `EntityPath` to use as the origin of this view. All other entities will be transformed + to be displayed relative to this origin. + contents + The contents of the 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 view. + + """ + super().__init__(class_identifier="Text Document", origin=origin, contents=contents, name=name) + + +class TextLogView(SpaceView): + """A text log view.""" + + def __init__( + self, *, origin: EntityPathLike = "/", contents: SpaceViewContentsLike = "/**", name: Utf8Like | None = None + ): + """ + Construct a blueprint for a new text log view. + + Parameters + ---------- + origin + The `EntityPath` to use as the origin of this view. All other entities will be transformed + to be displayed relative to this origin. + contents + The contents of the 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 view. + + """ + super().__init__(class_identifier="TextLog", origin=origin, contents=contents, name=name) + + +class TimeSeriesView(SpaceView): + """A time series view.""" + + def __init__( + self, *, origin: EntityPathLike = "/", contents: SpaceViewContentsLike = "/**", name: Utf8Like | None = None + ): + """ + Construct a blueprint for a new time series view. + + Parameters + ---------- + origin + The `EntityPath` to use as the origin of this view. All other entities will be transformed + to be displayed relative to this origin. + contents + The contents of the 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 view. + + """ + super().__init__(class_identifier="Time Series", origin=origin, contents=contents, name=name) diff --git a/tests/python/blueprint/main.py b/tests/python/blueprint/main.py index 3d431a2678f5..73723bea1d9c 100644 --- a/tests/python/blueprint/main.py +++ b/tests/python/blueprint/main.py @@ -2,24 +2,33 @@ import rerun as rr from numpy.random import default_rng -from rerun.blueprint import Blueprint, Grid, Horizontal, Spatial2D, Spatial3D, Tabs, Vertical, Viewport -from rerun.blueprint.api import TimePanel +from rerun.blueprint import ( + Blueprint, + Grid, + Horizontal, + Spatial2DView, + Spatial3DView, + Tabs, + TimePanel, + Vertical, + Viewport, +) if __name__ == "__main__": blueprint = Blueprint( Viewport( Vertical( - Spatial3D(origin="/test1"), + Spatial3DView(origin="/test1"), Horizontal( Tabs( - Spatial3D(origin="/test1"), - Spatial2D(origin="/test2"), + Spatial3DView(origin="/test1"), + Spatial2DView(origin="/test2"), ), Grid( - Spatial3D(origin="/test1"), - Spatial2D(origin="/test2"), - Spatial3D(origin="/test1"), - Spatial2D(origin="/test2"), + Spatial3DView(origin="/test1"), + Spatial2DView(origin="/test2"), + Spatial3DView(origin="/test1"), + Spatial2DView(origin="/test2"), grid_columns=3, column_shares=[1, 1, 1], ),