Skip to content

Commit

Permalink
Restore egui_plot auto-bounds state after dragging the time cursor …
Browse files Browse the repository at this point in the history
…in timeseries space views (#4270)

### What

* Fixes #4246
* Depends on emilk/egui#3586
* Blocked on #4111

![Export-1701442441839](https://github.com/rerun-io/rerun/assets/49431240/d02f7d64-801a-4fe4-8ec1-20524ba78bd5)


### 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 [demo.rerun.io](https://demo.rerun.io/pr/4270) (if
applicable)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG

- [PR Build Summary](https://build.rerun.io/pr/4270)
- [Docs
preview](https://rerun.io/preview/2706326572e06cf2623136a62fee75d75b490fdd/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/2706326572e06cf2623136a62fee75d75b490fdd/examples)
<!--EXAMPLES-PREVIEW-->
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)

---------

Co-authored-by: Andreas Reich <[email protected]>
Co-authored-by: Emil Ernerfeldt <[email protected]>
  • Loading branch information
3 people authored Dec 1, 2023
1 parent c97442f commit e3dd6f3
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion crates/re_space_view_time_series/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ use crate::view_part_system::{PlotSeriesKind, TimeSeriesSystem};

#[derive(Clone, Default)]
pub struct TimeSeriesSpaceViewState {
/// track across frames when the user moves the time cursor
/// Is the user dragging the cursor this frame?
is_dragging_time_cursor: bool,

/// Was the user dragging the cursor last frame?
was_dragging_time_cursor: bool,

/// State of egui_plot's auto bounds before the user started dragging the time cursor.
saved_auto_bounds: egui::Vec2b,
}

impl SpaceViewState for TimeSeriesSpaceViewState {
Expand Down Expand Up @@ -272,11 +278,18 @@ impl SpaceViewClass for TimeSeriesSpaceView {
}

if state.is_dragging_time_cursor {
if !state.was_dragging_time_cursor {
state.saved_auto_bounds = plot_ui.auto_bounds();
}
// Freeze any change to the plot boundaries to avoid weird interaction with the time
// cursor.
plot_ui.set_plot_bounds(plot_ui.plot_bounds());
} else if state.was_dragging_time_cursor {
plot_ui.set_auto_bounds(state.saved_auto_bounds);
}

state.was_dragging_time_cursor = state.is_dragging_time_cursor;

// decide if the time cursor should be displayed, and if where
current_time
.map(|current_time| (current_time - time_offset) as f64)
Expand Down

0 comments on commit e3dd6f3

Please sign in to comment.