Skip to content
Open
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
54 changes: 54 additions & 0 deletions egui_plot/src/items/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub struct PlotItemBase {
id: Id,
highlight: bool,
allow_hover: bool,
is_overlay: bool,
}

impl PlotItemBase {
Expand All @@ -45,6 +46,7 @@ impl PlotItemBase {
id,
highlight: false,
allow_hover: true,
is_overlay: false,
}
}
}
Expand Down Expand Up @@ -90,6 +92,14 @@ macro_rules! builder_methods_for_base {
self.base_mut().id = id.into();
self
}

/// Places this element in the overlay layer, exempting it from automatic bounds calculation.
/// Default: `false`.
#[inline]
pub fn overlay(mut self, is_overlay: bool) -> Self {
self.base_mut().is_overlay = is_overlay;
self
}
};
}

Expand Down Expand Up @@ -198,6 +208,7 @@ pub trait PlotItem {
label_formatter,
);
}
fn is_overlay(&self) -> bool;
}

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -298,6 +309,10 @@ impl PlotItem for HLine {
bounds.max[1] = self.y;
bounds
}

fn is_overlay(&self) -> bool {
self.base().is_overlay
}
}

/// A vertical line in a plot, filling the full width
Expand Down Expand Up @@ -396,6 +411,10 @@ impl PlotItem for VLine {
bounds.max[0] = self.x;
bounds
}

fn is_overlay(&self) -> bool {
self.base().is_overlay
}
}

/// A series of values forming a path.
Expand Down Expand Up @@ -424,6 +443,9 @@ impl<'a> Line<'a> {
}
}

/// Places this element in the overlay layer, exempting it from automatic bounds calculation.
/// Default: `false`.

/// Add a stroke.
#[inline]
pub fn stroke(mut self, stroke: impl Into<Stroke>) -> Self {
Expand Down Expand Up @@ -609,6 +631,10 @@ impl PlotItem for Line<'_> {
fn bounds(&self) -> PlotBounds {
self.series.bounds()
}

fn is_overlay(&self) -> bool {
self.base().is_overlay
}
}

/// A convex polygon.
Expand Down Expand Up @@ -719,6 +745,10 @@ impl PlotItem for Polygon<'_> {
fn base_mut(&mut self) -> &mut PlotItemBase {
&mut self.base
}

fn is_overlay(&self) -> bool {
self.base().is_overlay
}
}

/// Text inside the plot.
Expand Down Expand Up @@ -812,6 +842,10 @@ impl PlotItem for Text {
fn base_mut(&mut self) -> &mut PlotItemBase {
&mut self.base
}

fn is_overlay(&self) -> bool {
self.base().is_overlay
}
}

/// A set of points.
Expand Down Expand Up @@ -1039,6 +1073,10 @@ impl PlotItem for Points<'_> {
fn base_mut(&mut self) -> &mut PlotItemBase {
&mut self.base
}

fn is_overlay(&self) -> bool {
self.base().is_overlay
}
}

/// A set of arrows.
Expand Down Expand Up @@ -1150,6 +1188,10 @@ impl PlotItem for Arrows<'_> {
fn base_mut(&mut self) -> &mut PlotItemBase {
&mut self.base
}

fn is_overlay(&self) -> bool {
self.base().is_overlay
}
}

/// An image in the plot.
Expand Down Expand Up @@ -1307,6 +1349,10 @@ impl PlotItem for PlotImage {
fn base_mut(&mut self) -> &mut PlotItemBase {
&mut self.base
}

fn is_overlay(&self) -> bool {
self.base().is_overlay
}
}

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -1468,6 +1514,10 @@ impl PlotItem for BarChart {
fn base_mut(&mut self) -> &mut PlotItemBase {
&mut self.base
}

fn is_overlay(&self) -> bool {
self.base().is_overlay
}
}

/// A diagram containing a series of [`BoxElem`] elements.
Expand Down Expand Up @@ -1595,6 +1645,10 @@ impl PlotItem for BoxPlot {
fn base_mut(&mut self) -> &mut PlotItemBase {
&mut self.base
}

fn is_overlay(&self) -> bool {
self.base().is_overlay
}
}

// ----------------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions egui_plot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,9 @@ impl<'a> Plot<'a> {
// Set bounds automatically based on content.
if auto_x || auto_y {
for item in &items {
if item.is_overlay() {
continue;
}
let item_bounds = item.bounds();
if auto_x {
bounds.merge_x(&item_bounds);
Expand Down