Gip-Gip / egui-plotter

Simple to use utilties for integrating plotter into egui
MIT License
45 stars 19 forks source link

Embedding a plot inside a Window and trying to expand it produces the application to panic #17

Open jjimenezroda opened 6 months ago

jjimenezroda commented 6 months ago

I have the following piece of code:

egui::Window::new("Plot Window").open(&mut true).show(ctx, |ui| {
            let root = EguiBackend::new(ui).into_drawing_area();
            root.fill(&WHITE).unwrap();
            let mut chart = ChartBuilder::on(&root)
                .caption("y=x^2", ("sans-serif", 50).into_font())
                .margin(5)
                .x_label_area_size(30)
                .y_label_area_size(30)
                .build_cartesian_2d(-1f32..1f32, -0.1f32..1f32)
                .unwrap();

            chart.configure_mesh().draw().unwrap();

            chart
                .draw_series(LineSeries::new(
                    (-50..=50).map(|x| x as f32 / 50.0).map(|x| (x, x * x)),
                    &RED,
                ))
                .unwrap()
                .label("y = x^2")
                .legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], &RED));

            chart
                .configure_series_labels()
                .background_style(&WHITE.mix(0.8))
                .border_style(&BLACK)
                .draw()
                .unwrap();

            root.present().unwrap();
        });

And the first issue is that the plot expands the size of the window as you can see here:

image

The second issue is that, when you try to expand the window the application panics with the following message:

thread 'main' panicked at /Users/jimenj13/.cargo/registry/src/index.crates.io-6f17d22bba15001f/epaint-0.27.2/src/text/font.rs:92:9:
assertion failed: scale_in_pixels > 0.0
stack backtrace:
   0:        0x10177336c - std::backtrace_rs::backtrace::libunwind::trace::hdc7d2d82dacc83e6
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:        0x10177336c - std::backtrace_rs::backtrace::trace_unsynchronized::h11fcbf27db856d40
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:        0x10177336c - std::sys_common::backtrace::_print_fmt::h117e5fb45bd92414
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library/std/src/sys_common/backtrace.rs:68:5
   3:        0x10177336c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd4e6df6dd376d525
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library/std/src/sys_common/backtrace.rs:44:22
   4:        0x101792dc8 - core::fmt::rt::Argument::fmt::h4f724c1ed2e34985
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library/core/src/fmt/rt.rs:142:9
   5:        0x101792dc8 - core::fmt::write::h5a442bf928ef18fb
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library/core/src/fmt/mod.rs:1120:17
   6:        0x101770620 - std::io::Write::write_fmt::h01fe6f9cc882fac7
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library/std/src/io/mod.rs:1846:15
   7:        0x1017731a0 - std::sys_common::backtrace::_print::h15d065176d59d5e1
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library/std/src/sys_common/backtrace.rs:47:5
   8:        0x1017731a0 - std::sys_common::backtrace::print::h249c7fd853efd630
                               at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library/std/src/sys_common/backtrace.rs:34:9

Am I doing something wrong (or forgetting something)? Or is this an open issue?

jjimenezroda commented 5 months ago

So I've find out that basically it breaks when the size of the font gets too small when resizing the window. I can set a minimum size to the Window, but since the plot does not seem to respect the window limits, it is not really helping.

Here an example with a different plot:

image

Any ideas?