emilk / egui_plot

2D plotting library in Rust for egui
Apache License 2.0
65 stars 23 forks source link

egui_plot 0.25.0 - No auto_bounds + include_X/Y does not render anything until double click #25

Open rnd-ash opened 7 months ago

rnd-ash commented 7 months ago

Describe the bug

When trying to manually set the data view port with Include X/Y, the plot will show nothing until double clicked.

This is being done to hide the most recent plot point of data in a historic time series (Which is retrieved every 100ms or so), in order to avoid the appearance of stuttering when data comes in. (Stuttering will appear as soon as plot.auto_bounds([true, true].into()) is used.

To Reproduce

  1. Create a thread which adds a plot point every 100ms or so
    let mut plot = Plot::new(d.group_name.clone())
                          .height(space_per_chart)
                          .allow_drag(false)
                          .include_x(disp_now as f64) // Timestamp now - 100.0ms to hide the most recent plot point (To look smooth)
                          .include_x(last_bound) // Timestamp now - 20 seconds
                          .legend(legend.clone());
                      if let Some((min, max)) = &d.bounds {// Data has finite range in Y dir, restrict it
                          plot = plot.include_y(*min);
                          if *max > 0.1 {
                              // 0.0 check
                              plot = plot.include_y(*max);
                          }
                      }
                     // False False - User has to double click to show the chart, and it looks smooth
                    //  True True - Plot stutters as the infrequent data will show
                      plot = plot.auto_bounds([false, false].into());
                      plot.show(col, |f| {
                          for line in lines {
                              f.line(line);
                          }
                      });

Expected behavior Plot should show the requested area immediately, rather than wait for user input.

Screenshots With plot = plot.auto_bounds([false, false].into()); (Buggy) Kooha-2024-01-26-10-09-39.webm

With plot = plot.auto_bounds([true, true].into()); (Stutters, but expected behaviour, hence why no autobounds is being used) Kooha-2024-01-26-10-10-42.webm

aholtzma-am commented 3 months ago

This problem seems to be that the bounds set by include_x()/include_y() will not be used except on the first call. These methods set min_auto_bounds, which is only used to initially set the bounds memory or to restore the initial bounds by double clicking.