From f00f0f6878bcd93595c62db5531c5defecb24709 Mon Sep 17 00:00:00 2001 From: Olivier Jossoud <olivier.jossoud@lsce.ipsl.fr> Date: Fri, 22 Nov 2019 09:40:22 +0100 Subject: [PATCH] Stab. Keep window's view box when changing variable. --- src/uim/explouim.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/uim/explouim.py b/src/uim/explouim.py index 7a59342..d2cb9d2 100644 --- a/src/uim/explouim.py +++ b/src/uim/explouim.py @@ -637,22 +637,23 @@ class ExploUim: 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().disableAutoRange() 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) + # 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") + def __update_region_characteristics__(self, region: pg.LinearRegionItem, side: str): df = self.stab_timeseries.copy() @@ -666,8 +667,23 @@ class ExploUim: # Compute x_value's average and standard deviation over the selected region. mean = inside_values.mean() sd = inside_values.std() + + # Hide InfiniteLines if it is not possible to calculate any region's average. if math.isnan(mean): + self.stab_high_hline.hide() + self.stab_low_hline.hide() + self.stab_high_vline.hide() + self.stab_low_vline.hide() + self.stab_left_mean_line.hide() + self.stab_right_mean_line.hide() return + else: + self.stab_high_hline.show() + self.stab_low_hline.show() + self.stab_high_vline.show() + self.stab_low_vline.show() + self.stab_left_mean_line.show() + self.stab_right_mean_line.show() # Update UI's text zones getattr(self.stab_window.ui, "stab_lineedit_"+side+"_mean").setText("{:.3f}".format(mean)) -- GitLab