Repository: napari/napari

Issue:
Add public method for viewer.dims._transpose()
## 🚀 Feature
Add public method for viewer.dims._transpose()

## Motivation

I use this transpose method inside of a plugin. Currently it works, but by accessing this protected method, my IDE is complaining and it's not the cleanest way to code the plugin...

## Pitch

Simply add a viewer.dims.transpose() public method


Discussion:

Resolving patch:
diff --git a/napari/components/_viewer_key_bindings.py b/napari/components/_viewer_key_bindings.py
--- a/napari/components/_viewer_key_bindings.py
+++ b/napari/components/_viewer_key_bindings.py
@@ -108,7 +108,7 @@ def roll_axes(viewer: Viewer):
     ),
 )
 def transpose_axes(viewer: Viewer):
-    viewer.dims._transpose()
+    viewer.dims.transpose()
 
 
 @register_viewer_action(trans._("Toggle grid mode."))
diff --git a/napari/components/dims.py b/napari/components/dims.py
--- a/napari/components/dims.py
+++ b/napari/components/dims.py
@@ -347,6 +347,16 @@ def reset(self):
         self.current_step = (0,) * self.ndim
         self.order = tuple(range(self.ndim))
 
+    def transpose(self):
+        """Transpose displayed dimensions.
+
+        This swaps the order of the last two displayed dimensions.
+        The order of the displayed is taken from Dims.order.
+        """
+        order = list(self.order)
+        order[-2], order[-1] = order[-1], order[-2]
+        self.order = order
+
     def _increment_dims_right(self, axis: int = None):
         """Increment dimensions to the right along given axis, or last used axis if None
 
@@ -396,12 +406,6 @@ def _roll(self):
         order[nsteps > 1] = np.roll(order[nsteps > 1], 1)
         self.order = order.tolist()
 
-    def _transpose(self):
-        """Transpose displayed dimensions."""
-        order = list(self.order)
-        order[-2], order[-1] = order[-1], order[-2]
-        self.order = order
-
 
 def reorder_after_dim_reduction(order):
     """Ensure current dimension order is preserved after dims are dropped.


Test patch:
diff --git a/napari/_tests/test_interactive_transforms.py b/napari/_tests/test_interactive_transforms.py
--- a/napari/_tests/test_interactive_transforms.py
+++ b/napari/_tests/test_interactive_transforms.py
@@ -81,7 +81,7 @@ def test_interaction_box_dim_change(make_napari_viewer):
         bottom_right_corner=[6, 30],
     )
 
-    viewer.dims._transpose()
+    viewer.dims.transpose()
 
     check_corners_of_axis_aligned_interaction_box(
         viewer.overlays.interaction_box._box,
diff --git a/napari/_tests/test_viewer.py b/napari/_tests/test_viewer.py
--- a/napari/_tests/test_viewer.py
+++ b/napari/_tests/test_viewer.py
@@ -222,7 +222,7 @@ def test_roll_transpose_update(make_napari_viewer, layer_class, data, ndim):
     check_view_transform_consistency(layer, viewer, transf_dict)
 
     # Transpose and check again:
-    viewer.dims._transpose()
+    viewer.dims.transpose()
     check_view_transform_consistency(layer, viewer, transf_dict)
 
 
diff --git a/napari/layers/labels/_tests/test_labels.py b/napari/layers/labels/_tests/test_labels.py
--- a/napari/layers/labels/_tests/test_labels.py
+++ b/napari/layers/labels/_tests/test_labels.py
@@ -1120,7 +1120,7 @@ def test_get_value_ray_3d_rolled():
 
 def test_get_value_ray_3d_transposed():
     """Test using _get_value_ray to interrogate labels in 3D
-    with the dimensions trasposed.
+    with the dimensions transposed.
     """
     # make a mock mouse event
     mouse_event = MouseEvent(