Skip to content

Commit 7b169ec

Browse files
authored
Break out plotting to own crate egui_plot (#3282)
This replaces `egui::plot` with the new crate `egui_plot`
1 parent 87f12d7 commit 7b169ec

30 files changed

+134
-57
lines changed

.github/workflows/labels.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ jobs:
2929
with:
3030
mode: minimum
3131
count: 1
32-
labels: "CI, dependencies, docs and examples, ecolor, eframe, egui_extras, egui_glow, egui-wgpu, egui-winit, egui, epaint, plot, typo"
32+
labels: "CI, dependencies, docs and examples, ecolor, eframe, egui_extras, egui_glow, egui_plot, egui-wgpu, egui-winit, egui, epaint, typo"

ARCHITECTURE.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Also see [`CONTRIBUTING.md`](CONTRIBUTING.md) for what to do before opening a PR
55

66

77
## Crate overview
8-
The crates in this repository are: `egui, emath, epaint, egui_extras, egui-winit, egui_glium, egui_glow, egui_demo_lib, egui_demo_app`.
8+
The crates in this repository are: `egui, emath, epaint, egui_extras, egui_plot, egui-winit, egui_glium, egui_glow, egui_demo_lib, egui_demo_app`.
99

1010
### `egui`: The main GUI library.
1111
Example code: `if ui.button("Click me").clicked() { … }`
@@ -24,6 +24,9 @@ Depends on `emath`.
2424
### `egui_extras`
2525
This adds additional features on top of `egui`.
2626

27+
### `egui_plot`
28+
Plotting for `egui`.
29+
2730
### `egui-winit`
2831
This crates provides bindings between [`egui`](https://github.com/emilk/egui) and [winit](https://crates.io/crates/winit).
2932

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# egui changelog
22
All notable changes to the `egui` crate will be documented in this file.
33

4-
NOTE: [`epaint`](crates/epaint/CHANGELOG.md), [`eframe`](crates/eframe/CHANGELOG.md), [`egui-winit`](crates/egui-winit/CHANGELOG.md), [`egui_glium`](crates/egui_glium/CHANGELOG.md), [`egui_glow`](crates/egui_glow/CHANGELOG.md) and [`egui-wgpu`](crates/egui-wgpu/CHANGELOG.md) have their own changelogs!
4+
NOTE: [`epaint`](crates/epaint/CHANGELOG.md), [`egui_plot`](crates/egui_plot/CHANGELOG.md), [`eframe`](crates/eframe/CHANGELOG.md), [`egui-winit`](crates/egui-winit/CHANGELOG.md), [`egui_glium`](crates/egui_glium/CHANGELOG.md), [`egui_glow`](crates/egui_glow/CHANGELOG.md) and [`egui-wgpu`](crates/egui-wgpu/CHANGELOG.md) have their own changelogs!
55

66
This file is updated upon each release.
77
Changes since the last release can be found by running the `scripts/generate_changelog.py` script.

Cargo.lock

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ members = [
66
"crates/egui_demo_lib",
77
"crates/egui_extras",
88
"crates/egui_glow",
9+
"crates/egui_plot",
910
"crates/egui-wgpu",
1011
"crates/egui-winit",
1112
"crates/egui",

crates/egui/src/input_state.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ impl PointerState {
754754
/// Latest reported pointer position.
755755
/// When tapping a touch screen, this will be `None`.
756756
#[inline(always)]
757-
pub(crate) fn latest_pos(&self) -> Option<Pos2> {
757+
pub fn latest_pos(&self) -> Option<Pos2> {
758758
self.latest_pos
759759
}
760760

crates/egui/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,8 @@ pub mod widgets;
328328
#[cfg(feature = "accesskit")]
329329
pub use accesskit;
330330

331+
pub use ahash;
332+
331333
pub use epaint;
332334
pub use epaint::ecolor;
333335
pub use epaint::emath;

crates/egui/src/ui.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,8 @@ impl Ui {
809809
self.interact(rect, id, sense)
810810
}
811811

812-
pub(crate) fn advance_cursor_after_rect(&mut self, rect: Rect) -> Id {
812+
/// Allocate a rect without interacting with it.
813+
pub fn advance_cursor_after_rect(&mut self, rect: Rect) -> Id {
813814
egui_assert!(!rect.any_nan());
814815
let item_spacing = self.spacing().item_spacing;
815816
self.placer.advance_after_rects(rect, rect, item_spacing);

crates/egui/src/widgets/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ pub(crate) mod drag_value;
1212
mod hyperlink;
1313
mod image;
1414
mod label;
15-
pub mod plot;
1615
mod progress_bar;
1716
mod selected_label;
1817
mod separator;

crates/egui_demo_lib/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,18 @@ all-features = true
2323
default = []
2424

2525
chrono = ["egui_extras/datepicker", "dep:chrono"]
26+
2627
## Allow serialization using [`serde`](https://docs.rs/serde).
27-
serde = ["egui/serde", "dep:serde"]
28+
serde = ["egui/serde", "egui_plot/serde", "dep:serde"]
29+
2830
## Enable better syntax highlighting using [`syntect`](https://docs.rs/syntect).
2931
syntax_highlighting = ["syntect"]
3032

3133

3234
[dependencies]
3335
egui = { version = "0.22.0", path = "../egui", default-features = false }
3436
egui_extras = { version = "0.22.0", path = "../egui_extras" }
37+
egui_plot = { version = "0.22.0", path = "../egui_plot" }
3538
enum-map = { version = "2", features = ["serde"] }
3639
log = { version = "0.4", features = ["std"] }
3740
unicode_names2 = { version = "0.6.0", default-features = false }

crates/egui_demo_lib/src/demo/context_menu.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl super::View for ContextMenus {
122122

123123
impl ContextMenus {
124124
fn example_plot(&self, ui: &mut egui::Ui) -> egui::Response {
125-
use egui::plot::{Line, PlotPoints};
125+
use egui_plot::{Line, PlotPoints};
126126
let n = 128;
127127
let line = Line::new(
128128
(0..=n)
@@ -137,7 +137,7 @@ impl ContextMenus {
137137
})
138138
.collect::<PlotPoints>(),
139139
);
140-
egui::plot::Plot::new("example_plot")
140+
egui_plot::Plot::new("example_plot")
141141
.show_axes(self.show_axes)
142142
.allow_drag(self.allow_drag)
143143
.allow_zoom(self.allow_zoom)

crates/egui_demo_lib/src/demo/plot_demo.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::ops::RangeInclusive;
33

44
use egui::*;
55

6-
use egui::plot::{
6+
use egui_plot::{
77
Arrows, AxisBools, AxisHints, Bar, BarChart, BoxElem, BoxPlot, BoxSpread, CoordinatesFormatter,
88
Corner, GridInput, GridMark, HLine, Legend, Line, LineStyle, MarkerShape, Plot, PlotImage,
99
PlotPoint, PlotPoints, PlotResponse, Points, Polygon, Text, VLine,
@@ -575,7 +575,7 @@ impl CustomAxesDemo {
575575
.max_digits(4),
576576
AxisHints::default()
577577
.label("Absolute")
578-
.placement(plot::HPlacement::Right),
578+
.placement(egui_plot::HPlacement::Right),
579579
];
580580
Plot::new("custom_axes")
581581
.data_aspect(2.0 * MINS_PER_DAY as f32)
@@ -636,7 +636,7 @@ impl LinkedAxesDemo {
636636
))
637637
}
638638

639-
fn configure_plot(plot_ui: &mut plot::PlotUi) {
639+
fn configure_plot(plot_ui: &mut egui_plot::PlotUi) {
640640
plot_ui.line(LinkedAxesDemo::line_with_slope(0.5));
641641
plot_ui.line(LinkedAxesDemo::line_with_slope(1.0));
642642
plot_ui.line(LinkedAxesDemo::line_with_slope(2.0));
@@ -671,7 +671,7 @@ impl LinkedAxesDemo {
671671
.height(250.0)
672672
.y_axis_width(3)
673673
.y_axis_label("y")
674-
.y_axis_position(plot::HPlacement::Right)
674+
.y_axis_position(egui_plot::HPlacement::Right)
675675
.link_axis(link_group_id, self.link_x, self.link_y)
676676
.link_cursor(link_group_id, self.link_cursor_x, self.link_cursor_y)
677677
.show(ui, LinkedAxesDemo::configure_plot);

crates/egui_demo_lib/src/demo/widget_gallery.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ impl WidgetGallery {
259259
}
260260

261261
fn example_plot(ui: &mut egui::Ui) -> egui::Response {
262-
use egui::plot::{Line, PlotPoints};
262+
use egui_plot::{Line, PlotPoints};
263263
let n = 128;
264264
let line_points: PlotPoints = (0..=n)
265265
.map(|i| {
@@ -269,7 +269,7 @@ fn example_plot(ui: &mut egui::Ui) -> egui::Response {
269269
})
270270
.collect();
271271
let line = Line::new(line_points);
272-
egui::plot::Plot::new("example_plot")
272+
egui_plot::Plot::new("example_plot")
273273
.height(32.0)
274274
.show_axes(false)
275275
.data_aspect(1.0)

crates/egui_plot/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changelog for egui_plot
2+
All notable changes to the `egui_plot` integration will be noted in this file.
3+
4+
This file is updated upon each release.
5+
Changes since the last release can be found by running the `scripts/generate_changelog.py` script.

crates/egui_plot/Cargo.toml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[package]
2+
name = "egui_plot"
3+
version = "0.22.0"
4+
authors = [
5+
"Dominik Rössler <dominik@freshx.de>",
6+
"Emil Ernerfeldt <emil.ernerfeldt@gmail.com>",
7+
"René Rössler <rene@freshx.de>",
8+
]
9+
description = "Immediate mode plotting for the egui GUI library"
10+
edition = "2021"
11+
rust-version = "1.67"
12+
homepage = "https://github.com/emilk/egui"
13+
license = "MIT OR Apache-2.0"
14+
readme = "README.md"
15+
repository = "https://github.com/emilk/egui"
16+
categories = ["visualization", "gui"]
17+
keywords = ["egui", "plot", "plotting"]
18+
include = ["../LICENSE-APACHE", "../LICENSE-MIT", "**/*.rs", "Cargo.toml"]
19+
20+
[package.metadata.docs.rs]
21+
all-features = true
22+
23+
[lib]
24+
25+
26+
[features]
27+
default = []
28+
29+
30+
## Allow serialization using [`serde`](https://docs.rs/serde).
31+
serde = ["dep:serde", "egui/serde"]
32+
33+
34+
[dependencies]
35+
egui = { version = "0.22.0", path = "../egui", default-features = false }
36+
37+
38+
#! ### Optional dependencies
39+
## Enable this when generating docs.
40+
document-features = { version = "0.2", optional = true }
41+
42+
serde = { version = "1", optional = true, features = ["derive"] }

crates/egui_plot/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# egui_plot
2+
3+
[![Latest version](https://img.shields.io/crates/v/egui_plot.svg)](https://crates.io/crates/egui_plot)
4+
[![Documentation](https://docs.rs/egui_plot/badge.svg)](https://docs.rs/egui_plot)
5+
[![unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance/)
6+
![MIT](https://img.shields.io/badge/license-MIT-blue.svg)
7+
![Apache](https://img.shields.io/badge/license-Apache-blue.svg)
8+
9+
Immediate mode plotting for [`egui`](https://github.com/emilk/egui).

crates/egui/src/widgets/plot/axis.rs crates/egui_plot/src/axis.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use std::{fmt::Debug, ops::RangeInclusive, sync::Arc};
22

3-
use epaint::{
4-
emath::{remap_clamp, round_to_decimals},
5-
Pos2, Rect, Shape, Stroke, TextShape,
6-
};
3+
use egui::emath::{remap_clamp, round_to_decimals, Pos2, Rect};
4+
use egui::epaint::{Shape, Stroke, TextShape};
75

86
use crate::{Response, Sense, TextStyle, Ui, WidgetText};
97

crates/egui/src/widgets/plot/items/bar.rs crates/egui_plot/src/items/bar.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use crate::emath::NumExt;
2-
use crate::epaint::{Color32, RectShape, Rounding, Shape, Stroke};
1+
use egui::emath::NumExt;
2+
use egui::epaint::{Color32, RectShape, Rounding, Shape, Stroke};
33

44
use super::{add_rulers_and_text, highlighted_color, Orientation, PlotConfig, RectElement};
5-
use crate::plot::{BarChart, Cursor, PlotPoint, PlotTransform};
5+
use crate::{BarChart, Cursor, PlotPoint, PlotTransform};
66

77
/// One bar in a [`BarChart`]. Potentially floating, allowing stacked bar charts.
88
/// Width can be changed to allow variable-width histograms.
@@ -185,6 +185,6 @@ impl RectElement for Bar {
185185
Orientation::Vertical => scale[1],
186186
};
187187
let decimals = ((-scale.abs().log10()).ceil().at_least(0.0) as usize).at_most(6);
188-
crate::plot::format_number(self.value, decimals)
188+
crate::format_number(self.value, decimals)
189189
}
190190
}

crates/egui/src/widgets/plot/items/box_elem.rs crates/egui_plot/src/items/box_elem.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
use crate::emath::NumExt;
2-
use crate::epaint::{Color32, RectShape, Rounding, Shape, Stroke};
1+
use egui::emath::NumExt as _;
2+
use egui::epaint::{Color32, RectShape, Rounding, Shape, Stroke};
3+
4+
use crate::{BoxPlot, Cursor, PlotPoint, PlotTransform};
35

46
use super::{add_rulers_and_text, highlighted_color, Orientation, PlotConfig, RectElement};
5-
use crate::plot::{BoxPlot, Cursor, PlotPoint, PlotTransform};
67

78
/// Contains the values of a single box in a box plot.
89
#[derive(Clone, Debug, PartialEq)]

crates/egui/src/widgets/plot/items/mod.rs crates/egui_plot/src/items/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,10 @@ impl PlotItem for HLine {
187187

188188
// Round to minimize aliasing:
189189
let points = vec![
190-
ui.ctx().round_pos_to_pixels(
190+
ui.painter().round_pos_to_pixels(
191191
transform.position_from_point(&PlotPoint::new(transform.bounds().min[0], *y)),
192192
),
193-
ui.ctx().round_pos_to_pixels(
193+
ui.painter().round_pos_to_pixels(
194194
transform.position_from_point(&PlotPoint::new(transform.bounds().max[0], *y)),
195195
),
196196
];
@@ -303,10 +303,10 @@ impl PlotItem for VLine {
303303

304304
// Round to minimize aliasing:
305305
let points = vec![
306-
ui.ctx().round_pos_to_pixels(
306+
ui.painter().round_pos_to_pixels(
307307
transform.position_from_point(&PlotPoint::new(*x, transform.bounds().min[1])),
308308
),
309-
ui.ctx().round_pos_to_pixels(
309+
ui.painter().round_pos_to_pixels(
310310
transform.position_from_point(&PlotPoint::new(*x, transform.bounds().max[1])),
311311
),
312312
];

crates/egui/src/widgets/plot/items/rect_elem.rs crates/egui_plot/src/items/rect_elem.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
use egui::emath::NumExt as _;
2+
use egui::epaint::{Color32, Rgba, Stroke};
3+
4+
use crate::transform::{PlotBounds, PlotTransform};
5+
16
use super::{Orientation, PlotPoint};
2-
use crate::plot::transform::{PlotBounds, PlotTransform};
3-
use epaint::emath::NumExt;
4-
use epaint::{Color32, Rgba, Stroke};
57

68
/// Trait that abstracts from rectangular 'Value'-like elements, such as bars or boxes
79
pub(super) trait RectElement {

crates/egui/src/widgets/plot/items/values.rs crates/egui_plot/src/items/values.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use epaint::{Pos2, Shape, Stroke, Vec2};
21
use std::ops::{Bound, RangeBounds, RangeInclusive};
32

4-
use crate::plot::transform::PlotBounds;
3+
use egui::{Pos2, Shape, Stroke, Vec2};
4+
5+
use crate::transform::PlotBounds;
56

67
/// A point coordinate in the plot.
78
///
File renamed without changes.

0 commit comments

Comments
 (0)