MCPcopy Create free account
hub / github.com/emilk/egui_plot / compute_bounds

Method compute_bounds

egui_plot/src/plot.rs:992–1097  ·  view source on GitHub ↗
(&self, ui: &Ui, mem: &mut PlotMemory, plot_ui: &PlotUi<'a>, plot_rect: Rect)

Source from the content-addressed store, hash-verified

990 }
991
992 fn compute_bounds(&self, ui: &Ui, mem: &mut PlotMemory, plot_ui: &PlotUi<'a>, plot_rect: Rect) {
993 // Find the cursors from other plots we need to draw
994 let mut bounds = *plot_ui.last_plot_transform.bounds();
995
996 // Transfer the bounds from a link group.
997 if let Some((id, axes)) = self.linked_axes.as_ref() {
998 ui.data_mut(|data| {
999 let link_groups: &mut BoundsLinkGroups = data.get_temp_mut_or_default(Id::NULL);
1000 if let Some(linked_bounds) = link_groups.0.get(id) {
1001 if axes.x {
1002 bounds.set_x(&linked_bounds.bounds);
1003 mem.auto_bounds.x = linked_bounds.auto_bounds.x;
1004 }
1005 if axes.y {
1006 bounds.set_y(&linked_bounds.bounds);
1007 mem.auto_bounds.y = linked_bounds.auto_bounds.y;
1008 }
1009 }
1010 });
1011 }
1012
1013 // Allow double-clicking to reset to the initial bounds.
1014 if self.allow_double_click_reset && plot_ui.response.double_clicked() {
1015 mem.auto_bounds = true.into();
1016 }
1017
1018 // Apply bounds modifications.
1019 for modification in &plot_ui.bounds_modifications {
1020 match modification {
1021 BoundsModification::SetX(range) => {
1022 bounds.min[0] = *range.start();
1023 bounds.max[0] = *range.end();
1024 mem.auto_bounds.x = false;
1025 }
1026 BoundsModification::SetY(range) => {
1027 bounds.min[1] = *range.start();
1028 bounds.max[1] = *range.end();
1029 mem.auto_bounds.y = false;
1030 }
1031 BoundsModification::Translate(delta) => {
1032 let delta = (delta.x as f64, delta.y as f64);
1033 bounds.translate(delta);
1034 mem.auto_bounds = false.into();
1035 }
1036 BoundsModification::AutoBounds(new_auto_bounds) => {
1037 mem.auto_bounds = *new_auto_bounds;
1038 }
1039 BoundsModification::Zoom(zoom_factor, center) => {
1040 bounds.zoom(*zoom_factor, *center);
1041 mem.auto_bounds = false.into();
1042 }
1043 }
1044 }
1045
1046 // Reset bounds to initial bounds if current auto_bounds are active.
1047 if mem.auto_bounds.x {
1048 bounds.set_x(&self.min_auto_bounds);
1049 }

Callers 1

show_dynMethod · 0.80

Calls 13

set_xMethod · 0.80
set_yMethod · 0.80
translateMethod · 0.80
is_valid_xMethod · 0.80
is_valid_yMethod · 0.80
merge_xMethod · 0.80
merge_yMethod · 0.80
add_relative_margin_xMethod · 0.80
add_relative_margin_yMethod · 0.80
boundsMethod · 0.45

Tested by

no test coverage detected