Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Break out plotting to own crate egui_plot #3282

Merged
merged 1 commit into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
with:
mode: minimum
count: 1
labels: "CI, dependencies, docs and examples, ecolor, eframe, egui_extras, egui_glow, egui-wgpu, egui-winit, egui, epaint, plot, typo"
labels: "CI, dependencies, docs and examples, ecolor, eframe, egui_extras, egui_glow, egui_plot, egui-wgpu, egui-winit, egui, epaint, typo"
5 changes: 4 additions & 1 deletion ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Also see [`CONTRIBUTING.md`](CONTRIBUTING.md) for what to do before opening a PR


## Crate overview
The crates in this repository are: `egui, emath, epaint, egui_extras, egui-winit, egui_glium, egui_glow, egui_demo_lib, egui_demo_app`.
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`.

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

### `egui_plot`
Plotting for `egui`.

### `egui-winit`
This crates provides bindings between [`egui`](https://github.com/emilk/egui) and [winit](https://crates.io/crates/winit).

Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# egui changelog
All notable changes to the `egui` crate will be documented in this file.

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!
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!

This file is updated upon each release.
Changes since the last release can be found by running the `scripts/generate_changelog.py` script.
Expand Down
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"crates/egui_demo_lib",
"crates/egui_extras",
"crates/egui_glow",
"crates/egui_plot",
"crates/egui-wgpu",
"crates/egui-winit",
"crates/egui",
Expand Down
2 changes: 1 addition & 1 deletion crates/egui/src/input_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ impl PointerState {
/// Latest reported pointer position.
/// When tapping a touch screen, this will be `None`.
#[inline(always)]
pub(crate) fn latest_pos(&self) -> Option<Pos2> {
pub fn latest_pos(&self) -> Option<Pos2> {
self.latest_pos
}

Expand Down
2 changes: 2 additions & 0 deletions crates/egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ pub mod widgets;
#[cfg(feature = "accesskit")]
pub use accesskit;

pub use ahash;

pub use epaint;
pub use epaint::ecolor;
pub use epaint::emath;
Expand Down
3 changes: 2 additions & 1 deletion crates/egui/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,8 @@ impl Ui {
self.interact(rect, id, sense)
}

pub(crate) fn advance_cursor_after_rect(&mut self, rect: Rect) -> Id {
/// Allocate a rect without interacting with it.
pub fn advance_cursor_after_rect(&mut self, rect: Rect) -> Id {
egui_assert!(!rect.any_nan());
let item_spacing = self.spacing().item_spacing;
self.placer.advance_after_rects(rect, rect, item_spacing);
Expand Down
1 change: 0 additions & 1 deletion crates/egui/src/widgets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ pub(crate) mod drag_value;
mod hyperlink;
mod image;
mod label;
pub mod plot;
mod progress_bar;
mod selected_label;
mod separator;
Expand Down
5 changes: 4 additions & 1 deletion crates/egui_demo_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ all-features = true
default = []

chrono = ["egui_extras/datepicker", "dep:chrono"]

## Allow serialization using [`serde`](https://docs.rs/serde).
serde = ["egui/serde", "dep:serde"]
serde = ["egui/serde", "egui_plot/serde", "dep:serde"]

## Enable better syntax highlighting using [`syntect`](https://docs.rs/syntect).
syntax_highlighting = ["syntect"]


[dependencies]
egui = { version = "0.22.0", path = "../egui", default-features = false }
egui_extras = { version = "0.22.0", path = "../egui_extras" }
egui_plot = { version = "0.22.0", path = "../egui_plot" }
enum-map = { version = "2", features = ["serde"] }
log = { version = "0.4", features = ["std"] }
unicode_names2 = { version = "0.6.0", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions crates/egui_demo_lib/src/demo/context_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl super::View for ContextMenus {

impl ContextMenus {
fn example_plot(&self, ui: &mut egui::Ui) -> egui::Response {
use egui::plot::{Line, PlotPoints};
use egui_plot::{Line, PlotPoints};
let n = 128;
let line = Line::new(
(0..=n)
Expand All @@ -137,7 +137,7 @@ impl ContextMenus {
})
.collect::<PlotPoints>(),
);
egui::plot::Plot::new("example_plot")
egui_plot::Plot::new("example_plot")
.show_axes(self.show_axes)
.allow_drag(self.allow_drag)
.allow_zoom(self.allow_zoom)
Expand Down
8 changes: 4 additions & 4 deletions crates/egui_demo_lib/src/demo/plot_demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::ops::RangeInclusive;

use egui::*;

use egui::plot::{
use egui_plot::{
Arrows, AxisBools, AxisHints, Bar, BarChart, BoxElem, BoxPlot, BoxSpread, CoordinatesFormatter,
Corner, GridInput, GridMark, HLine, Legend, Line, LineStyle, MarkerShape, Plot, PlotImage,
PlotPoint, PlotPoints, PlotResponse, Points, Polygon, Text, VLine,
Expand Down Expand Up @@ -575,7 +575,7 @@ impl CustomAxesDemo {
.max_digits(4),
AxisHints::default()
.label("Absolute")
.placement(plot::HPlacement::Right),
.placement(egui_plot::HPlacement::Right),
];
Plot::new("custom_axes")
.data_aspect(2.0 * MINS_PER_DAY as f32)
Expand Down Expand Up @@ -636,7 +636,7 @@ impl LinkedAxesDemo {
))
}

fn configure_plot(plot_ui: &mut plot::PlotUi) {
fn configure_plot(plot_ui: &mut egui_plot::PlotUi) {
plot_ui.line(LinkedAxesDemo::line_with_slope(0.5));
plot_ui.line(LinkedAxesDemo::line_with_slope(1.0));
plot_ui.line(LinkedAxesDemo::line_with_slope(2.0));
Expand Down Expand Up @@ -671,7 +671,7 @@ impl LinkedAxesDemo {
.height(250.0)
.y_axis_width(3)
.y_axis_label("y")
.y_axis_position(plot::HPlacement::Right)
.y_axis_position(egui_plot::HPlacement::Right)
.link_axis(link_group_id, self.link_x, self.link_y)
.link_cursor(link_group_id, self.link_cursor_x, self.link_cursor_y)
.show(ui, LinkedAxesDemo::configure_plot);
Expand Down
4 changes: 2 additions & 2 deletions crates/egui_demo_lib/src/demo/widget_gallery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ impl WidgetGallery {
}

fn example_plot(ui: &mut egui::Ui) -> egui::Response {
use egui::plot::{Line, PlotPoints};
use egui_plot::{Line, PlotPoints};
let n = 128;
let line_points: PlotPoints = (0..=n)
.map(|i| {
Expand All @@ -269,7 +269,7 @@ fn example_plot(ui: &mut egui::Ui) -> egui::Response {
})
.collect();
let line = Line::new(line_points);
egui::plot::Plot::new("example_plot")
egui_plot::Plot::new("example_plot")
.height(32.0)
.show_axes(false)
.data_aspect(1.0)
Expand Down
5 changes: 5 additions & 0 deletions crates/egui_plot/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog for egui_plot
All notable changes to the `egui_plot` integration will be noted in this file.

This file is updated upon each release.
Changes since the last release can be found by running the `scripts/generate_changelog.py` script.
42 changes: 42 additions & 0 deletions crates/egui_plot/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[package]
name = "egui_plot"
version = "0.22.0"
authors = [
"Dominik Rössler <dominik@freshx.de>",
"Emil Ernerfeldt <emil.ernerfeldt@gmail.com>",
"René Rössler <rene@freshx.de>",
]
description = "Immediate mode plotting for the egui GUI library"
edition = "2021"
rust-version = "1.67"
homepage = "https://github.com/emilk/egui"
license = "MIT OR Apache-2.0"
readme = "README.md"
repository = "https://github.com/emilk/egui"
categories = ["visualization", "gui"]
keywords = ["egui", "plot", "plotting"]
include = ["../LICENSE-APACHE", "../LICENSE-MIT", "**/*.rs", "Cargo.toml"]

[package.metadata.docs.rs]
all-features = true

[lib]


[features]
default = []


## Allow serialization using [`serde`](https://docs.rs/serde).
serde = ["dep:serde", "egui/serde"]


[dependencies]
egui = { version = "0.22.0", path = "../egui", default-features = false }


#! ### Optional dependencies
## Enable this when generating docs.
document-features = { version = "0.2", optional = true }

serde = { version = "1", optional = true, features = ["derive"] }
9 changes: 9 additions & 0 deletions crates/egui_plot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# egui_plot

[![Latest version](https://img.shields.io/crates/v/egui_plot.svg)](https://crates.io/crates/egui_plot)
[![Documentation](https://docs.rs/egui_plot/badge.svg)](https://docs.rs/egui_plot)
[![unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance/)
![MIT](https://img.shields.io/badge/license-MIT-blue.svg)
![Apache](https://img.shields.io/badge/license-Apache-blue.svg)

Immediate mode plotting for [`egui`](https://github.com/emilk/egui).
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::{fmt::Debug, ops::RangeInclusive, sync::Arc};

use epaint::{
emath::{remap_clamp, round_to_decimals},
Pos2, Rect, Shape, Stroke, TextShape,
};
use egui::emath::{remap_clamp, round_to_decimals, Pos2, Rect};
use egui::epaint::{Shape, Stroke, TextShape};

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::emath::NumExt;
use crate::epaint::{Color32, RectShape, Rounding, Shape, Stroke};
use egui::emath::NumExt;
use egui::epaint::{Color32, RectShape, Rounding, Shape, Stroke};

use super::{add_rulers_and_text, highlighted_color, Orientation, PlotConfig, RectElement};
use crate::plot::{BarChart, Cursor, PlotPoint, PlotTransform};
use crate::{BarChart, Cursor, PlotPoint, PlotTransform};

/// One bar in a [`BarChart`]. Potentially floating, allowing stacked bar charts.
/// Width can be changed to allow variable-width histograms.
Expand Down Expand Up @@ -185,6 +185,6 @@ impl RectElement for Bar {
Orientation::Vertical => scale[1],
};
let decimals = ((-scale.abs().log10()).ceil().at_least(0.0) as usize).at_most(6);
crate::plot::format_number(self.value, decimals)
crate::format_number(self.value, decimals)
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::emath::NumExt;
use crate::epaint::{Color32, RectShape, Rounding, Shape, Stroke};
use egui::emath::NumExt as _;
use egui::epaint::{Color32, RectShape, Rounding, Shape, Stroke};

use crate::{BoxPlot, Cursor, PlotPoint, PlotTransform};

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

/// Contains the values of a single box in a box plot.
#[derive(Clone, Debug, PartialEq)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ impl PlotItem for HLine {

// Round to minimize aliasing:
let points = vec![
ui.ctx().round_pos_to_pixels(
ui.painter().round_pos_to_pixels(
transform.position_from_point(&PlotPoint::new(transform.bounds().min[0], *y)),
),
ui.ctx().round_pos_to_pixels(
ui.painter().round_pos_to_pixels(
transform.position_from_point(&PlotPoint::new(transform.bounds().max[0], *y)),
),
];
Expand Down Expand Up @@ -303,10 +303,10 @@ impl PlotItem for VLine {

// Round to minimize aliasing:
let points = vec![
ui.ctx().round_pos_to_pixels(
ui.painter().round_pos_to_pixels(
transform.position_from_point(&PlotPoint::new(*x, transform.bounds().min[1])),
),
ui.ctx().round_pos_to_pixels(
ui.painter().round_pos_to_pixels(
transform.position_from_point(&PlotPoint::new(*x, transform.bounds().max[1])),
),
];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use egui::emath::NumExt as _;
use egui::epaint::{Color32, Rgba, Stroke};

use crate::transform::{PlotBounds, PlotTransform};

use super::{Orientation, PlotPoint};
use crate::plot::transform::{PlotBounds, PlotTransform};
use epaint::emath::NumExt;
use epaint::{Color32, Rgba, Stroke};

/// Trait that abstracts from rectangular 'Value'-like elements, such as bars or boxes
pub(super) trait RectElement {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use epaint::{Pos2, Shape, Stroke, Vec2};
use std::ops::{Bound, RangeBounds, RangeInclusive};

use crate::plot::transform::PlotBounds;
use egui::{Pos2, Shape, Stroke, Vec2};

use crate::transform::PlotBounds;

/// A point coordinate in the plot.
///
Expand Down
File renamed without changes.
Loading