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

Speed up region labels interaction and fix placement during zoom #317

Merged
merged 12 commits into from
Dec 7, 2022

Conversation

yoda-vid
Copy link
Collaborator

The Plot Editor shows region labels on mouse hover when registered atlas labels are loaded with an image. This PR fixes several issues with label interactivity:

  • Greatly speeds up label display by using blitting in Matplotlib
  • The label's position relative to the mouse now fits within the plot across zoom. The label has changed its position relative to the mouse depending in turn on where the mouse is relative to the whole image, which tends to keep the label within the plot. This relative image position is no longer relevant to the label position when zooming into an image, however. Instead, the relative plot position is used so that the label tends to stay within the plot.

The region label displayed when hovering over a region is offset from the mouse position in data coordinates, which can give inconsistent distances depending on the image size or amount of zooming. To offset by a consistent distance, transform the data coordinates to axes coordinates and offset by a fixed axes unit value. Store this offset as a private attribute for future customizability.
Move into separate function for modularity and readability.
…data

The region label position changes orientation around the mouse pointer to maximize available space. The orientation has been based on data coordinates, which works when the full image is shown in the plot but not for zoomed plots, where the data midline usually differs from the plot midline. Change this midline to use the axes coordinates rather than the data coordinates.
Accept additional arguments to fix error in figure close handler.
…mance

Add a blit controller class inspired by this tutorial:
https://matplotlib.org/stable/tutorials/advanced/blitting.html#class-based-example

Store this controller in the Plot Editor to update the region label more efficiently if the controller is set.
- Separate out appending artists into a separate function to allow appending a single arist
- Add the region label from the Plot Editor to this blitter when generating the label
Implement the blitter in these editors to improve the speed of region label display on mouse hover.
The fully integrated GUI uses a TraitsUI/Pyface/Mayavi stack with PyQt5 but is not necessary for running other parts of MM, including the individual Matplotlib-based GUI components. Move the full GUI dependencies into a separate, optional group, which allows MM to be installed as a library with a smaller dependency footprint. Include this GUI group in the `most` and `all` groups to ensure that it is still installed in the recommended pathways.
@yoda-vid yoda-vid added bug Something isn't working enhancement New feature or request labels Nov 29, 2022
@yoda-vid yoda-vid added this to the v1.6.0 milestone Nov 29, 2022
Move from Atlas Editor to the image sync mixin class since the function's attributes are all present in the mixin.
Turn off the region label when leaving each Plot Editor to prevent stale labels.
… Plot Editor

The Plot Editor currently filters out movements within the same pixel to reduce performance impact. Small movements may also be desirable to filter, especially for backends where redraw events can incur a delay, such as the web and Jupyter-related backends. Add a customizable threshold to filter movements based on both time since the last movement and distance. Filter out short, fast movements, which are more likely from imprecise, "noise" movements. Instead, respond to far, slow movements, such as long-distance motion to a different region of the plot or slow movement to a more precise position. The default threshold is 0 to continue filtering only movement within the same plot pixel.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant