-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
bugSomething is brokenSomething is brokenegui_plotRelated to egui_plotRelated to egui_plotgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needed
Description
Describe the bug
When all y values are identically the same, the calculated y bounds will be considered invalid and the default y-range of [0, 1] will be used instead. The same bug applies to x as well.
To Reproduce
I've created an example application here:
The gist is
let x_range = 0..1000;
let single2: PlotPoints = x_range
.clone()
.map(|i| {
let x = i as f64 * 0.01;
[x, 2.0]
})
.collect();
ui.label("All values == 2, completely missing");
Plot::new("plot3")
.allow_drag(false)
.allow_zoom(false)
.allow_scroll(false)
.height(row_height)
.show(ui, |plot_ui| plot_ui.line(Line::new(single2)));
Where determining the bounds, there is
egui/crates/egui/src/widgets/plot/mod.rs
Line 831 in a1f6f68
let auto_x = !bounds_modified.x && (!min_auto_bounds.is_valid_x() || auto_bounds.x); |
let auto_x = !bounds_modified.x && (!min_auto_bounds.is_valid_x() || auto_bounds.x);
let auto_y = !bounds_modified.y && (!min_auto_bounds.is_valid_y() || auto_bounds.y);
Ultimately there is a call to
self.is_finite() && self.width() > 0.0 && self.height() > 0.0 |
pub fn is_valid(&self) -> bool {
self.is_finite() && self.width() > 0.0 && self.height() > 0.0
}
where, in this case, the height will be == 0.0
since all values are the same. Since the y bounds are not valid, the default bounds of [0, 1]
are used.
Expected behavior
An appropriate bound to be calculated for this case.
Desktop (please complete the following information):
- OS: macOS
- Version 12.6
Additional context
barbiefan and JumpyLionnn
Metadata
Metadata
Assignees
Labels
bugSomething is brokenSomething is brokenegui_plotRelated to egui_plotRelated to egui_plotgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needed