`Line::fill` area has a hole where the line is out of view (regression in 0.38)
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 85/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- rust
- Bereich
- data-visualization
Rechercherichtung
Lies zuerst egui_plot/src/items/series.rs, insbesondere Line::shapes und visible_line_runs; der Issue verlinkt auf beide relevanten Abschnitte. Führe die bereitgestellte Reproduktion mit cargo run aus und vergleiche den Line::fill-Plot mit dem FilledArea-Plot. Als erledigt gilt die Aufgabe, wenn die Füllung unter außerhalb des sichtbaren Bereichs liegenden Liniensegmenten sichtbar bleibt, auch beim Scrollen, während ungefüllte Linien weiterhin wie bisher ausgeschnitten werden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Describe the bug
Line::fill draws no area under a line segment that is out of view, even when the area under it is in view. The fill then has a hole.
This is new in 0.38.0. In 0.37.0 the area is whole. I tried the same plot code with 0.37.0.
You can see the hole in two cases.
- The plot shows only part of the line, for example after you zoom in or pan. The code below does this with
default_y_bounds. - The plot is in a
ScrollAreaand you scroll its top out of view. The area shrinks while you scroll, because each segment that leaves the view takes its area with it.
To Reproduce
- Create a new project with
eframe = "0.37"andegui_plot = "0.38". - Put the code below in
src/main.rs. - Run
cargo run. - Look at the left plot between x = 2 and x = 4.
use eframe::egui::{self, Color32};
use egui_plot::{FilledArea, Line, Plot};
// The line goes up to 9, but the plots show only 0 to 5. The flat top of the line is above them.
const X: [f64; 7] = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0];
const Y: [f64; 7] = [1.0, 2.0, 8.0, 9.0, 8.0, 2.0, 1.0];
fn plot(id: &'static str) -> Plot<'static> {
Plot::new(id)
.height(240.0)
.default_x_bounds(0.0, 6.0)
.default_y_bounds(0.0, 5.0)
}
fn line() -> Line<'static> {
let points: Vec<[f64; 2]> = X.iter().zip(Y).map(|(x, y)| [*x, y]).collect();
Line::new("y", points).color(Color32::LIGHT_BLUE)
}
pub fn app(ui: &mut egui::Ui) {
egui::CentralPanel::default().show(ui, |ui| {
ui.columns(2, |cols| {
cols[0].label("Line::fill(0.0)");
plot("line_fill").show(&mut cols[0], |p| {
p.line(line().fill(0.0).fill_alpha(0.4));
});
cols[1].label("Same data with FilledArea (what I expect)");
plot("filled_area").show(&mut cols[1], |p| {
let fill = Color32::LIGHT_BLUE.gamma_multiply(0.4);
p.add(FilledArea::new("", &X, &[0.0; 7], &Y).fill_color(fill));
p.line(line());
});
});
});
}
fn main() -> eframe::Result {
eframe::run_ui_native("Line::fill repro", Default::default(), |ui, _frame| app(ui))
}
Expected behavior
The left plot looks like the right plot. The area is filled from the line down to 0, also under the flat top of the line. 0.37.0 draws it this way.
Actual behavior
The left plot has no area between x = 2 and x = 4. The flat top of the line is above the plot, so its segments are dropped, and the area under them with it.
Screenshots
Additional context
Line::shapes builds the fill from the runs that visible_line_runs returns. That function drops every segment whose rect does not touch the clip rect. This is fine for the stroke. It is wrong for the fill, because the area under a dropped segment still reaches into the clip rect.
0.37.0 built the fill from all the points. The culling came with #260, which draws dense lines as bands.
A fix that works for me is to test the segment's rect up to the fill line when fill is set. In visible_line_runs:
- if !clip_rect.intersects(Rect::from_two_pos(previous_position, next_position)) {
+ let mut segment_rect = Rect::from_two_pos(previous_position, next_position);
+ if let Some(y) = fill_y {
+ segment_rect.extend_with_y(y); // the area reaches down to the fill line
+ }
+ if !clip_rect.intersects(segment_rect) {
fill_y is the screen y of the fill line. Line::shapes passes it in, and it is None without fill, so lines without a fill keep the old culling. With this change both plots above look the same, also in a scrolled ScrollArea.
Until then, FilledArea and a plain Line give the right picture, as the right plot shows.
Versions and system
egui_plot0.38.0. The code is the same onmain(d95a746), and the example shows the same hole there.eframeandegui0.37.0- Rust 1.99.1
- macOS 26.6.2, Apple M1 Pro
- The fill is dropped before anything is drawn, so I expect the same on every system. I only tried macOS.
- Vorherrschende Sprache
- Rust
- Sterne
- 494
- Forks
- 110
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus emilk/egui_plot
-
bug
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 66/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 45/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 45/100
Alle Issues in emilk/egui_plot
Ähnliche Issues
-
claim
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
Nixitov/Riptide-Native#946 ·
Maintainer antworten meist innerhalb von 1 Tag
-
area: ai-assistants documentation help wanted
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
BetaBots-LLC/latticegate#17 ·
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 94/100
storytold/craft-libs#5594 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
听歌识曲历史跳转后对应音源界面无法返回Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
LingyunStudio/RustMusic#16 ·