diff --git a/src/View/Results/PlotXY.py b/src/View/Results/PlotXY.py index 21ba93a4853f90d157b9c7df1a24e6e8d7de2073..2a684fcd6b1badd24155b678734fe41406b82bad 100644 --- a/src/View/Results/PlotXY.py +++ b/src/View/Results/PlotXY.py @@ -133,49 +133,18 @@ class PlotXY(PamhyrPlot): ) self.plot_selected.set_visible(False) - # Display point under water - poly_l_x = [] - poly_l_y = [] - poly_r_x = [] - poly_r_y = [] - for profile in reach.profiles: - water_z = profile.get_ts_key( - self._current_timestamp, "Z" - ) - pgeo = profile.geometry - - x, y = reduce( - lambda acc, pts: (acc[0] + [pts.x], acc[1] + [pts.y]), - filter( - lambda pts: pts.z < water_z, - pgeo.points - ), - ([], []) - ) + poly_x = [0] + poly_y = [0] - poly_l_x.append(x[0]) - poly_l_y.append(y[0]) - poly_r_x.append(x[-1]) - poly_r_y.append(y[-1]) + self.fill = self.canvas.axes.fill(poly_x, poly_y, color='blue', alpha=1) - self.canvas.axes.plot( - x, y, lw=1., - color='b', - markersize=1, - marker='o' - ) - - poly_x = poly_l_x + list(reversed(poly_r_x)) + [poly_l_x[0]] - poly_y = poly_l_y + list(reversed(poly_r_y)) + [poly_l_y[0]] - - self.canvas.axes.fill(poly_x, poly_y, color='blue', alpha=1) - - self.canvas.axes.autoscale_view(True, True, True) - self.canvas.axes.autoscale() + #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() + self.update() def set_reach(self, reach_id): self._current_reach_id = reach_id @@ -184,11 +153,69 @@ class PlotXY(PamhyrPlot): def set_profile(self, profile_id): self._current_profile_id = profile_id - self.draw() + self.update_profile() def set_timestamp(self, timestamp): self._current_timestamp = timestamp - self.draw() + self.update_poly() + + def update_profile(self): + + reach = self.results.river.reach(self._current_reach_id) + if self.display_current: + # Current profile + profile = reach.profile(self._current_profile_id).geometry + + self.plot_selected, = self.canvas.axes.plot( + profile.x(), + profile.y(), + lw=1., markersize=3, + marker='+', color="b" + ) + self.plot_selected.set_visible(False) + self.canvas.draw_idle() + + def update_poly(self): + + reach = self.results.river.reach(self._current_reach_id) + profile = reach.profile(self._current_profile_id).geometry + + # Display water + poly_l_x = [] + poly_l_y = [] + poly_r_x = [] + poly_r_y = [] + for profile in reach.profiles: + water_z = profile.get_ts_key( + self._current_timestamp, "Z" + ) + ptX = profile.get_ts_key( + self._current_timestamp, "ptX" + ) + ptY = profile.get_ts_key( + self._current_timestamp, "ptY" + ) + + poly_l_x.append(ptX.x) + poly_l_y.append(ptX.y) + poly_r_x.append(ptY.x) + poly_r_y.append(ptY.y) + + #self.canvas.axes.plot( + #x, y, lw=1., + #color='b', + #markersize=1, + #marker='o' + #) + + poly_x = poly_l_x + list(reversed(poly_r_x)) + [poly_l_x[0]] + poly_y = poly_l_y + list(reversed(poly_r_y)) + [poly_l_y[0]] + poly = [] + for i in range(len(poly_x)): + poly.append([poly_x[i], poly_y[i]]) + self.fill[0].set_xy(poly) + self.canvas.draw_idle() def update(self): - self.draw() + self.update_profile() + self.update_poly()