`Line::fill` area has a hole where the line is out of view (regression in 0.38)

Abierto Apto para principiantes
#274 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
85/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust

Línea de trabajo

Empieza leyendo egui_plot/src/items/series.rs, especialmente Line::shapes y visible_line_runs; el issue enlaza a ambas secciones relevantes. Ejecuta la reproducción proporcionada con cargo run y compara el gráfico Line::fill con el gráfico FilledArea. Se considerará terminado cuando el relleno siga siendo visible bajo los segmentos de línea que quedan fuera de la vista, incluso al desplazarse, mientras que las líneas sin relleno mantienen su recorte actual.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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 ScrollArea and 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

  1. Create a new project with eframe = "0.37" and egui_plot = "0.38".
  2. Put the code below in src/main.rs.
  3. Run cargo run.
  4. 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

Image

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_plot 0.38.0. The code is the same on main (d95a746), and the example shows the same hole there.
  • eframe and egui 0.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.
Lenguaje dominante
Rust
Estrellas
494
Forks
110
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de emilk/egui_plot

Todos los issues de emilk/egui_plot

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.