Skip to content

Commit

Permalink
Split visible time range component into two for time & sequence using…
Browse files Browse the repository at this point in the history
… the same backing data (#6134)

### What

* Part of [#6083](#6083)

Necessary step on the way towards a `VisibleTimeRange` view property
archetype.

### 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/6134?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/6134?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/6134)
- [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`.
  • Loading branch information
Wumpf authored Apr 26, 2024
1 parent 33ec179 commit 660463d
Show file tree
Hide file tree
Showing 32 changed files with 503 additions and 440 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

70 changes: 30 additions & 40 deletions crates/re_space_view/src/visual_time_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
use re_log_types::TimeRange;
use re_query::{ExtraQueryHistory, VisibleHistory, VisibleHistoryBoundary};
use re_types::blueprint::{
components::VisibleTimeRange,
datatypes::{VisibleTimeRangeBoundary, VisibleTimeRangeBoundaryKind},
use re_types::blueprint::datatypes::{
VisibleTimeRange, VisibleTimeRangeBoundary, VisibleTimeRangeBoundaryKind,
};
use re_viewer_context::ViewerContext;

Expand Down Expand Up @@ -48,19 +47,12 @@ pub fn visible_history_boundary_to_time_range_boundary(

pub fn visible_time_range_to_time_range(
range: &VisibleTimeRange,
time_type: re_log_types::TimeType,
cursor: re_log_types::TimeInt,
) -> re_log_types::TimeRange {
let cursor = cursor.as_i64().into();

let mut min = match time_type {
re_log_types::TimeType::Sequence => range.0.from_sequence.start_boundary_time(cursor),
re_log_types::TimeType::Time => range.0.from_time.start_boundary_time(cursor),
};
let mut max = match time_type {
re_log_types::TimeType::Sequence => range.0.to_sequence.end_boundary_time(cursor),
re_log_types::TimeType::Time => range.0.to_time.end_boundary_time(cursor),
};
let mut min = range.start.start_boundary_time(cursor);
let mut max = range.end.end_boundary_time(cursor);

if min > max {
std::mem::swap(&mut min, &mut max);
Expand All @@ -76,33 +68,31 @@ pub fn query_visual_history(
ctx: &ViewerContext<'_>,
data_result: &re_viewer_context::DataResult,
) -> ExtraQueryHistory {
let visual_time_range_component =
data_result.lookup_override::<re_types::blueprint::components::VisibleTimeRange>(ctx);
if let Some(visual_time_range_component) = visual_time_range_component {
ExtraQueryHistory {
enabled: true,
nanos: VisibleHistory {
from: time_range_boundary_to_visible_history_boundary(
&visual_time_range_component.0.from_time,
),
to: time_range_boundary_to_visible_history_boundary(
&visual_time_range_component.0.to_time,
),
},
sequences: VisibleHistory {
from: time_range_boundary_to_visible_history_boundary(
&visual_time_range_component.0.from_sequence,
),
to: time_range_boundary_to_visible_history_boundary(
&visual_time_range_component.0.to_sequence,
),
},
}
} else {
ExtraQueryHistory {
enabled: false,
nanos: VisibleHistory::default(),
sequences: VisibleHistory::default(),
}
let time_range =
data_result.lookup_override::<re_types::blueprint::components::VisibleTimeRangeTime>(ctx);
let sequence_range = data_result
.lookup_override::<re_types::blueprint::components::VisibleTimeRangeSequence>(ctx);

let mut history = ExtraQueryHistory {
enabled: false,
nanos: Default::default(),
sequences: Default::default(),
};

if let Some(time_range) = time_range {
history.enabled = true;
history.nanos = VisibleHistory {
from: time_range_boundary_to_visible_history_boundary(&time_range.0.start),
to: time_range_boundary_to_visible_history_boundary(&time_range.0.end),
};
}
if let Some(sequence_range) = sequence_range {
history.enabled = true;
history.sequences = VisibleHistory {
from: time_range_boundary_to_visible_history_boundary(&sequence_range.0.start),
to: time_range_boundary_to_visible_history_boundary(&sequence_range.0.end),
};
}

history
}
6 changes: 2 additions & 4 deletions crates/re_space_view_time_series/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ use re_data_store::TimeType;
use re_format::next_grid_tick_magnitude_ns;
use re_log_types::{EntityPath, TimeInt, TimeZone};
use re_space_view::{controls, query_space_view_sub_archetype_or_default};
use re_types::{
blueprint::components::{Corner2D, VisibleTimeRange},
components::Range1D,
};
use re_types::blueprint::datatypes::VisibleTimeRange;
use re_types::{blueprint::components::Corner2D, components::Range1D};
use re_viewer_context::external::re_entity_db::{
EditableAutoValue, EntityProperties, TimeSeriesAggregator,
};
Expand Down
21 changes: 12 additions & 9 deletions crates/re_space_view_time_series/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,18 @@ pub fn determine_time_range(
plot_bounds: Option<egui_plot::PlotBounds>,
enable_query_clamping: bool,
) -> TimeRange {
let visible_time_range_override = data_result
.lookup_override::<re_types::blueprint::components::VisibleTimeRange>(ctx)
.unwrap_or(TimeSeriesSpaceView::DEFAULT_TIME_RANGE);

let mut time_range = visible_time_range_to_time_range(
&visible_time_range_override,
query.timeline.typ(),
query.latest_at,
);
let visible_time_range_override = match query.timeline.typ() {
re_log_types::TimeType::Time => data_result
.lookup_override::<re_types::blueprint::components::VisibleTimeRangeTime>(ctx)
.map(|v| v.0),
re_log_types::TimeType::Sequence => data_result
.lookup_override::<re_types::blueprint::components::VisibleTimeRangeSequence>(ctx)
.map(|v| v.0),
}
.unwrap_or(TimeSeriesSpaceView::DEFAULT_TIME_RANGE);

let mut time_range =
visible_time_range_to_time_range(&visible_time_range_override, query.latest_at);

// TODO(cmc): We would love to reduce the query to match the actual plot bounds, but because
// the plot widget handles zoom after we provide it with data for the current frame,
Expand Down
3 changes: 2 additions & 1 deletion crates/re_types/definitions/rerun/blueprint.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ include "./blueprint/components/space_view_class.fbs";
include "./blueprint/components/space_view_maximized.fbs";
include "./blueprint/components/space_view_origin.fbs";
include "./blueprint/components/viewer_recommendation_hash.fbs";
include "./blueprint/components/visible_time_range.fbs";
include "./blueprint/components/visible_time_range_sequence.fbs";
include "./blueprint/components/visible_time_range_time.fbs";
include "./blueprint/components/visible.fbs";

include "./blueprint/archetypes/background.fbs";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace rerun.blueprint.components;

// ---

/// The range of values that will be included in a space view query.
table VisibleTimeRange (
/// The range of values on time timelines that will be included in a space view query.
table VisibleTimeRangeSequence (
"attr.arrow.transparent",
"attr.rerun.scope": "blueprint",
"attr.rust.repr": "transparent",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
include "arrow/attributes.fbs";
include "python/attributes.fbs";
include "rust/attributes.fbs";

include "rerun/datatypes.fbs";
include "rerun/attributes.fbs";

namespace rerun.blueprint.components;

// ---

/// The range of values on sequence timelines that will be included in a space view query.
table VisibleTimeRangeTime (
"attr.arrow.transparent",
"attr.rerun.scope": "blueprint",
"attr.rust.repr": "transparent",
"attr.rust.derive": "PartialEq, Eq"
) {
value: rerun.blueprint.datatypes.VisibleTimeRange (order: 100);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,17 @@ struct VisibleTimeRangeBoundary (
time: rerun.datatypes.TimeInt (order: 200);
}

/// Visible time range bounds.
/// Visible time range bounds for a timelines.
///
/// This datatype does not specify whether it's a time or sequence based timeline.
struct VisibleTimeRange (
"attr.rerun.scope": "blueprint",
"attr.rust.derive": "PartialEq, Eq"
) {
// TODO(andreas): Split this up into two separate components.

/// Low time boundary for sequence timeline.
from_sequence: rerun.blueprint.datatypes.VisibleTimeRangeBoundary (order: 100);
// Can't call it `from` because it's a reserved keyword in Python.
start: rerun.blueprint.datatypes.VisibleTimeRangeBoundary (order: 100);

/// High time boundary for sequence timeline.
to_sequence: rerun.blueprint.datatypes.VisibleTimeRangeBoundary (order: 200);

/// Low time boundary for time timeline.
from_time: rerun.blueprint.datatypes.VisibleTimeRangeBoundary (order: 300);

/// High time boundary for time timeline.
to_time: rerun.blueprint.datatypes.VisibleTimeRangeBoundary (order: 400);
end: rerun.blueprint.datatypes.VisibleTimeRangeBoundary (order: 200);
}
3 changes: 2 additions & 1 deletion crates/re_types/src/blueprint/components/.gitattributes

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

7 changes: 4 additions & 3 deletions crates/re_types/src/blueprint/components/mod.rs

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

This file was deleted.

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

Loading

0 comments on commit 660463d

Please sign in to comment.