Skip to content

Commit

Permalink
Improve plot item UX (#1816)
Browse files Browse the repository at this point in the history
* initial work

* changelog entry

* fix CI

* Update egui/src/widgets/plot/items/values.rs

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>

* Update egui/src/widgets/plot/items/values.rs

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>

* derive 'FromIterator'

* remove `bytemuck` dependency again and remove borrowing plot points for now

* update doctest

* update documentation

* remove unnecessary numeric cast

* cargo fmt

* Update egui/src/widgets/plot/items/values.rs

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
  • Loading branch information
EmbersArc and emilk authored Jul 24, 2022
1 parent cf591da commit 0bf9fc9
Show file tree
Hide file tree
Showing 14 changed files with 302 additions and 234 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui-w
* `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)).
* `Layout::left_to_right` and `Layout::right_to_left` now takes the vertical align as an argument. Previous default was `Align::Center`.
* 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 `Response::changed` for `ui.toggle_value` ([#1573](https://github.com/emilk/egui/pull/1573)).
Expand Down
2 changes: 1 addition & 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
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

0 comments on commit 0bf9fc9

Please sign in to comment.