diff --git a/src/ndv/viewer/_viewer.py b/src/ndv/viewer/_viewer.py index daa46fcb..0ce01b5f 100755 --- a/src/ndv/viewer/_viewer.py +++ b/src/ndv/viewer/_viewer.py @@ -299,6 +299,11 @@ def set_data( # store the data self._data_wrapper: DataWrapper = DataWrapper.create(data) # type: ignore + # update the range of all the sliders to match the sizes we set above + maxes = self._data_wrapper.sizes() + with signals_blocked(self._dims_sliders): + self._dims_sliders.setMaxima({k: v - 1 for k, v in maxes.items()}) + # update the dimensions we are visualizing sizes = dict(self._data_wrapper.sizes().items()) @@ -318,10 +323,6 @@ def set_data( # By convention, visualize the final dimensions self.set_visualized_dims(visualized_dims[-self._ndims :]) - # update the range of all the sliders to match the sizes we set above - with signals_blocked(self._dims_sliders): - self._update_slider_ranges() - # redraw if initial_index is None: idx = self._dims_sliders.value() or { @@ -372,6 +373,11 @@ def set_visualized_dims(self, dims: Iterable[DimKey]) -> None: self._dims_sliders.set_dimension_visible(d, d not in self._visualized_dims) for d in self._visualized_dims: self._dims_sliders.set_dimension_visible(d, False) + if self._channel_axis is not None: + self._dims_sliders.set_dimension_visible( + self._channel_axis, + self._channel_mode not in [ChannelMode.COMPOSITE, ChannelMode.RGBA], + ) def set_ndim(self, ndim: Literal[2, 3]) -> None: """Set the number of dimensions to display.""" @@ -486,27 +492,6 @@ def _toggle_3d(self) -> None: if self._roi: self._roi.visible = self._ndims == 2 - def _update_slider_ranges(self) -> None: - """Set the maximum values of the sliders. - - If `sizes` is not provided, sizes will be inferred from the datastore. - """ - if self._data_wrapper is None: - return - - maxes = self._data_wrapper.sizes() - self._dims_sliders.setMaxima({k: v - 1 for k, v in maxes.items()}) - - # FIXME: this needs to be moved and made user-controlled - for dim in self._visualized_dims: - self._dims_sliders.set_dimension_visible(dim, False) - - if self._channel_axis is not None: - self._dims_sliders.set_dimension_visible( - self._channel_axis, - self._channel_mode not in [ChannelMode.RGBA, ChannelMode.COMPOSITE], - ) - def _on_set_range_clicked(self) -> None: # using method to swallow the parameter passed by _set_range_btn.clicked self._canvas.set_range()