epezent / implot

Immediate Mode Plotting
MIT License
4.5k stars 495 forks source link

`Constrains` should scroll rather than zoom if possible. #537

Open Nahor opened 7 months ago

Nahor commented 7 months ago

When scrolling an axis, if the new axis range gets outside the constraints, Implot will fix the limit that is outside and leave the other unchanged (if applicable). It will then compute what the zoom level must be. A user is probably not expecting the zoom to be changed.

For instance, the "Axis constraints" example:

https://github.com/epezent/implot/assets/1198364/4ff1a491-02ce-49f2-9eaa-3a14ab57f4dd

Expected: When correcting one side of an axis, the other side should be changed by the same amount, and if both sides cannot fit within the constraints (i.e. the user must be zooming out, or the constraints changed), then and only then should the zoom factor be changed.

Nahor commented 7 months ago

Someone already pushed a PR for this (PR #386), however I do not think this will fix it (or at least not anymore)

Nahor commented 7 months ago

There is a similar issue with zooming out. When one side of the axis is against the limit constraint, and the mouse is near the other side, zooming-out is extremely slow. Because of the left/mouse vs right/mouse ratio, most of the change is on the opposite side of the mouse, which is against the limit constraint and thus gets "undone", while the side of the mouse gets little change.

See the video, where zooming out is "quick" at first, until the limit constraint is reached, after which is very slow.

https://github.com/epezent/implot/assets/1198364/890dae2f-3aa2-4003-aefb-4337c3e8754f

Nahor commented 7 months ago

Third weird behavior:

In the video below, I select the range [-0.5, 0], which is too small. The result is [-0.5, 0.5], while one would more expect [-0.75, 0.25] (i.e. grow the box, but keep it centered on the selection instead of "left aligned")

https://github.com/epezent/implot/assets/1198364/20da40b1-62c4-47c4-9cef-bee2af10c8b3