Skip to content

Commit

Permalink
Make egui_plot::PlotItem a public trait (emilk#3943)
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk authored and hacknus committed Oct 30, 2024
1 parent 71e35fa commit 36679d1
Show file tree
Hide file tree
Showing 5 changed files with 283 additions and 276 deletions.
28 changes: 14 additions & 14 deletions crates/egui_plot/src/items/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ mod values;
const DEFAULT_FILL_ALPHA: f32 = 0.05;

/// Container to pass-through several parameters related to plot visualization
pub(super) struct PlotConfig<'a> {
pub struct PlotConfig<'a> {
pub ui: &'a Ui,
pub transform: &'a PlotTransform,
pub show_x: bool,
pub show_y: bool,
}

/// Trait shared by things that can be drawn in the plot.
pub(super) trait PlotItem {
fn shapes(&self, ui: &mut Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>);
pub trait PlotItem {
fn shapes(&self, ui: &Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>);

/// For plot-items which are generated based on x values (plotting functions).
fn initialize(&mut self, x_range: RangeInclusive<f64>);
Expand Down Expand Up @@ -194,7 +194,7 @@ impl HLine {
}

impl PlotItem for HLine {
fn shapes(&self, ui: &mut Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
fn shapes(&self, ui: &Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
let Self {
y,
stroke,
Expand Down Expand Up @@ -329,7 +329,7 @@ impl VLine {
}

impl PlotItem for VLine {
fn shapes(&self, ui: &mut Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
fn shapes(&self, ui: &Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
let Self {
x,
stroke,
Expand Down Expand Up @@ -479,7 +479,7 @@ fn y_intersection(p1: &Pos2, p2: &Pos2, y: f32) -> Option<f32> {
}

impl PlotItem for Line {
fn shapes(&self, _ui: &mut Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
fn shapes(&self, _ui: &Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
let Self {
series,
stroke,
Expand Down Expand Up @@ -653,7 +653,7 @@ impl Polygon {
}

impl PlotItem for Polygon {
fn shapes(&self, _ui: &mut Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
fn shapes(&self, _ui: &Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
let Self {
series,
stroke,
Expand Down Expand Up @@ -778,7 +778,7 @@ impl Text {
}

impl PlotItem for Text {
fn shapes(&self, ui: &mut Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
fn shapes(&self, ui: &Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
let color = if self.color == Color32::TRANSPARENT {
ui.style().visuals.text_color()
} else {
Expand Down Expand Up @@ -910,7 +910,7 @@ impl Points {
self
}

/// Set the maximum extent of the marker around its position.
/// Set the maximum extent of the marker around its position, in ui points.
#[inline]
pub fn radius(mut self, radius: impl Into<f32>) -> Self {
self.radius = radius.into();
Expand Down Expand Up @@ -939,7 +939,7 @@ impl Points {
}

impl PlotItem for Points {
fn shapes(&self, _ui: &mut Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
fn shapes(&self, _ui: &Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
let sqrt_3 = 3_f32.sqrt();
let frac_sqrt_3_2 = 3_f32.sqrt() / 2.0;
let frac_1_sqrt_2 = 1.0 / 2_f32.sqrt();
Expand Down Expand Up @@ -1167,7 +1167,7 @@ impl Arrows {
}

impl PlotItem for Arrows {
fn shapes(&self, _ui: &mut Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
fn shapes(&self, _ui: &Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
use crate::emath::*;
let Self {
origins,
Expand Down Expand Up @@ -1331,7 +1331,7 @@ impl PlotImage {
}

impl PlotItem for PlotImage {
fn shapes(&self, ui: &mut Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
fn shapes(&self, ui: &Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
let Self {
position,
rotation,
Expand Down Expand Up @@ -1565,7 +1565,7 @@ impl BarChart {
}

impl PlotItem for BarChart {
fn shapes(&self, _ui: &mut Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
fn shapes(&self, _ui: &Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
for b in &self.bars {
b.add_shapes(transform, self.highlight, shapes);
}
Expand Down Expand Up @@ -1726,7 +1726,7 @@ impl BoxPlot {
}

impl PlotItem for BoxPlot {
fn shapes(&self, _ui: &mut Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
fn shapes(&self, _ui: &Ui, transform: &PlotTransform, shapes: &mut Vec<Shape>) {
for b in &self.boxes {
b.add_shapes(transform, self.highlight, shapes);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/egui_plot/src/items/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ impl MarkerShape {
// ----------------------------------------------------------------------------

/// Query the points of the plot, for geometric relations like closest checks
pub(crate) enum PlotGeometry<'a> {
pub enum PlotGeometry<'a> {
/// No geometry based on single elements (examples: text, image, horizontal/vertical line)
None,

Expand Down Expand Up @@ -425,7 +425,7 @@ impl ExplicitGenerator {
// ----------------------------------------------------------------------------

/// Result of [`super::PlotItem::find_closest()`] search, identifies an element inside the item for immediate use
pub(crate) struct ClosestElem {
pub struct ClosestElem {
/// Position of hovered-over value (or bar/box-plot/...) in PlotItem
pub index: usize,

Expand Down
Loading

0 comments on commit 36679d1

Please sign in to comment.