Skip to content

Commit

Permalink
Copy-pasta a LineVisualizerSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
jleibs committed Jan 30, 2024
1 parent eb806e9 commit eb4bac8
Show file tree
Hide file tree
Showing 4 changed files with 484 additions and 27 deletions.
47 changes: 26 additions & 21 deletions crates/re_space_view_time_series/src/legacy_visualizer_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@ use crate::{
pub struct LegacyTimeSeriesSystem {
pub annotation_map: AnnotationMap,
pub lines: Vec<PlotSeries>,

/// Earliest time an entity was recorded at on the current timeline.
pub min_time: Option<i64>,

/// What kind of aggregation was used to compute the graph?
pub aggregator: TimeSeriesAggregator,

/// `1.0` for raw data.
pub aggregation_factor: f64,
}

impl IdentifiedViewSystem for LegacyTimeSeriesSystem {
Expand Down Expand Up @@ -257,15 +248,12 @@ impl LegacyTimeSeriesSystem {
continue;
}

let (aggregation_factor, points) = {
let (aggregator, aggregation_factor, points) = {
let aggregator = data_result
.accumulated_properties()
.time_series_aggregator
.get();

// So it can be displayed in the UI by the SpaceViewClass.
self.aggregator = *aggregator;

let aggregation_factor = plot_value_delta;
let num_points_before = points.len() as f64;

Expand Down Expand Up @@ -308,20 +296,15 @@ impl LegacyTimeSeriesSystem {
actual_aggregation_factor,
);

(actual_aggregation_factor, points)
(aggregator, actual_aggregation_factor, points)
};

// So it can be displayed in the UI by the SpaceViewClass.
self.aggregation_factor = aggregation_factor;

re_tracing::profile_scope!("secondary", &data_result.entity_path.to_string());

let min_time = store
.entity_min_time(&query.timeline, &data_result.entity_path)
.map_or(points.first().map_or(0, |p| p.time), |time| time.as_i64());

self.min_time = Some(self.min_time.map_or(min_time, |time| time.min(min_time)));

// If all points within a line share the label (and it isn't `None`), then we use it
// as the whole line label for the plot legend.
// Otherwise, we just use the entity path as-is.
Expand All @@ -340,9 +323,18 @@ impl LegacyTimeSeriesSystem {
width: 2.0 * points[0].attrs.radius,
kind: PlotSeriesKind::Scatter,
points: vec![(points[0].time, points[0].value)],
aggregator: *aggregator,
aggregation_factor,
min_time,
});
} else {
self.add_line_segments(&line_label, points);
self.add_line_segments(
&line_label,
points,
*aggregator,
aggregation_factor,
min_time,
);
}
}

Expand All @@ -354,7 +346,14 @@ impl LegacyTimeSeriesSystem {
// A line segment is a continuous run of points with identical attributes: each time
// we notice a change in attributes, we need a new line segment.
#[inline(never)] // Better callstacks on crashes
fn add_line_segments(&mut self, line_label: &str, points: Vec<PlotPoint>) {
fn add_line_segments(
&mut self,
line_label: &str,
points: Vec<PlotPoint>,
aggregator: TimeSeriesAggregator,
aggregation_factor: f64,
min_time: i64,
) {
re_tracing::profile_function!();

let num_points = points.len();
Expand All @@ -365,6 +364,9 @@ impl LegacyTimeSeriesSystem {
width: 2.0 * attrs.radius,
points: Vec::with_capacity(num_points),
kind: attrs.kind,
aggregator,
aggregation_factor,
min_time,
};

for (i, p) in points.into_iter().enumerate() {
Expand All @@ -385,6 +387,9 @@ impl LegacyTimeSeriesSystem {
width: 2.0 * attrs.radius,
kind: attrs.kind,
points: Vec::with_capacity(num_points - i),
aggregator,
aggregation_factor,
min_time,
},
);

Expand Down
11 changes: 11 additions & 0 deletions crates/re_space_view_time_series/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
mod aggregation;
mod legacy_visualizer_system;
mod line_visualizer_system;
mod overrides;
mod space_view_class;

use re_viewer_context::external::re_entity_db::TimeSeriesAggregator;
pub use space_view_class::TimeSeriesSpaceView;

/// Computes a deterministic, globally unique ID for the plot based on the ID of the space view
Expand Down Expand Up @@ -69,4 +71,13 @@ pub struct PlotSeries {
pub width: f32,
pub kind: PlotSeriesKind,
pub points: Vec<(i64, f64)>,

/// Earliest time an entity was recorded at on the current timeline.
pub min_time: i64,

/// What kind of aggregation was used to compute the graph?
pub aggregator: TimeSeriesAggregator,

/// `1.0` for raw data.
pub aggregation_factor: f64,
}
Loading

0 comments on commit eb4bac8

Please sign in to comment.