emilk / emilk/egui_plot

Allow Auto-Bounds to Include or Exclude Specific Datasets

Open
#100 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
Rust
Stars
468
Forks
108
Avg merge
15m
Merged PRs (30d)
3

Description

**Is your feature request related to a problem? Please describe.**
I’m building a trading terminal using `egui` and `egui_plot`. Right now, `auto_bounds` considers all series when computing plot limits. I’d like to exclude certain datasets (for example, indicators) so that auto-bounds apply only to the primary data (e.g., candlesticks).

**Describe the solution you'd like**
Add an API to include or exclude named series when computing auto-bounds. For example:

```rs
plot
.auto_bounds([false, true])
.include(vec!["ohlc"])
// or
plot
.auto_bounds([false, true])
.exclude(vec!["bbu", "bbl"])
```

- `include(&[&str])`: only these series affect auto_bounds
- `exclude(&[&str])`: all series except these affect auto_bounds

**Describe alternatives you've considered**
Currently, I disable auto-bounds entirely, track the plot’s visible bounds each frame, and then manually re-apply the desired x/y limits when there hasn’t been any interaction:

```rs
if !pane.interacting &&
(pane.needed_plot_bounds.min()[1] != pane.plot_bounds.min()[1]
|| pane.needed_plot_bounds.max()[1] != pane.plot_bounds.max()[1])
{
plot = plot.reset(); // because include_x and include_y only works once after reset
}
plot.auto_bounds([false, false])
.include_x(pane.needed_plot_bounds.min()[0])
.include_x(pane.needed_plot_bounds.max()[0])
.include_y(pane.needed_plot_bounds.min()[1])
.include_y(pane.needed_plot_bounds.max()[1])
.link_axis(LINK_GROUP_ID, Vec2b::new(true, false))
.link_cursor(LINK_GROUP_ID, Vec2b::new(true, false))
.show(ui, |plot_ui| {
// to update plot_bounds, needed_plot_bounds and interacting
pane.update_plot_bounds(plot_ui.plot_bounds());
});
```

This workaround incurs a noticeable “jump” whenever bounds update, resulting in a less smooth scrolling/zooming experience.

**Additional context**
- A built-in `include`/`exclude` filter for `auto_bounds` would greatly simplify my code and preserve smooth interactions by avoiding the need to reset and reapply manual bounds every frame.
- `set_plot_bounds` works smoothly when there is only one pane. However, when multiple panes are linked together, it fails to update bounds correctly, making the workaround unusable in a multi-pane layout.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.