Skip to content
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

Horizontally adjacent plots separated by larger margin in v0.23.0 #13

Open
ryanavella opened this issue Oct 4, 2023 · 2 comments
Open
Labels
bug Something isn't working

Comments

@ryanavella
Copy link

Describe the bug
When switching from egui::plot (v0.22.0) to egui_plot (v0.23.0), horizontally adjacent plots are now separated by an awkwardly large margin.

To Reproduce

This is an attempt to produce a MRE from my own code, it might be further reducible. For v0.23.0, replace egui::plot with egui_plot

use eframe::egui::{self};
use egui::plot::{Line, Plot, PlotPoints};

fn main() {
    let _ = eframe::run_native("", Default::default(), Box::new(|_cc| Box::new(Foo)));
}
struct Foo;

impl eframe::App for Foo {
    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
        egui::CentralPanel::default().show(ctx, |ui| {
            const SIZE: f32 = 200.0;

            let v = vec![[0.0, 0.0], [1.0, 1.0]];

            ui.horizontal(|ui| {
                Plot::new(0).height(SIZE).width(SIZE).show(ui, |ui| {
                    ui.line(Line::new(PlotPoints::from(v.clone())));
                });
                Plot::new(1).height(SIZE).width(SIZE).show(ui, |ui| {
                    ui.line(Line::new(PlotPoints::from(v)));
                });
            });
        });
    }
}

Expected behavior

Probably the old behavior from v0.22.0?

Screenshots

v0.22.0

Capture1

v0.23.0

Capture2

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Chrome
  • Version: v0.23.0
@ryanavella ryanavella added the bug Something isn't working label Oct 4, 2023
@YgorSouza
Copy link
Contributor

As the axes are now outside the plot viewbox, the widget has to reserve some room for them. This is controlled by the y_axis_width or the custom_y_axes methods.

The code actually has a little diagram explaining how it works.

https://github.com/emilk/egui/blob/2bc2fb9c393bbbfc4832a35af1c100bc4ea48719/crates/egui_plot/src/lib.rs#L767-L788

There doesn't seem to be any way to restore the previous behavior with the axes inside the plot, though (I could be wrong about that, as I haven't kept up with this development and there is a lot of code to read through).

@ryanavella
Copy link
Author

Nice catch! I was quickly comparing 0.22.0 and 0.23.0 side-by-side and didn't notice any API differences, but I totally missed the addition of the new methods Plot::y_axis_width and Plot::custom_y_axes.

Applying .y_axis_width(1) gets me 90% of the way there, but there is one big downside: my plots are dynamically updating so I can't predict with certainty how long the tick labels are. Some tick labels will just be 0 and others might be -1e2, for example.

One solution could be adding new variants to HPlacement for inline labels, though I haven't been following development so I don't know how simple it is to bring back the old behavior. If there was a lot of major refactoring between 0.22.0 and 0.23.0 for example, I could see this being a very non-trivial task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants