mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 06:10:06 -04:00
plot: Update demo lib
This commit is contained in:
committed by
JohannesProgrammiert
parent
086bb49ede
commit
2d013fcfad
@@ -1,7 +1,7 @@
|
|||||||
use std::f64::consts::TAU;
|
use std::f64::consts::TAU;
|
||||||
use std::ops::RangeInclusive;
|
use std::ops::RangeInclusive;
|
||||||
|
|
||||||
use egui::plot::{AxisBools, GridInput, GridMark, PlotResponse};
|
use egui::plot::{AxisBools, GridInput, GridMark, Placement, PlotResponse, XAxisHints, YAxisHints};
|
||||||
use egui::*;
|
use egui::*;
|
||||||
use plot::{
|
use plot::{
|
||||||
Arrows, Bar, BarChart, BoxElem, BoxPlot, BoxSpread, CoordinatesFormatter, Corner, HLine,
|
Arrows, Bar, BarChart, BoxElem, BoxPlot, BoxSpread, CoordinatesFormatter, Corner, HLine,
|
||||||
@@ -264,10 +264,7 @@ impl LineDemo {
|
|||||||
ui.ctx().request_repaint();
|
ui.ctx().request_repaint();
|
||||||
self.time += ui.input(|i| i.unstable_dt).at_most(1.0 / 30.0) as f64;
|
self.time += ui.input(|i| i.unstable_dt).at_most(1.0 / 30.0) as f64;
|
||||||
};
|
};
|
||||||
let mut plot = Plot::new("lines_demo")
|
let mut plot = Plot::new("lines_demo").legend(Legend::default());
|
||||||
.x_axis_label("x".to_string())
|
|
||||||
.y_axis_label("y".to_string())
|
|
||||||
.legend(Legend::default());
|
|
||||||
if self.square {
|
if self.square {
|
||||||
plot = plot.view_aspect(1.0);
|
plot = plot.view_aspect(1.0);
|
||||||
}
|
}
|
||||||
@@ -552,12 +549,25 @@ impl CustomAxisDemo {
|
|||||||
|
|
||||||
ui.label("Zoom in on the X-axis to see hours and minutes");
|
ui.label("Zoom in on the X-axis to see hours and minutes");
|
||||||
|
|
||||||
|
let x_axes = vec![
|
||||||
|
XAxisHints::default()
|
||||||
|
.label("Time".to_string())
|
||||||
|
.formatter(x_fmt),
|
||||||
|
XAxisHints::default().label("Value".to_string()),
|
||||||
|
];
|
||||||
|
let y_axes = vec![
|
||||||
|
YAxisHints::default()
|
||||||
|
.label("Percent".to_string())
|
||||||
|
.formatter(y_fmt)
|
||||||
|
.max_digits(4),
|
||||||
|
YAxisHints::default()
|
||||||
|
.label("Absolute".to_string())
|
||||||
|
.placement(Placement::Opposite),
|
||||||
|
];
|
||||||
Plot::new("custom_axes")
|
Plot::new("custom_axes")
|
||||||
.data_aspect(2.0 * MINS_PER_DAY as f32)
|
.data_aspect(2.0 * MINS_PER_DAY as f32)
|
||||||
.x_axis_label("Percent".to_string())
|
.custom_x_axes(x_axes)
|
||||||
.x_axis_formatter(x_fmt)
|
.custom_y_axes(y_axes)
|
||||||
.y_axis_label("Time".to_string())
|
|
||||||
.y_axis_formatter(y_fmt)
|
|
||||||
.x_grid_spacer(CustomAxisDemo::x_grid)
|
.x_grid_spacer(CustomAxisDemo::x_grid)
|
||||||
.label_formatter(label_fmt)
|
.label_formatter(label_fmt)
|
||||||
.show(ui, |plot_ui| {
|
.show(ui, |plot_ui| {
|
||||||
|
|||||||
@@ -271,6 +271,7 @@ fn example_plot(ui: &mut egui::Ui) -> egui::Response {
|
|||||||
let line = Line::new(line_points);
|
let line = Line::new(line_points);
|
||||||
egui::plot::Plot::new("example_plot")
|
egui::plot::Plot::new("example_plot")
|
||||||
.height(32.0)
|
.height(32.0)
|
||||||
|
.show_axes([false, false])
|
||||||
.data_aspect(1.0)
|
.data_aspect(1.0)
|
||||||
.show(ui, |plot_ui| plot_ui.line(line))
|
.show(ui, |plot_ui| plot_ui.line(line))
|
||||||
.response
|
.response
|
||||||
|
|||||||
Reference in New Issue
Block a user