From c3954208a601438f05071d8273b4f3f46d7b5d1e Mon Sep 17 00:00:00 2001
From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr>
Date: Wed, 19 Apr 2023 13:49:14 +0200
Subject: [PATCH] geometry: Fix index 0 on plot and minor change.

---
 src/View/Geometry/GeometryWindow.py | 24 ++++++++++++------------
 src/View/Geometry/PlotAC.py         |  2 +-
 src/View/Geometry/PlotKPC.py        |  2 +-
 src/View/Geometry/PlotXY.py         |  6 +++---
 4 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/src/View/Geometry/GeometryWindow.py b/src/View/Geometry/GeometryWindow.py
index f466febd..ffdc1eb8 100644
--- a/src/View/Geometry/GeometryWindow.py
+++ b/src/View/Geometry/GeometryWindow.py
@@ -281,16 +281,20 @@ class GeometryWindow(QMainWindow, WindowToolKit):
     def get_elevation(self, ind: int):
         return self._reach.profile(ind).z()
 
-    def select_plot_plot_xy(self, ind: int):
+    def select_plot_xy(self, ind: int):
         self.tableView.model().blockSignals(True)
         self._plot_xy.update(ind=ind)
         self.tableView.model().blockSignals(False)
 
-    def select_plot_plot_kpc(self, ind: int):
+    def select_plot_kpc(self, ind: int):
         self.tableView.model().blockSignals(True)
         self._plot_kpc.update(ind=ind)
         self.tableView.model().blockSignals(False)
 
+    def select_plot_ac(self, ind: int):
+        self.tableView.model().blockSignals(True)
+        self._plot_ac.update(ind=ind)
+        self.tableView.model().blockSignals(False)
 
     def select_row_profile_slider(self, ind: int = 0):
         if self.tableView is not None:
@@ -313,15 +317,11 @@ class GeometryWindow(QMainWindow, WindowToolKit):
             row = self.index_selected_row()
 
             self.ui.verticalSlider.setValue(row)
-            self.select_plot_plot_xy(row)
-            self.select_plot_plot_kpc(row)
+            self.select_plot_xy(row)
+            self.select_plot_kpc(row)
+            self.select_plot_ac(row)
 
-            self._plot_xy.update(ind = row)
-            self._plot_kpc.update(ind = row)
-
-            self.tableView.model().blockSignals(False)
-            self.update_plot_ac(row)
-            self.ui.canvas_2.figure.canvas.draw_idle()
+        self.tableView.model().blockSignals(False)
 
     def changed_slider_value(self):
         self.tableView.model().blockSignals(True)
@@ -340,8 +340,8 @@ class GeometryWindow(QMainWindow, WindowToolKit):
                 f"{slider_value + 1}"
             )
 
-            self.select_plot_plot_xy(slider_value)
-            self.select_plot_plot_kpc(slider_value)
+            self.select_plot_xy(slider_value)
+            self.select_plot_kpc(slider_value)
             self.select_row_profile_slider(slider_value)
 
         self.tableView.model().blockSignals(False)
diff --git a/src/View/Geometry/PlotAC.py b/src/View/Geometry/PlotAC.py
index f4dd768e..1dfb9bbc 100644
--- a/src/View/Geometry/PlotAC.py
+++ b/src/View/Geometry/PlotAC.py
@@ -285,7 +285,7 @@ class PlotAC(APlot):
 
     @timer
     def update(self, ind=None):
-        if ind:
+        if ind is not None:
             before = ind - 1
             after = ind + 1
 
diff --git a/src/View/Geometry/PlotKPC.py b/src/View/Geometry/PlotKPC.py
index 690367cf..8a5d7364 100644
--- a/src/View/Geometry/PlotKPC.py
+++ b/src/View/Geometry/PlotKPC.py
@@ -94,7 +94,7 @@ class PlotKPC(APlot):
 
     @timer
     def update(self, ind=None):
-        if ind:
+        if ind is not None:
             before = ind - 1
             after = ind + 1
 
diff --git a/src/View/Geometry/PlotXY.py b/src/View/Geometry/PlotXY.py
index 2d7b6ed0..7e182447 100644
--- a/src/View/Geometry/PlotXY.py
+++ b/src/View/Geometry/PlotXY.py
@@ -93,7 +93,7 @@ class PlotXY(APlot):
 
     @timer
     def update(self, ind=None):
-        if ind:
+        if ind is not None:
             before = ind - 1
             after = ind + 1
 
@@ -116,7 +116,6 @@ class PlotXY(APlot):
                                                   self.data.profile(after).y())
                 self.after_plot_selected.set_visible(True)
 
-            self.canvas.figure.canvas.draw_idle()
         else:
             for ind in range(self.data.number_profiles):
                 self.line_xy[ind][0].set_data(
@@ -133,4 +132,5 @@ class PlotXY(APlot):
                     [y[i] for y in y_complete]
                 )
 
-            self.canvas.figure.canvas.draw_idle()
+        self.canvas.figure.tight_layout()
+        self.canvas.figure.canvas.draw_idle()
-- 
GitLab