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

Custom zoom configuration #1164

Closed
SwayStar123 opened this issue Jan 26, 2022 · 5 comments · Fixed by #2714
Closed

Custom zoom configuration #1164

SwayStar123 opened this issue Jan 26, 2022 · 5 comments · Fixed by #2714
Labels
egui_plot Related to egui_plot feature New feature or request

Comments

@SwayStar123
Copy link

Is your feature request related to a problem? Please describe.

Currently, the ctrl + scroll zooms in on both x and y axis at the same time, when trying to see granular candlestick data this is not ideal.

Describe the solution you'd like

It would be nice if I could add my own custom zoom logic, like regular scroll to zoom on the x axis, ctrl scroll to zoom on the y axis, etc.

Describe alternatives you've considered

Ive tried setting the bar width at a higher number, so that zooming would be unnecessary but its impossible to find a zoom level that works for every need

Additional context

image
Pretty much impossible to make any good use out of this chart with the current y axis zoom, only option is to zoom in on both axes and only view a small segment of the chart.

@SwayStar123 SwayStar123 added the feature New feature or request label Jan 26, 2022
@SwayStar123
Copy link
Author

SwayStar123 commented Jan 26, 2022

its not as important as a seperate x & y zoom but it would be nice if I could add a maximum and a minimum zoom level aswell as a log scale

@emilk emilk added the egui_plot Related to egui_plot label Jan 26, 2022
@calbaker
Copy link

calbaker commented Sep 2, 2022

Yep, I'd benefit hugely from being able to make check boxes for lock x zoom and/or lock y zoom so that I could zoom in one axis only. It'd also be nice to be able to specify ranges of x- and y-data to plot.

@g-tejas
Copy link

g-tejas commented Jan 8, 2023

This would be of great help to me too! Any ideas anyone?

@IFcoltransG
Copy link

For my use case, I'd simply like to change zoom so it happens on regular scrolling, rather than ctrl + scrolling. A convenience method to zoom by a certain amount per each direction (around some centre point) would help me immensely, and would allow everyone to hook up whatever zooming behaviour they need. Sort of like the translate_bounds but for scale. Granted, they'd still need process the scroll deltas and mouse position themselves, but it would still be a lot friendlier than messing with set_plot_bounds.
A possible API could be pub fn scale_bounds(&mut self, scale: Vec2, centre: Pos2) where the components of the scale vector represent the amounts to scale x and y by. Or alternatively two separate functions scale_x/y_bounds(&mut self, scale: f64, centre: f64).

@YgorSouza
Copy link
Contributor

I opened a PR to address this issue. Any feedback would be appreciated. I included an example of how to customize the plot manipulation, but I am struggling with using Ctrl for scrolling instead of zooming. When Ctrl is down, the mouse Scroll event is automatically replaced by a Zoom event, so I don't know how to distinguish it from other Zoom events. If anyone knows of a way to get the mouse scroll delta regardless of modifier keys, that would be appreciated as well.

emilk pushed a commit that referenced this issue Jan 6, 2024
<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md)
before opening a Pull Request!

* Keep your PR:s small and focused.
* If applicable, add a screenshot or gif.
* Unless this is a trivial change, add a line to the relevant
`CHANGELOG.md` under "Unreleased".
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`.
* Remember to run `cargo fmt` and `cargo clippy`.
* Open the PR as a draft until you have self-reviewed it and run
`./sh/check.sh`.
* When you have addressed a PR comment, mark it as resolved.

Please be patient! I will review you PR, but my time is limited!
-->

- Added methods to zoom the plot programmatically, to match the
previously added `translate_bounds()`.
- Added an example of how this method can be used to customize the plot
navigation.

Closes #1164.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
egui_plot Related to egui_plot feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants