Gip-Gip / Gip-Gip/egui-plotter

AreaChart renderer bug

Open
#7 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
70
Forks
37
PR merge metrics
No merged PRs in 30d

Description

The area chart renderer creates unnecessary and wrong triangles.

use egui_plotter::Chart;
use eframe::egui::{self};
use plotters::prelude::*;

 fn main() {
    test_chart();
    let options = eframe::NativeOptions {
        initial_window_size: Some(egui::vec2(320.0, 240.0)),
        ..Default::default()
    };
    let _ = eframe::run_native("Test", options, Box::new(|_cc| Box::<App>::new(App::default())));
}

struct App {
    chart: Chart
}

impl Default for App {
    fn default() -> Self {
        Self {
            chart: create_chart()}
    }
}


impl eframe::App for App {
    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
        ctx.request_repaint();
        egui::CentralPanel::default().show(ctx, |ui| {
            self.chart.draw(ui);
        });
        }
    }
    
fn create_chart() -> Chart {
    Chart::new()
        .builder_cb(Box::new(|area, _t, _| {
                let mut chart = ChartBuilder::on(area)
                    .set_label_area_size(LabelAreaPosition::Left, 40)
                    .set_label_area_size(LabelAreaPosition::Bottom, 40)
                    .margin(5)
                    .build_cartesian_2d(0..10, 0..50)
                    .unwrap();

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

                let data = [25, 37, 15, 32, 45, 33, 32, 10, 29, 0, 21];
                chart
                    .draw_series(
                        AreaSeries::new((0..).zip(data.iter().enumerate().map(|x| (*x.1 as i32))),
                        0, &RED.mix(0.2)).border_style(&RED)
                    )
                    .unwrap();
    }))

}

pub fn test_chart() {
    let root_area = BitMapBackend::new("image.png", (600, 400))
    .into_drawing_area();
    root_area.fill(&WHITE).unwrap();

                let mut chart = ChartBuilder::on(&root_area)
                    .set_label_area_size(LabelAreaPosition::Left, 40)
                    .set_label_area_size(LabelAreaPosition::Bottom, 40)
                    .margin(5)
                    .build_cartesian_2d(0..10, 0..50)
                    .unwrap();

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

                let data = [25, 37, 15, 32, 45, 33, 32, 10, 29, 0, 21];
                chart
                    .draw_series(
                        AreaSeries::new((0..).zip(data.iter().enumerate().map(|x| (*x.1 as i32))),
                        0, &RED.mix(0.2)).border_style(&RED)
                    )
                    .unwrap();
}

The output of egui-plotter is:
screenshot
The output of plotters with the BitmapBackend is:
image

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the Rust reproduction in the issue and compare the egui-plotter AreaSeries output with the BitmapBackend output from plotters. Trace the AreaChart renderer used by Chart::draw and verify that the rendered triangles match the reference image without the extra or incorrect shapes.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.