Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plot wrong bounds data aspect ratio corresponding directive and allow auto_bounds if [false,false] #12

Open
haricot opened this issue Sep 22, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@haricot
Copy link
Contributor

haricot commented Sep 22, 2023

About process default bounds (enforce aspect ratio) and process allow auto_bounds.


Wrong bounds aspect ratio corresponding directive:

  • auto_bounds.x && auto_bounds.y
  • auto_bounds.x && !auto_bounds.y
  • !auto_bounds.x && auto_bounds

https://github.com/emilk/egui/blob/d77c44657206d6a5a9eda0d3b10fac6e189acc27/crates/egui_plot/src/lib.rs#L1024-L1033

My Actual comprehension of the process default bounds:
The Plot fields min_auto_bounds: PlotBounds and auto_bounds : AxisBool are used for determined the enforce aspect ratio. min_auto_bounds is determined once is initialized and on reset to initial bound else it is last_plot_transform.bounds if any axis bounds_modified.any() or if any Nan axis !bounds_modified.any() is preserving the current bounds.

The issue is to pass good axis in PlotTransform::set_aspect_by_changing_axis


Wrong allow auto_bounds when it used with !auto_bounds.x && !auto_bounds.

Only allow auto_bounds need to be true if it used like plot.auto_bounds_x() or plot.auto_bounds_y() or plot.auto_bounds_x() and plot.auto_bounds_y(), but it less live auto_bounds if is !auto_bounds.x && !auto_bounds.

https://github.com/emilk/egui/blob/d77c44657206d6a5a9eda0d3b10fac6e189acc27/crates/egui_plot/src/lib.rs#L997-L999

Proposal for resolving this two issues:


       if let Some(data_aspect) = data_aspect {
            if let Some((_, linked_axes)) = &linked_axes {
                let change_x = linked_axes.y && !linked_axes.x;
                transform.set_aspect_by_changing_axis(data_aspect as f64, change_x);
                //   bounds_modified = false.into()
            } else if auto_bounds.x && auto_bounds.y {
                transform.set_aspect_by_expanding(data_aspect as f64);
            } else if auto_bounds.any() {
                let change_x = auto_bounds.y && !auto_bounds.x;
                transform.set_aspect_by_changing_axis(data_aspect as f64, change_x);
            } else {
                transform.set_aspect_by_changing_axis(data_aspect as f64, false);
                bounds_modified.allow_auto_bounds = false;
            }
        }
[...]
 
        let auto_x = (!bounds_modified.x && bounds_modified.allow_auto_bounds)
            && (!min_auto_bounds.is_valid_x()
                || (auto_bounds.x && bounds_modified.allow_auto_bounds));
        let auto_y = (!bounds_modified.x && bounds_modified.allow_auto_bounds)
            && (!min_auto_bounds.is_valid_y()
                || (auto_bounds.y && bounds_modified.allow_auto_bounds));

        bounds_modified.allow_auto_bounds = true;

or something like that :

           bounds_modified =  AxisChoice::reset(bounds_modified.choice);
            if let Some(data_aspect) = data_aspect {
                if let Some((_, linked_axes)) = &linked_axes {
                    let change_x = linked_axes.y && !linked_axes.x;
                    transform.set_aspect_by_changing_axis(data_aspect as f64, change_x);
                } else if auto_bounds.x && auto_bounds.y {
                    transform.set_aspect_by_expanding(data_aspect as f64);
                } else if auto_bounds.any() {
                    let change_x = auto_bounds.y && !auto_bounds.x;
                    transform.set_aspect_by_changing_axis(data_aspect as f64, change_x);
                } else {
                    transform.set_aspect_by_changing_axis(data_aspect as f64, false);
                    bounds_modified = AxisBools::from(([true, true], AxisChoice::None));

                }
            }
[...]
 
 not needed change like previous proposal.

unfixed:
auto_bounds : None

wrong_none.webm

fixed:
auto_bounds : None

fixed_autobounds_none.webm

auto_bounds : X

auto_bounds_X.webm

auto_bounds : Y

auto_bounds_Y.webm

auto_bounds : X_or_Y

auto_bounds_X_or_Y.webm

Which approach is best, is there a more suitable resolution?

@haricot haricot added the bug Something isn't working label Sep 22, 2023
@haricot
Copy link
Contributor Author

haricot commented Sep 23, 2023

Auto_bounds [false,false] may occur once or not at all, which may lead to additional functionality (which may be necessary to have custom bounds on initialization ), apart from the case where auto_bounds is activated (it would also be possible to have a similar choice for the other cases but its usefulness escapes me for the moment)).

once_auto_bounds_None

never_auto_bounds_none

@emilk emilk transferred this issue from emilk/egui Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant