Skip to content
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
15 changes: 11 additions & 4 deletions egui_plot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -998,9 +998,15 @@ impl<'a> Plot<'a> {
// Apply bounds modifications.
for modification in bounds_modifications {
match modification {
BoundsModification::Set(new_bounds) => {
bounds = new_bounds;
mem.auto_bounds = false.into();
BoundsModification::SetX(range) => {
bounds.min[0] = *range.start();
bounds.max[0] = *range.end();
mem.auto_bounds.x = false;
}
BoundsModification::SetY(range) => {
bounds.min[1] = *range.start();
bounds.max[1] = *range.end();
mem.auto_bounds.y = false;
}
BoundsModification::Translate(delta) => {
let delta = (delta.x as f64, delta.y as f64);
Expand Down Expand Up @@ -1421,7 +1427,8 @@ fn axis_widgets<'a>(
/// User-requested modifications to the plot bounds. We collect them in the plot build function to later apply
/// them at the right time, as other modifications need to happen first.
enum BoundsModification {
Set(PlotBounds),
SetX(RangeInclusive<f64>),
SetY(RangeInclusive<f64>),
Translate(Vec2),
AutoBounds(Vec2b),
Zoom(Vec2, PlotPoint),
Expand Down
16 changes: 15 additions & 1 deletion egui_plot/src/plot_ui.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::ops::RangeInclusive;

use egui::{epaint::Hsva, Color32, Pos2, Response, Vec2, Vec2b};

use crate::{BoundsModification, PlotBounds, PlotItem, PlotPoint, PlotTransform};
Expand Down Expand Up @@ -39,8 +41,20 @@ impl<'a> PlotUi<'a> {

/// Set the plot bounds. Can be useful for implementing alternative plot navigation methods.
pub fn set_plot_bounds(&mut self, plot_bounds: PlotBounds) {
self.set_plot_bounds_x(plot_bounds.range_x());
self.set_plot_bounds_y(plot_bounds.range_y());
}

/// Set the X bounds. Can be useful for implementing alternative plot navigation methods.
pub fn set_plot_bounds_x(&mut self, range: impl Into<RangeInclusive<f64>>) {
self.bounds_modifications
.push(BoundsModification::SetX(range.into()));
}

/// Set the Y bounds. Can be useful for implementing alternative plot navigation methods.
pub fn set_plot_bounds_y(&mut self, range: impl Into<RangeInclusive<f64>>) {
self.bounds_modifications
.push(BoundsModification::Set(plot_bounds));
.push(BoundsModification::SetY(range.into()));
}

/// Move the plot bounds. Can be useful for implementing alternative plot navigation methods.
Expand Down
Loading