From 363c348a64ed68730d2eb2a1fe3b10afa91af1fc Mon Sep 17 00:00:00 2001 From: ldam <ldam@passcal.nmt.edu> Date: Mon, 24 Jun 2024 10:42:27 -0600 Subject: [PATCH] zoom out in TPS --- .../plotting_widget/plotting_widget.py | 18 ++++++------- .../time_power_squared_widget.py | 26 ++++++++++++++++--- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/sohstationviewer/view/plotting/plotting_widget/plotting_widget.py b/sohstationviewer/view/plotting/plotting_widget/plotting_widget.py index 3681a34f..54de2d0b 100644 --- a/sohstationviewer/view/plotting/plotting_widget/plotting_widget.py +++ b/sohstationviewer/view/plotting/plotting_widget/plotting_widget.py @@ -496,9 +496,9 @@ class PlottingWidget(QtWidgets.QScrollArea): When click mouse on the current plottingWidget, SOHView will loop through different plottingWidgets to do the same task for interaction: - + shift+click: call on_shift_click() to do zooming. This is - disregarded in TimePowerSquareWidget because it isn't subjected - to be zoomed in. + + shift+click: is disregarded if start in TimePowerSquareWidget + * If click on left side of the plot (xdata<xmin): call zoom out + * Otherwise: call on_shift_click to do tasks of zoom in + ctrl+click or cmd+click in mac: call on_ctrl_cmd_click() to show ruler @@ -556,7 +556,12 @@ class PlottingWidget(QtWidgets.QScrollArea): except AttributeError: pass if modifiers == QtCore.Qt.KeyboardModifier.ShiftModifier: - w.on_shift_click(xdata) + if xdata < w.min_x: + # click on left of plot + w.zoom_marker1_shown = False # reset zoom in + w.zoom_out() + else: + w.on_shift_click(xdata) elif modifiers in [QtCore.Qt.KeyboardModifier.ControlModifier, QtCore.Qt.KeyboardModifier.MetaModifier]: w.on_ctrl_cmd_click(xdata) @@ -617,11 +622,6 @@ class PlottingWidget(QtWidgets.QScrollArea): :param xdata: float - time value of a channel plot """ - if xdata < self.min_x: - # click on left of plot - self.zoom_marker1_shown = False # reset zoom in - self.zoom_out() - return if not self.zoom_marker1_shown: self.ruler.set_visible(False) self.set_ruler_visibled(self.zoom_marker1, xdata) diff --git a/sohstationviewer/view/plotting/time_power_square/time_power_squared_widget.py b/sohstationviewer/view/plotting/time_power_square/time_power_squared_widget.py index 733d5684..6de150a0 100644 --- a/sohstationviewer/view/plotting/time_power_square/time_power_squared_widget.py +++ b/sohstationviewer/view/plotting/time_power_square/time_power_squared_widget.py @@ -579,6 +579,16 @@ class TimePowerSquaredWidget(plotting_widget.PlottingWidget): self.set_lim_markers() self.zoom_marker1_shown = False + def zoom_out(self): + """ + Zoom out by setting limit to the previous range when there's at least + one zoom-in. + """ + if len(self.zoom_minmax_list) > 1: + self.min_x, self.max_x = self.zoom_minmax_list[-2] + self.zoom_minmax_list.pop() + self.set_lim_markers(is_zoom_in=False) + def set_rulers_invisible(self): """ Clear data for self.rulers to make them disappeared. @@ -586,12 +596,20 @@ class TimePowerSquaredWidget(plotting_widget.PlottingWidget): for rl in self.rulers: rl.set_data([], []) - def set_lim_markers(self): + def set_lim_markers(self, is_zoom_in=True): """ - Find x index (which index in five minutes of a day) and - y index (which day) of self.min_x and self.min_y, and set data for - all markers in self.zoom_marker1s and self.zoom_marker2s. + + Append to zoom_minmax_list if called from a zoom_in. First time + plotting is considered a zoom_in to create first x range in the list. + + + Find x index (which index in five minutes of a day) and + y index (which day) of self.min_x and self.min_y, and set data for + all markers in self.zoom_marker1s and self.zoom_marker2s. + + :param is_zoom_in: if set_lim comes from zoom_in task """ + if is_zoom_in: + self.zoom_minmax_list.append((self.min_x, self.max_x)) + five_minute_idx, day_idx = find_tps_tm_idx(self.min_x, self.start_5min_blocks, self.start_first_day) -- GitLab