Skip to content

Commit

Permalink
fix(interactive.imagetool): scale spinbox decimals relative to coordi…
Browse files Browse the repository at this point in the history
…nate step size
  • Loading branch information
kmnhan committed Aug 28, 2024
1 parent 0a70884 commit 9a801a5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/erlab/interactive/imagetool/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ def update_content(self) -> None:
self.spin_val[i].setRange(*self.array_slicer.lims[i])
self.spin_val[i].setSingleStep(self.array_slicer.incs[i])
self.spin_val[i].setValue(self.slicer_area.get_current_value(i))
self.spin_val[i].setDecimals(self.array_slicer.get_significant(i))

self.label_dim[i].blockSignals(False)
self.spin_idx[i].blockSignals(False)
Expand Down
5 changes: 5 additions & 0 deletions src/erlab/interactive/imagetool/slicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@ def values_of_dim(self, dim: Hashable) -> npt.NDArray[np.float32]:
"""
return self._obj._coords[dim]._data.array._data # type: ignore[union-attr]

def get_significant(self, axis: int) -> int:
"""Return the number of significant digits for a given axis."""
step = self.incs[axis]
return int(np.clip(np.ceil(-np.log10(abs(step)) + 1), 0, None))

def add_cursor(self, like_cursor: int = -1, update: bool = True) -> None:
self._bins.append(list(self.get_bins(like_cursor)))
new_ind = self.get_indices(like_cursor)
Expand Down

0 comments on commit 9a801a5

Please sign in to comment.