From e2415a7af099d16858e1fb4f8979425bc3632478 Mon Sep 17 00:00:00 2001 From: Olivier Jossoud <olivier.jossoud@lsce.ipsl.fr> Date: Thu, 21 Nov 2019 11:28:11 +0100 Subject: [PATCH] Stab. Keep window's view box when changing variable. --- src/uim/explouim.py | 48 +++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/src/uim/explouim.py b/src/uim/explouim.py index f9d36e8..7a59342 100644 --- a/src/uim/explouim.py +++ b/src/uim/explouim.py @@ -623,25 +623,35 @@ class ExploUim: if not is_numeric_dtype(self.stab_timeseries["value"]): self.stab_timeseries["value"] = self.stab_timeseries["value_int"] - # Get the main windows view box - main_range = self.plot_item.getViewBox().viewRange() - - # Place the 2 (right/left) regions - x_min = main_range[0][0] - x_max = main_range[0][1] - x_1_third = x_min + ((x_max - x_min) / 3) - x_2_third = x_min + 2 * ((x_max - x_min) / 3) - self.stab_region_left.setRegion([x_min, x_1_third]) - self.stab_region_right.setRegion([x_2_third, x_max]) - - # Re-calculate the position of the left/right means - self.__update_region_characteristics__(self.stab_region_left, "left") - self.__update_region_characteristics__(self.stab_region_right, "right") - - # X range is the same as main window's plot X range - self.stab_plot_item.getViewBox().setRange(xRange=(main_range[0][0], main_range[0][1]), - yRange=(main_range[1][0], main_range[1][1]), - padding=0) + # If the regions are not yet placed, it means that this function is executed for stabilization window's + # initialization --> use view box of the main window's plot + if self.stab_region_left.getRegion() == (0, 1): + # Get the main windows view box + main_range = self.plot_item.getViewBox().viewRange() + + # Place the 2 (right/left) regions + x_min = main_range[0][0] + x_max = main_range[0][1] + x_1_third = x_min + ((x_max - x_min) / 3) + x_2_third = x_min + 2 * ((x_max - x_min) / 3) + self.stab_region_left.setRegion([x_min, x_1_third]) + self.stab_region_right.setRegion([x_2_third, x_max]) + + # Re-calculate the position of the left/right means + self.__update_region_characteristics__(self.stab_region_left, "left") + self.__update_region_characteristics__(self.stab_region_right, "right") + + # X range is the same as main window's plot X range + self.stab_plot_item.getViewBox().setXRange(min=main_range[0][0], + max=main_range[0][1], + padding=0) + # Otherwise, the function is executed due to a variable change --> keep current viewbox and regions settings. + else: + pass + + self.stab_plot_item.getViewBox().setYRange(min=self.stab_timeseries["value"].min(), + max=self.stab_timeseries["value"].max(), + padding=0) def __update_region_characteristics__(self, region: pg.LinearRegionItem, side: str): df = self.stab_timeseries.copy() -- GitLab