egui-plotter

simple to use utilties for integrating plotter into egui

Usage
This crate can be used by adding egui-plotter
to the dependencies in your
project's Cargo.toml
.
[dependencies]
egui-plotter = "0.1.0"
It is also heavily recommended you disable feathering in your egui context,
as not only does it slow things down but it causes artifacts with certain plots.
See line 24 example below to see how to disable feathering.
Examples
Here's a simple plotter example being run on native eframe.
Derived from
eframe and
plotters.
use eframe::egui::{self, CentralPanel, Visuals};
use egui_plotter::EguiBackend;
use plotters::prelude::*;
fn main() {
let native_options = eframe::NativeOptions::default();
eframe::run_native("My egui App", native_options, Box::new(|cc| Box::new(MyEguiApp::new(cc)))).unwrap();
}
#[derive(Default)]
struct MyEguiApp {}
impl MyEguiApp {
fn new(cc: &eframe::CreationContext<'_>) -> Self {
let context = &cc.egui_ctx;
context.tessellation_options_mut(|tess_options| {
tess_options.feathering = false;
});
context.set_visuals(Visuals::light());
Self::default()
}
}
impl eframe::App for MyEguiApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
CentralPanel::default().show(ctx, |ui| {
let root = EguiBackend::new(ui).into_drawing_area();
root.fill(&WHITE).unwrap();
let mut chart = ChartBuilder::on(&root)
.caption("y=x^2", ("sans-serif", 50).into_font())
.margin(5)
.x_label_area_size(30)
.y_label_area_size(30)
.build_cartesian_2d(-1f32..1f32, -0.1f32..1f32).unwrap();
chart.configure_mesh().draw().unwrap();
chart
.draw_series(LineSeries::new(
(-50..=50).map(|x| x as f32 / 50.0).map(|x| (x, x * x)),
&RED,
)).unwrap()
.label("y = x^2")
.legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], &RED));
chart
.configure_series_labels()
.background_style(&WHITE.mix(0.8))
.border_style(&BLACK)
.draw().unwrap();
root.present().unwrap();
});
}
}