gip-gip / egui-plotter Goto Github PK
View Code? Open in Web Editor NEWSimple to use utilties for integrating plotter into egui
License: MIT License
Simple to use utilties for integrating plotter into egui
License: MIT License
Hi, I'm running into an issue that looks a lot like the one shown in #5, where the value labels get placed incorrectly next to the axis ticks.
It seems to have been fixed here on Github, though (and indeed things look right if I use the code pulled directly from this repo), but the version up on crates.io appears not to have been updated yet.
Would you mind publishing the updated version?
Does turning off the feathering turn it off for the entire GUI or just the plot ?
I have the following piece of code:
egui::Window::new("Plot Window").open(&mut true).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();
});
And the first issue is that the plot expands the size of the window as you can see here:
The second issue is that, when you try to expand the window the application panics with the following message:
thread 'main' panicked at /Users/jimenj13/.cargo/registry/src/index.crates.io-6f17d22bba15001f/epaint-0.27.2/src/text/font.rs:92:9:
assertion failed: scale_in_pixels > 0.0
stack backtrace:
0: 0x10177336c - std::backtrace_rs::backtrace::libunwind::trace::hdc7d2d82dacc83e6
at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
1: 0x10177336c - std::backtrace_rs::backtrace::trace_unsynchronized::h11fcbf27db856d40
at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
2: 0x10177336c - std::sys_common::backtrace::_print_fmt::h117e5fb45bd92414
at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library/std/src/sys_common/backtrace.rs:68:5
3: 0x10177336c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd4e6df6dd376d525
at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library/std/src/sys_common/backtrace.rs:44:22
4: 0x101792dc8 - core::fmt::rt::Argument::fmt::h4f724c1ed2e34985
at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library/core/src/fmt/rt.rs:142:9
5: 0x101792dc8 - core::fmt::write::h5a442bf928ef18fb
at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library/core/src/fmt/mod.rs:1120:17
6: 0x101770620 - std::io::Write::write_fmt::h01fe6f9cc882fac7
at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library/std/src/io/mod.rs:1846:15
7: 0x1017731a0 - std::sys_common::backtrace::_print::h15d065176d59d5e1
at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library/std/src/sys_common/backtrace.rs:47:5
8: 0x1017731a0 - std::sys_common::backtrace::print::h249c7fd853efd630
at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library/std/src/sys_common/backtrace.rs:34:9
Am I doing something wrong (or forgetting something)? Or is this an open issue?
Currently the basic dragging/zooming works ok for graphs, but in order to make it actually useful it would be nice to allow users to toggle during the callback what is and isn't transformed by dragging and zooming, allowing people to disable transforming for the grid/tic marks and enable it for the plot points.
This will likely result in some breaking changes.
Pre-built charts likely won't be used by everyone and not all currently work with WASM due to dependence on std::time.
Charts should be their own feature and also allow for compatibility with WASM.
The code in the examples/ directory is unable to compile due to a mismatch between the dependencies specified in the Cargo.toml file and the versions of the dependencies used in the example code.
[dependencies]
egui = "0.25.0"
eframe = "0.25.0"
plotters-backend = "0.3"
plotters = "0.3"
egui-plotter = "0.3.0"
examples/simple.rs
)error[E0308]: mismatched types
--> src/main.rs:36:41
|
36 | let root = EguiBackend::new(ui).into_drawing_area();
| ---------------- ^^ expected `&Ui`, found `&mut Ui`
| |
| arguments to this function are incorrect
|
= note: `Ui` and `egui::ui::Ui` have similar names, but are actually distinct types
note: `Ui` is defined in crate `egui`
--> /home/<user>/.cargo/registry/src/index.crates.io-6f17d22bba15001f/egui-0.25.0/src/ui.rs:31:1
|
31 | pub struct Ui {
| ^^^^^^^^^^^^^
note: `egui::ui::Ui` is defined in crate `egui`
--> /home/<user>/.cargo/registry/src/index.crates.io-6f17d22bba15001f/egui-0.22.0/src/ui.rs:31:1
|
31 | pub struct Ui {
| ^^^^^^^^^^^^^
= note: perhaps two different versions of crate `egui` are being used?
note: associated function defined here
--> /home/<user>/.cargo/registry/src/index.crates.io-6f17d22bba15001f/egui-plotter-0.3.0/src/backend.rs:200:12
|
200 | pub fn new(ui: &'a Ui) -> Self {
| ^^^
For more information about this error, try `rustc --explain E0308`.
error: could not compile `metaheuristics` (bin "metaheuristics") due to 1 previous error
The example code should compile and run without any issues, using the dependency versions specified in the Cargo.toml file.
The example code fails to compile due to a mismatch between the dependency versions used in the code and the versions specified in the Cargo.toml file.
[dependencies]
egui = "0.22.0" # <-- "0.25.0"
eframe = "0.22.0" # <-- "0.25.0"
plotters-backend = "0.3"
plotters = "0.3"
egui-plotter = "0.3.0"
This should resolve the compilation issue and allow the example code to run successfully.
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:
Tips egui::Ui
and egui::ui::Ui
have similar names, but are actually distinct types.
And cannot compile.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.