Skip to content

Commit

Permalink
Merge pull request #254 from BiAPoL/fix_reset_zoom
Browse files Browse the repository at this point in the history
Fix reset zoom
  • Loading branch information
haesleinhuepf authored May 11, 2023
2 parents b23ff77 + 683e64a commit 808ff46
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions napari_clusters_plotter/_Qt_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ def __init__(self, parent=None, width=7, height=4, manual_clustering_method=None

self.match_napari_layout()
self.xylim = None
self.last_xy_labels = None

super().__init__(self.fig)
self.mpl_connect("draw_event", self.on_draw)
Expand Down Expand Up @@ -554,6 +555,7 @@ def reset_zoom(self):
self.axes.set_ylim(self.xylim[1])

def on_draw(self, event):
self.last_xy_labels = (self.axes.get_xlabel(), self.axes.get_ylabel())
self.xylim = (self.axes.get_xlim(), self.axes.get_ylim())

def draw_rectangle(self, eclick, erelease):
Expand Down
7 changes: 6 additions & 1 deletion napari_clusters_plotter/_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,11 @@ def run(
self.graphics_widget.axes.set_ylabel(plot_y_axis_name)

self.graphics_widget.match_napari_layout()
self.graphics_widget.draw()

if self.graphics_widget.last_xy_labels != (plot_x_axis_name, plot_y_axis_name):
# Additional redraw in case axis have changed, otherwise y-axis may not get updated. General redraw would
# resets the zoom, which needs to be avoided.
self.graphics_widget.draw()

self.graphics_widget.draw() # Always redraws, oterwise y-axis may not get updated in histograms
self.graphics_widget.reset_zoom()

0 comments on commit 808ff46

Please sign in to comment.