|
| 1 | +from matplotlib.transforms import Affine2D |
| 2 | +from traitlets import Any |
| 3 | + |
| 4 | +from jdaviz.core.registries import tray_registry |
| 5 | +from jdaviz.core.template_mixin import TemplateMixin, ViewerSelectMixin |
| 6 | + |
| 7 | + |
| 8 | +@tray_registry('imviz-rotate-image', label="Simple Image Rotation") |
| 9 | +class RotateImageSimple(TemplateMixin, ViewerSelectMixin): |
| 10 | + template_file = __file__, "rotate_image.vue" |
| 11 | + |
| 12 | + angle = Any(0).tag(sync=True) |
| 13 | + |
| 14 | + def __init__(self, *args, **kwargs): |
| 15 | + super().__init__(*args, **kwargs) |
| 16 | + self._theta = 0 # degrees, clockwise |
| 17 | + |
| 18 | + def vue_rotate_image(self, *args, **kwargs): |
| 19 | + # We only grab the value here to avoid constantly updating as |
| 20 | + # user is still entering or updating the value. |
| 21 | + try: |
| 22 | + self._theta = float(self.angle) |
| 23 | + except Exception: |
| 24 | + return |
| 25 | + |
| 26 | + viewer = self.app._viewer_by_id(self.viewer_selected) |
| 27 | + |
| 28 | + # TODO: Is this really clockwise? Does it take negative angle? |
| 29 | + # Rotate selected viewer canvas. This changes zoom too. |
| 30 | + affine_transform = Affine2D().rotate_deg(self._theta) |
| 31 | + viewer.state.affine_matrix = affine_transform |
| 32 | + |
| 33 | + # TODO: Does the zoom box behave? If not, we need to disable it. |
| 34 | + # Update Compass plugin. |
| 35 | + viewer.on_limits_change() |
0 commit comments