Skip to content

Commit

Permalink
Allow dragging time cursor in plots (#2115)
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk authored May 17, 2023
1 parent 30e7d63 commit d49a8d6
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions crates/re_viewer/src/ui/view_time_series/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub(crate) fn view_time_series(
let egui::plot::PlotResponse {
inner: time_x,
response,
transform: _,
transform,
} = plot.show(ui, |plot_ui| {
if plot_ui.plot_secondary_clicked() {
let timeline = ctx.rec_cfg.time_ctrl.timeline();
Expand Down Expand Up @@ -154,8 +154,33 @@ pub(crate) fn view_time_series(
});

if let Some(time_x) = time_x {
// TODO(emilk): allow interacting with the timeline (may require `egui::Plot` to return the `plot_from_screen` transform)
let stroke = ui.visuals().widgets.inactive.fg_stroke;
let interact_radius = ui.style().interaction.resize_grab_radius_side;
let line_rect = egui::Rect::from_x_y_ranges(time_x..=time_x, response.rect.y_range())
.expand(interact_radius);

let time_drag_id = ui.id().with("time_drag");
let response = ui
.interact(line_rect, time_drag_id, egui::Sense::drag())
.on_hover_and_drag_cursor(egui::CursorIcon::ResizeHorizontal);

if response.dragged() {
if let Some(pointer_pos) = ui.input(|i| i.pointer.hover_pos()) {
let time =
time_offset + transform.value_from_position(pointer_pos).x.round() as i64;

let time_ctrl = &mut ctx.rec_cfg.time_ctrl;
time_ctrl.set_time(time);
time_ctrl.pause();
}
}

let stroke = if response.dragged() {
ui.style().visuals.widgets.active.fg_stroke
} else if response.hovered() {
ui.style().visuals.widgets.hovered.fg_stroke
} else {
ui.visuals().widgets.inactive.fg_stroke
};
crate::ui::time_panel::paint_time_cursor(
ui.painter(),
time_x,
Expand Down

1 comment on commit d49a8d6

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Rust Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.25.

Benchmark suite Current: d49a8d6 Previous: 30e7d63 Ratio
datastore/num_rows=1000/num_instances=1000/packed=false/insert/default 3996876 ns/iter (± 139406) 2750577 ns/iter (± 24005) 1.45
datastore/num_rows=1000/num_instances=1000/packed=false/range/default 4498375 ns/iter (± 91908) 2860207 ns/iter (± 29290) 1.57
mono_points_arrow/generate_message_bundles 33517480 ns/iter (± 316190) 26040368 ns/iter (± 1385888) 1.29
mono_points_arrow_batched/generate_message_bundles 29456416 ns/iter (± 446549) 18064394 ns/iter (± 640796) 1.63
mono_points_arrow_batched/generate_messages 7216730 ns/iter (± 179329) 4160848 ns/iter (± 83389) 1.73
mono_points_arrow_batched/encode_total 38748229 ns/iter (± 504654) 25846549 ns/iter (± 942679) 1.50
mono_points_arrow_batched/decode_message_bundles 10779288 ns/iter (± 399597) 7337398 ns/iter (± 100144) 1.47
mono_points_arrow_batched/decode_total 11784906 ns/iter (± 309820) 8077508 ns/iter (± 150503) 1.46

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.