Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AreaChart renderer bug #7

Open
Doge815 opened this issue Aug 3, 2023 · 2 comments
Open

AreaChart renderer bug #7

Doge815 opened this issue Aug 3, 2023 · 2 comments

Comments

@Doge815
Copy link

Doge815 commented Aug 3, 2023

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

@Gip-Gip
Copy link
Owner

Gip-Gip commented Aug 16, 2023

Investigating now, sorry for the delay

@Gip-Gip
Copy link
Owner

Gip-Gip commented Aug 16, 2023

Looks like some issue with egui's tesselator, or at least is my guess. Will try to work around this however

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants