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

Improve plot item UX #1816

Merged
merged 15 commits into from
Jul 24, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui-w
### Changed
* `PaintCallback` shapes now require the whole callback to be put in an `Arc<dyn Any>` with the value being a backend-specific callback type. ([#1684](https://github.com/emilk/egui/pull/1684))
* Replaced `needs_repaint` in `FullOutput` with `repaint_after`. Used to force repaint after the set duration in reactive mode.([#1694](https://github.com/emilk/egui/pull/1694)).
* Improved ergonomics of adding plot items. All plot items that take a series of 2D coordinates can now be created directly from `Vec<[f64; 2]>`. The `Value` and `Values` types were removed in favor of `PlotPoint` and `PlotPoints` respectively.

### Fixed 🐛
* Fixed `ImageButton`'s changing background padding on hover ([#1595](https://github.com/emilk/egui/pull/1595)).
Expand Down
3 changes: 2 additions & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion eframe/src/epi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ impl Theme {

// ----------------------------------------------------------------------------

/// WebGl Context options
/// WebGL Context options
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub enum WebGlContextOption {
Expand Down
6 changes: 5 additions & 1 deletion egui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ serde = ["dep:serde", "epaint/serde"]
[dependencies]
epaint = { version = "0.18.1", path = "../epaint", default-features = false }

bytemuck = { version = "1.7.0", features = ["derive", "extern_crate_alloc"] }

ahash = "0.7"
nohash-hasher = "0.2"

Expand All @@ -68,4 +70,6 @@ ron = { version = "0.7", optional = true }
serde = { version = "1", optional = true, features = ["derive", "rc"] }

# egui doesn't log much, but when it does, it uses [`tracing`](https://docs.rs/tracing).
tracing = { version = "0.1", optional = true, default-features = false, features = ["std"] }
tracing = { version = "0.1", optional = true, default-features = false, features = [
"std",
] }
8 changes: 4 additions & 4 deletions egui/src/widgets/plot/items/bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::emath::NumExt;
use crate::epaint::{Color32, RectShape, Rounding, Shape, Stroke};

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

/// One bar in a [`BarChart`]. Potentially floating, allowing stacked bar charts.
/// Width can be changed to allow variable-width histograms.
Expand Down Expand Up @@ -157,15 +157,15 @@ impl RectElement for Bar {
self.name.as_str()
}

fn bounds_min(&self) -> Value {
fn bounds_min(&self) -> PlotPoint {
self.point_at(self.argument - self.bar_width / 2.0, self.lower())
}

fn bounds_max(&self) -> Value {
fn bounds_max(&self) -> PlotPoint {
self.point_at(self.argument + self.bar_width / 2.0, self.upper())
}

fn values_with_ruler(&self) -> Vec<Value> {
fn values_with_ruler(&self) -> Vec<PlotPoint> {
let base = self.base_offset.unwrap_or(0.0);
let value_center = self.point_at(self.argument, base + self.value);

Expand Down
14 changes: 7 additions & 7 deletions egui/src/widgets/plot/items/box_elem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::emath::NumExt;
use crate::epaint::{Color32, RectShape, Rounding, Shape, Stroke};

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

/// Contains the values of a single box in a box plot.
#[derive(Clone, Debug, PartialEq)]
Expand Down Expand Up @@ -161,8 +161,8 @@ impl BoxElem {
let line_between = |v1, v2| {
Shape::line_segment(
[
transform.position_from_value(&v1),
transform.position_from_value(&v2),
transform.position_from_point(&v1),
transform.position_from_point(&v2),
],
stroke,
)
Expand Down Expand Up @@ -236,19 +236,19 @@ impl RectElement for BoxElem {
self.name.as_str()
}

fn bounds_min(&self) -> Value {
fn bounds_min(&self) -> PlotPoint {
let argument = self.argument - self.box_width.max(self.whisker_width) / 2.0;
let value = self.spread.lower_whisker;
self.point_at(argument, value)
}

fn bounds_max(&self) -> Value {
fn bounds_max(&self) -> PlotPoint {
let argument = self.argument + self.box_width.max(self.whisker_width) / 2.0;
let value = self.spread.upper_whisker;
self.point_at(argument, value)
}

fn values_with_ruler(&self) -> Vec<Value> {
fn values_with_ruler(&self) -> Vec<PlotPoint> {
let median = self.point_at(self.argument, self.spread.median);
let q1 = self.point_at(self.argument, self.spread.quartile1);
let q3 = self.point_at(self.argument, self.spread.quartile3);
Expand All @@ -262,7 +262,7 @@ impl RectElement for BoxElem {
self.orientation
}

fn corner_value(&self) -> Value {
fn corner_value(&self) -> PlotPoint {
self.point_at(self.argument, self.spread.upper_whisker)
}

Expand Down
Loading