diff --git a/src/View/Results/PlotH.py b/src/View/Results/PlotH.py index a797acf7..2a626a36 100644 --- a/src/View/Results/PlotH.py +++ b/src/View/Results/PlotH.py @@ -51,6 +51,14 @@ class PlotH(PamhyrPlot): self._current_reach_id = reach_id self._current_profile_id = profile_id + self.label_x = _translate("Results", "Time (s)") + self.label_y = _translate("Results", "Discharge (m³/s)") + + self._isometric_axis = False + + self._auto_relim_update = True + self._autoscale_update = True + @property def results(self): return self.data @@ -62,8 +70,7 @@ class PlotH(PamhyrPlot): @timer def draw(self, highlight=None): - self.canvas.axes.cla() - self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5) + self.init_axes() if self.results is None: return @@ -75,87 +82,60 @@ class PlotH(PamhyrPlot): self._init = False return - kp_min, kp_max = (-1, -1) - if highlight is not None: - kp_min, kp_max = highlight + self.draw_max(reach) + self.draw_data(reach, profile) + self.draw_current(reach, profile) - # Axes - self.canvas.axes.set_xlabel( - _translate("Results", "Time (s)"), - color='black', fontsize=10 - ) - self.canvas.axes.set_ylabel( - _translate("Results", "Discharge (m³/s)"), - color='black', fontsize=10 - ) + self.set_ticks_time_formater() + self.idle() + self._init = True + + def draw_data(self, reach, profile): self.ts = list(self.results.get("timestamps")) self.ts.sort() - # Draw discharge for each timestamp x = self.ts y = profile.get_key("Q") self._line, = self.canvas.axes.plot( - x, y, lw=1., - color='r', - markersize=3, marker='+' + x, y, + color=self.color_plot, + **self.plot_default_kargs ) + def draw_current(self, reach, profile): + y = profile.get_key("Q") + + kargs = self.plot_default_kargs.copy() + kargs["marker"] = "o" self._current, = self.canvas.axes.plot( self._current_timestamp, y[self.ts.index(self._current_timestamp)], - lw=1., color='b', - markersize=3, marker='+' + color=self.color_plot_current, + **kargs ) - self.canvas.axes.relim() + def draw_max(self, reach): + self.ts = list(self.results.get("timestamps")) + self.ts.sort() - # Custom time display - nb = len(x) - mod = int(nb / 5) - mod = mod if mod > 0 else nb + x = self.ts + y = [] + for ts in x: + ts_y = -9999 + for profile in reach.profiles: + q = profile.get_ts_key(ts, "Q") + ts_y = max(ts_y, q) + y.append(ts_y) - fx = list( - map( - lambda x: x[1], - filter( - lambda x: x[0] % mod == 0, - enumerate(x) - ) - ) + self._line_max, = self.canvas.axes.plot( + x, y, + color=self.color_plot_highlight, + linestyle='dotted', + **self.plot_default_kargs ) - if self._mode == "time": - t0 = datetime.fromtimestamp(0) - xt = list( - map( - lambda v: ( - str( - datetime.fromtimestamp(v) - t0 - ).split(",")[0] - .replace("days", _translate("Results", "days")) - .replace("day", _translate("Results", "day")) - ), - fx - ) - ) - else: - xt = list( - map( - lambda v: str(datetime.fromtimestamp(v).date()), - fx - ) - ) - - self.canvas.axes.set_xticks(ticks=fx, labels=xt, rotation=45) - - # self.canvas.axes.autoscale_view(True, True, True) - # self.canvas.axes.autoscale() - self.canvas.figure.tight_layout() - self.canvas.figure.canvas.draw_idle() - if self.toolbar is not None: - self.toolbar.update() def set_reach(self, reach_id): self._current_reach_id = reach_id diff --git a/src/View/Results/Window.py b/src/View/Results/Window.py index 7b36c964..7a7c49dd 100644 --- a/src/View/Results/Window.py +++ b/src/View/Results/Window.py @@ -335,7 +335,7 @@ class ResultsWindow(PamhyrWindow): fun = { "reach": self._set_current_reach, "profile": self._set_current_profile, - "raw_data": self._set_current_profile, + "raw_data": self._set_current_profile_raw_data, } for t in ["reach", "profile", "raw_data"]: @@ -375,17 +375,18 @@ class ResultsWindow(PamhyrWindow): self._table["raw_data"].update(ind) def update_table_selection_profile(self, ind): - table = self.find(QTableView, f"tableView_profile") - selectionModel = table.selectionModel() - index = table.model().index(ind, 0) + for t in ["profile", "raw_data"]: + table = self.find(QTableView, f"tableView_{t}") + selectionModel = table.selectionModel() + index = table.model().index(ind, 0) - selectionModel.select( - index, - QItemSelectionModel.Rows | - QItemSelectionModel.ClearAndSelect | - QItemSelectionModel.Select - ) - table.scrollTo(index) + selectionModel.select( + index, + QItemSelectionModel.Rows | + QItemSelectionModel.ClearAndSelect | + QItemSelectionModel.Select + ) + table.scrollTo(index) def update(self, reach_id=None, profile_id=None, timestamp=None): if reach_id is not None: @@ -475,6 +476,16 @@ class ResultsWindow(PamhyrWindow): self.update(profile_id=ind) self._slider_profile.setValue(ind) + def _set_current_profile_raw_data(self): + table = self.find(QTableView, f"tableView_raw_data") + indexes = table.selectedIndexes() + if len(indexes) == 0: + return + + ind = indexes[0].row() + self.update(profile_id=ind) + self._slider_profile.setValue(ind) + def _set_current_profile_slider(self): pid = self._slider_profile.value() self.update(profile_id=pid) diff --git a/src/View/ui/Results.ui b/src/View/ui/Results.ui index 8371b604..bf92cc0d 100644 --- a/src/View/ui/Results.ui +++ b/src/View/ui/Results.ui @@ -145,15 +145,22 @@ - 1 + 0 Raw data - - + + + + + + + + + @@ -232,6 +239,7 @@ false + @@ -251,6 +259,17 @@ Reload + + + Export + + + Export raw data + + + Ctrl+E + +