Skip to content
This repository has been archived by the owner on Jul 22, 2021. It is now read-only.

Commit

Permalink
Merge pull request #590 from nmearl/fix-autorange-with-labels
Browse files Browse the repository at this point in the history
Fix autorange with labels
  • Loading branch information
nmearl committed Nov 30, 2018
2 parents ba3b357 + 43e0959 commit 46d4ed6
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions specviz/widgets/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import qtawesome as qta
from qtpy.QtCore import Signal, QEvent
from qtpy.QtWidgets import (QColorDialog, QMainWindow, QMdiSubWindow,
QMessageBox, QErrorMessage, QWidget)
QMessageBox, QErrorMessage, QApplication)
from qtpy.uic import loadUi

from astropy.units import Quantity
Expand Down Expand Up @@ -60,7 +60,7 @@ def __init__(self, model, *args, **kwargs):
self._on_line_labels)

self._central_widget.reset_view_action.triggered.connect(
lambda: self.plot_widget.autoRange())
self._on_reset_view)

@property
def tool_bar(self):
Expand All @@ -82,6 +82,17 @@ def proxy_model(self):
def _on_current_item_changed(self, current_idx, prev_idx):
self._current_item_index = current_idx

def _on_reset_view(self):
"""
Resets the visible range of the plot taking into consideration only the
PlotDataItem objects currently attached.
"""
self.plot_widget.autoRange(
items=[item for item in self.plot_widget.listDataItems()
if isinstance(item, PlotDataItem)])

self.plot_widget.sigRangeChanged.emit(*self.plot_widget.viewRange())

def _on_change_color(self):
"""
Listens for color changed events in plot windows, gets the currently
Expand Down Expand Up @@ -620,7 +631,11 @@ def _show_linelists_window(self, *args, **kwargs):
self.linelist_window = LineListsWindow(self)
self.line_labels_plotter = LineLabelsPlotter(self)

self.sigRangeChanged.connect(self.line_labels_plotter.process_zoom_signal)
self.sigRangeChanged.connect(
self.line_labels_plotter.process_zoom_signal)
self.sigRangeChanged.connect(
lambda: self.line_labels_plotter._handle_mouse_events(
QEvent.Enter))

self.linelist_window.show()

Expand Down

0 comments on commit 46d4ed6

Please sign in to comment.