Skip to content

Fix inconsistencies in plot highlights #9061

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

Merged
merged 4 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions crates/viewer/re_view_time_series/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ mod point_visualizer_system;
mod util;
mod view_class;

use re_log_types::EntityPath;
use re_types::components::{AggregationPolicy, MarkerShape};
use re_viewer_context::external::re_entity_db::InstancePath;

pub use view_class::TimeSeriesView;

/// Computes a deterministic, globally unique ID for the plot based on the ID of the view
Expand Down Expand Up @@ -83,7 +84,7 @@ pub struct PlotSeries {

pub kind: PlotSeriesKind,
pub points: Vec<(i64, f64)>,
pub entity_path: EntityPath,
pub instance_path: InstancePath,

/// Earliest time an entity was recorded at on the current timeline.
pub min_time: i64,
Expand Down
18 changes: 16 additions & 2 deletions crates/viewer/re_view_time_series/src/line_visualizer_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use re_types::{
Archetype as _, Component, Loggable,
};
use re_view::{clamped_or_nothing, range_with_blueprint_resolved_data};
use re_viewer_context::external::re_entity_db::InstancePath;
use re_viewer_context::{
auto_color_egui, auto_color_for_entity_path, IdentifiedViewSystem, QueryContext,
TypedComponentFallbackProvider, ViewContext, ViewQuery, ViewStateExt as _,
Expand Down Expand Up @@ -534,9 +535,22 @@ impl SeriesLineSystem {
}

debug_assert_eq!(points_per_series.len(), series_names.len());
for (points, label) in points_per_series.into_iter().zip(series_names.into_iter()) {
for (instance, (points, label)) in points_per_series
.into_iter()
.zip(series_names.into_iter())
.enumerate()
{
let instance_path = if num_series == 1 {
InstancePath::entity_all(data_result.entity_path.clone())
} else {
InstancePath::instance(
data_result.entity_path.clone(),
(instance as u64).into(),
)
};

points_to_series(
&data_result.entity_path,
instance_path,
time_per_pixel,
points,
ctx.recording_engine().store(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use re_types::{
};
use re_view::range_with_blueprint_resolved_data;
use re_viewer_context::{
auto_color_for_entity_path, IdentifiedViewSystem, QueryContext, TypedComponentFallbackProvider,
ViewContext, ViewQuery, ViewStateExt as _, ViewSystemExecutionError, VisualizerQueryInfo,
VisualizerSystem,
auto_color_for_entity_path, external::re_entity_db::InstancePath, IdentifiedViewSystem,
QueryContext, TypedComponentFallbackProvider, ViewContext, ViewQuery, ViewStateExt as _,
ViewSystemExecutionError, VisualizerQueryInfo, VisualizerSystem,
};

use crate::{
Expand Down Expand Up @@ -472,7 +472,7 @@ impl SeriesPointSystem {

// Now convert the `PlotPoints` into `Vec<PlotSeries>`
points_to_series(
&data_result.entity_path,
InstancePath::entity_all(data_result.entity_path.clone()),
time_per_pixel,
points,
ctx.recording_engine().store(),
Expand Down
20 changes: 10 additions & 10 deletions crates/viewer/re_view_time_series/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use re_log_types::{EntityPath, ResolvedTimeRange};
use re_log_types::ResolvedTimeRange;
use re_types::{
components::AggregationPolicy,
datatypes::{TimeRange, TimeRangeBoundary},
};
use re_viewer_context::{ViewQuery, ViewerContext};
use re_viewer_context::{external::re_entity_db::InstancePath, ViewQuery, ViewerContext};

use crate::{
aggregation::{AverageAggregator, MinMaxAggregator},
Expand Down Expand Up @@ -82,7 +82,7 @@ pub fn determine_time_range(
// we notice a change in attributes, we need a new series.
#[allow(clippy::too_many_arguments)]
pub fn points_to_series(
entity_path: &EntityPath,
instance_path: InstancePath,
time_per_pixel: f64,
points: Vec<PlotPoint>,
store: &re_chunk_store::ChunkStore,
Expand All @@ -91,14 +91,14 @@ pub fn points_to_series(
aggregator: AggregationPolicy,
all_series: &mut Vec<PlotSeries>,
) {
re_tracing::profile_scope!("secondary", &entity_path.to_string());
re_tracing::profile_scope!("secondary", &instance_path.to_string());
if points.is_empty() {
return;
}

let (aggregation_factor, points) = apply_aggregation(aggregator, time_per_pixel, points, query);
let min_time = store
.entity_min_time(&query.timeline, entity_path)
.entity_min_time(&query.timeline, &instance_path.entity_path)
.map_or(points.first().map_or(0, |p| p.time), |time| time.as_i64());

if points.len() == 1 {
Expand All @@ -114,7 +114,7 @@ pub fn points_to_series(
radius_ui: points[0].attrs.radius_ui,
kind,
points: vec![(points[0].time, points[0].value)],
entity_path: entity_path.clone(),
instance_path,
aggregator,
aggregation_factor,
min_time,
Expand All @@ -123,7 +123,7 @@ pub fn points_to_series(
add_series_runs(
series_label,
points,
entity_path,
instance_path,
aggregator,
aggregation_factor,
min_time,
Expand Down Expand Up @@ -203,7 +203,7 @@ pub fn apply_aggregation(
fn add_series_runs(
series_label: String,
points: Vec<PlotPoint>,
entity_path: &EntityPath,
instance_path: InstancePath,
aggregator: AggregationPolicy,
aggregation_factor: f64,
min_time: i64,
Expand All @@ -219,7 +219,7 @@ fn add_series_runs(
radius_ui: attrs.radius_ui,
points: Vec::with_capacity(num_points),
kind: attrs.kind,
entity_path: entity_path.clone(),
instance_path: instance_path.clone(),
aggregator,
aggregation_factor,
min_time,
Expand All @@ -243,7 +243,7 @@ fn add_series_runs(
radius_ui: attrs.radius_ui,
kind: attrs.kind,
points: Vec::with_capacity(num_points - i),
entity_path: entity_path.clone(),
instance_path: instance_path.clone(),
aggregator,
aggregation_factor,
min_time,
Expand Down
20 changes: 14 additions & 6 deletions crates/viewer/re_view_time_series/src/view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ impl ViewClass for TimeSeriesView {
plot = plot.x_grid_spacer(move |spacer| ns_grid_spacer(canvas_size, &spacer));
}

let mut plot_item_id_to_entity_path = HashMap::default();
let mut plot_item_id_to_instance_path = HashMap::default();

let mut is_resetting = false;

Expand Down Expand Up @@ -465,7 +465,7 @@ impl ViewClass for TimeSeriesView {
state.default_names_for_entities = EntityPath::short_names_with_disambiguation(
all_plot_series
.iter()
.map(|series| series.entity_path.clone()),
.map(|series| series.instance_path.entity_path.clone()),
);

for series in all_plot_series {
Expand All @@ -485,15 +485,22 @@ impl ViewClass for TimeSeriesView {
.collect::<Vec<_>>();

let color = series.color;
let id = egui::Id::new(series.entity_path.hash());
plot_item_id_to_entity_path.insert(id, series.entity_path.clone());
let id = egui::Id::new(series.instance_path.hash());
plot_item_id_to_instance_path.insert(id, series.instance_path.clone());

let interaction_highlight = query
.highlights
.entity_highlight(series.instance_path.entity_path.hash())
.index_highlight(series.instance_path.instance);
let highlight = interaction_highlight.any();

match series.kind {
PlotSeriesKind::Continuous => plot_ui.line(
Line::new(points)
.name(&series.label)
.color(color)
.width(2.0 * series.radius_ui)
.highlight(highlight)
.id(id),
),
PlotSeriesKind::Scatter(scatter_attrs) => plot_ui.points(
Expand All @@ -502,6 +509,7 @@ impl ViewClass for TimeSeriesView {
.color(color)
.radius(series.radius_ui)
.shape(scatter_attrs.marker.into())
.highlight(highlight)
.id(id),
),
// Break up the chart. At some point we might want something fancier.
Expand Down Expand Up @@ -543,9 +551,9 @@ impl ViewClass for TimeSeriesView {
// If we are not resetting on this frame, interact with the plot items (lines, scatters, etc.)
if !is_resetting {
if let Some(hovered) = hovered_plot_item
.and_then(|hovered_plot_item| plot_item_id_to_entity_path.get(&hovered_plot_item))
.and_then(|hovered_plot_item| plot_item_id_to_instance_path.get(&hovered_plot_item))
.map(|entity_path| {
re_viewer_context::Item::DataResult(query.view_id, entity_path.clone().into())
re_viewer_context::Item::DataResult(query.view_id, entity_path.clone())
})
.or_else(|| {
if response.hovered() {
Expand Down
5 changes: 5 additions & 0 deletions crates/viewer/re_viewer_context/src/selection_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ impl InteractionHighlight {
hover: self.hover.max(other.hover),
}
}

/// Returns true if either selection or hover is active.
pub fn any(&self) -> bool {
self.selection != SelectionHighlight::None || self.hover != HoverHighlight::None
}
}

/// An ordered collection of [`Item`] and optional associated context objects.
Expand Down
Loading