emilk / emilk/egui_plot

Auto bounds breaks link_axis and link_cursor

Open
#75 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Rust
Stars
468
Forks
108
Avg merge
15m
Merged PRs (30d)
3

Description

**Describe the bug**

While auto bounds is active `link_axis` and `link_cursor` does not work if the plot data for the different plots have a different width.

The linking works if the user zoom's in, but when the user double clicks to enable auto bounds the plots are unaligned again.

**To Reproduce**

Run the following example:

```rs
use eframe::egui;
use egui_plot::Line;

fn main() -> eframe::Result {
let native_options = eframe::NativeOptions::default();

eframe::run_simple_native("UnalignedPlots", native_options, move |ctx, _frame| {
egui::CentralPanel::default().show(ctx, |ui| {
let plot_height = ui.available_height() / 2.0;

egui_plot::Plot::new("Plot1")
.height(plot_height)
.link_axis("plot_axis", [true, false])
.link_cursor("plot_cursor", [true, false])
.show(ui, |ui| {
ui.line(Line::new(vec![[0.0, 1.0], [10.0, 0.5]]));
});

egui_plot::Plot::new("Plot2")
.height(plot_height)
.link_axis("plot_axis", [true, false])
.link_cursor("plot_cursor", [true, false])
.show(ui, |ui| {
ui.line(Line::new(vec![[5.0, 0.5], [7.0, 1.0]]));
});
});
})
}
```

Cargo.toml:

```toml
[package]
name = "unaligned_plots"
version = "0.1.0"
edition = "2021"

[dependencies]
egui = "0.31"
egui_plot = { git = "https://github.com/emilk/egui_plot", branch = "main" }
eframe = { version = "0.31", default-features = false, features = ["x11", "default_fonts", "wgpu"] }
```

**Expected behavior**

The x axis for both the cursor and the plot should be linked even while auto bounds is active.

**Screenshots**

![Image](https://github.com/user-attachments/assets/c7b1c6a2-2090-4b21-bb51-288c428e3ce7)

As can be seen in the image both cursor and plot axis are not aligned properly.

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.