egui-plotter
egui-plotter copied to clipboard
AreaChart renderer bug
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:
The output of plotters with the BitmapBackend is:
Investigating now, sorry for the delay
Looks like some issue with egui's tesselator, or at least is my guess. Will try to work around this however