Skip to content

Commit 38a760b

Browse files
Wumpfabey79
andauthored
Archetype based overrides & defaults (#9209)
### Related * Fixes #9059 ### What Defaults and overrides can now be set using archetypes. This not only leads to a much more ergonomic API with working auto-complete for archetype fields, but also paves the way for handling tagging in blueprint overrides/defaults which in the future will allow more fine grained defaults/overrides using the archetype "context information". ### Examples Setting default & override for radius Before: ```py rrb.Spatial2DView( name="Rect 1", origin="/", contents=["/**"], defaults=[rr.components.Radius(2)], overrides={"rect/0": [rr.components.Radius(1)]}, ) ``` After: ```py rrb.Spatial2DView( name="Rect 1", origin="/", contents=["/**"], defaults=[rr.Boxes2D.from_fields(radii=1)], overrides={"rect/0": rr.Boxes2D.from_fields(radii=2)}, ) ``` Setting up styles for a plot. Before: ```py rrb.TimeSeriesView( name="Trig", origin="/trig", overrides={ "/trig/sin": [rr.components.Color([255, 0, 0]), rr.components.Name("sin(0.01t)")], "/trig/cos": [rr.components.Color([0, 255, 0]), rr.components.Name("cos(0.01t)")], }, ), rrb.TimeSeriesView( name="Classification", origin="/classification", overrides={ "classification/line": [rr.components.Color([255, 255, 0]), rr.components.StrokeWidth(3.0)], "classification/samples": [rrb.VisualizerOverrides("SeriesPoint")], # This ensures that the `SeriesPoint` visualizers is used for this entity. }, ), ``` After: ```py rrb.TimeSeriesView( name="Trig", origin="/trig", overrides={ "/trig/sin": rr.SeriesLine.from_fields(color=[255, 0, 0], name="sin(0.01t)"), "/trig/cos": rr.SeriesLine.from_fields(color=[0, 255, 0], name="cos(0.01t)"), }, ), rrb.TimeSeriesView( name="Classification", origin="/classification", overrides={ "classification/line": rr.SeriesLine.from_fields(color=[255, 255, 0], width=3.0), "classification/samples": rrb.VisualizerOverrides("SeriesPoint"), # This ensures that the `SeriesPoint` visualizers is used for this entity. }, ), ``` --- ### Technical notes on corner cases There's two special cases that were loose component so far: * `VisualizerOverrides` * the former component becomes an archetype with a list of VisualizerOverride components each being a rerun.datatypes.Utf8. rerun.datatypes.Utf8List which was previously used goes away * `VisualTimeRange` * we _already_ have an archetype for this, it's called `VisualTimeRanges`. There's a bit of an ergonomic issue with this since `VisualTimeRanges` has to be constructed from one or more `VisualTimeRange`. But decided to enforce the archetype here. To avoid accidentally using the component instead of the datatype with the same name, I moved the component out and the datatype in to the rrb namespace --- * [x] go through override/default docs & associated snippets --------- Co-authored-by: Antoine Beyeler <[email protected]>
1 parent bd29230 commit 38a760b

File tree

85 files changed

+1286
-985
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+1286
-985
lines changed

crates/build/re_types_builder/src/codegen/python/views.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ fn init_method(reporter: &Reporter, objects: &Objects, obj: &Object) -> String {
5858
contents: ViewContentsLike = "$origin/**",
5959
name: Utf8Like | None = None,
6060
visible: datatypes.BoolLike | None = None,
61-
defaults: list[Union[AsComponents, ComponentBatchLike]] | None = None,
62-
overrides: dict[EntityPathLike, list[ComponentBatchLike]] | None = None,
61+
defaults: list[AsComponents | Iterable[DescribedComponentBatch]] | None = None,
62+
overrides: dict[EntityPathLike, AsComponents | Iterable[DescribedComponentBatch | AsComponents | Iterable[DescribedComponentBatch]]] | None = None,
6363
"#
6464
.to_owned();
6565

@@ -130,18 +130,24 @@ Defaults to true if not specified."
130130
),
131131
(
132132
"defaults",
133-
"List of default components or component batches to add to the view. When an archetype
134-
in the view is missing a component included in this set, the value of default will be used
135-
instead of the normal fallback for the visualizer.".to_owned(),
133+
"List of archetypes or (described) component batches to add to the view.
134+
When an archetype in the view is missing a component included in this set,
135+
the value of default will be used instead of the normal fallback for the visualizer.
136+
137+
Note that an archetype's required components typically don't have any effect.
138+
It is recommended to use the archetype's `from_fields` method instead and only specify the fields that you need.".to_owned(),
136139
),
137140
(
138141
"overrides",
139142
"Dictionary of overrides to apply to the view. The key is the path to the entity where the override
140-
should be applied. The value is a list of component or component batches to apply to the entity.
143+
should be applied. The value is a list of archetypes or (described) component batches to apply to the entity.
144+
145+
It is recommended to use the archetype's `from_fields` method instead and only specify the fields that you need.
141146
142147
Important note: the path must be a fully qualified entity path starting at the root. The override paths
143148
do not yet support `$origin` relative paths or glob expressions.
144-
This will be addressed in <https://github.com/rerun-io/rerun/issues/6673>.".to_owned(),)
149+
This will be addressed in <https://github.com/rerun-io/rerun/issues/6673>.
150+
".to_owned(),)
145151
];
146152
for field in &obj.fields {
147153
let doc_content = field.docs.lines_for(reporter, objects, Target::Python);

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

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace rerun.blueprint.archetypes;
2+
3+
/// Override the visualizers for an entity.
4+
///
5+
/// This archetype is a stop-gap mechanism based on the current implementation details
6+
/// of the visualizer system. It is not intended to be a long-term solution, but provides
7+
/// enough utility to be useful in the short term.
8+
///
9+
/// The long-term solution is likely to be based off: <https://github.com/rerun-io/rerun/issues/6626>
10+
///
11+
/// This can only be used as part of blueprints. It will have no effect if used
12+
/// in a regular entity.
13+
table VisualizerOverrides (
14+
"attr.rerun.scope": "blueprint",
15+
"attr.python.aliases": "str, Sequence[str]"
16+
) {
17+
/// Names of the visualizers that should be active.
18+
ranges: [rerun.blueprint.components.VisualizerOverride] ("attr.rerun.component_required", order: 1000);
19+
}
Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
11
namespace rerun.blueprint.components;
22

3-
// ---
4-
5-
/// Override the visualizers for an entity.
6-
///
7-
/// This component is a stop-gap mechanism based on the current implementation details
8-
/// of the visualizer system. It is not intended to be a long-term solution, but provides
9-
/// enough utility to be useful in the short term.
10-
///
11-
/// The long-term solution is likely to be based off: <https://github.com/rerun-io/rerun/issues/6626>
3+
/// Single visualizer override the visualizers for an entity.
124
///
13-
/// This can only be used as part of blueprints. It will have no effect if used
14-
/// in a regular entity.
15-
table VisualizerOverrides (
5+
/// For details see [archetypes.VisualizerOverrides].
6+
table VisualizerOverride (
167
"attr.python.aliases": "str, list[str]",
178
"attr.python.array_aliases": "str",
189
"attr.rerun.scope": "blueprint",
1910
"attr.rust.derive": "PartialEq, Eq, PartialOrd, Ord, Default",
2011
"attr.rust.repr": "transparent"
2112
) {
22-
/// Names of the visualizers that should be active.
23-
visualizers: rerun.blueprint.datatypes.Utf8List (order: 100);
13+
/// Names of a visualizer that should be active.
14+
visualizer: rerun.datatypes.Utf8 (order: 100);
2415
}

crates/store/re_types/definitions/rerun/blueprint/datatypes.fbs

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/store/re_types/definitions/rerun/blueprint/datatypes/utf8_list.fbs

Lines changed: 0 additions & 15 deletions
This file was deleted.

crates/store/re_types/definitions/rerun/components/SeriesVisible.fbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
namespace rerun.components;
22

3-
/// Like `Visible`, but for time series.
3+
/// Like [components.Visible], but for time series.
44
///
5-
/// TODO(#6889): This is a temporary workaround. Right now we can't use `Visible` since it would conflict with the entity-wide visibility state.
5+
/// TODO(#6889): This is a temporary workaround. Right now we can't use [components.Visible] since it would conflict with the entity-wide visibility state.
66
struct SeriesVisible (
77
"attr.docs.unreleased", // this component got moved, links changed.
88
"attr.arrow.transparent",

crates/store/re_types/src/blueprint/archetypes/.gitattributes

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/store/re_types/src/blueprint/archetypes/mod.rs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/store/re_types/src/blueprint/archetypes/visualizer_overrides.rs

Lines changed: 196 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/store/re_types/src/blueprint/components/.gitattributes

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/store/re_types/src/blueprint/components/mod.rs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)