From e4670e4a4da6070acc02a70e316a0981e0a5fd19 Mon Sep 17 00:00:00 2001
From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr>
Date: Mon, 18 Dec 2023 15:28:22 +0100
Subject: [PATCH] Results: Add current timestamps on hydrograph.

---
 src/View/Results/PlotH.py  | 40 ++++++++++++++++++++------------------
 src/View/Results/Window.py |  2 +-
 2 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/src/View/Results/PlotH.py b/src/View/Results/PlotH.py
index 3494cfa5..f236bf8f 100644
--- a/src/View/Results/PlotH.py
+++ b/src/View/Results/PlotH.py
@@ -92,31 +92,24 @@ class PlotH(PamhyrPlot):
         self.ts = list(self.results.get("timestamps"))
         self.ts.sort()
 
-        self.canvas.axes.set_xlim(
-            left=min(self.ts), right=max(self.ts)
-        )
-
         # Draw discharge for each timestamp
         x = self.ts
         y = profile.get_key("Q")
 
-        if len(self.ts) != len(x):
-            logger.warning(
-                "Results as less Q data ({len(x)}) " +
-                "than timestamps ({len(self.ts)}) " +
-                "for profile {self._current_profile_id}"
-            )
-            return
+        self._line, = self.canvas.axes.plot(
+            x, y, lw=1.,
+            color='r',
+            markersize=3, marker='+'
+        )
 
-        self.canvas.axes.set_ylim(
-            [min(min(y), 0), max(y) + 10]
+        self._current, = self.canvas.axes.plot(
+            self._current_timestamp,
+            y[self.ts.index(self._current_timestamp)],
+            lw=1., color='b',
+            markersize=3, marker='+'
         )
 
-        self._line, = self.canvas.axes.plot(
-                x, y, lw=1.,
-                color='r',
-                markersize=3, marker='+'
-            )
+        self.canvas.axes.relim()
 
         # Custom time display
         nb = len(x)
@@ -175,12 +168,21 @@ class PlotH(PamhyrPlot):
 
     def set_timestamp(self, timestamp):
         self._current_timestamp = timestamp
-        # self.update()
+        self.update()
 
     def update(self):
         reach = self.results.river.reach(self._current_reach_id)
         profile = reach.profile(self._current_profile_id)
+
         x = self.ts
         y = profile.get_key("Q")
+
         self._line.set_data(x, y)
+
+        self._current.set_data(
+            self._current_timestamp,
+            y[self.ts.index(self._current_timestamp)]
+        )
+
+        self.canvas.axes.relim()
         self.canvas.figure.canvas.draw_idle()
diff --git a/src/View/Results/Window.py b/src/View/Results/Window.py
index 68a38b34..75e95f21 100644
--- a/src/View/Results/Window.py
+++ b/src/View/Results/Window.py
@@ -396,7 +396,7 @@ class ResultsWindow(PamhyrWindow):
             self.plot_xy.set_timestamp(timestamp)
             self.plot_ac.set_timestamp(timestamp)
             self.plot_kpc.set_timestamp(timestamp)
-            # self.plot_h.set_timestamp(timestamp)
+            self.plot_h.set_timestamp(timestamp)
 
             if self._study.river.has_sediment():
                 self.plot_sed_reach.set_timestamp(timestamp)
-- 
GitLab