Commit 2ba3c16a authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

Results: Add the 2 last plot into results view.

Showing with 228 additions and 10 deletions
+228 -10
...@@ -42,7 +42,7 @@ class PlotDKP(APlot): ...@@ -42,7 +42,7 @@ class PlotDKP(APlot):
return return
self.canvas.axes.set_ylabel( self.canvas.axes.set_ylabel(
_translate("MainWindow_reach", "Draft (m)"), _translate("MainWindow_reach", "Elevation (m)"),
color='green', fontsize=11 color='green', fontsize=11
) )
self.canvas.axes.set_xlabel( self.canvas.axes.set_xlabel(
......
...@@ -15,3 +15,101 @@ ...@@ -15,3 +15,101 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from tools import timer
from View.Plot.APlot import APlot
from PyQt5.QtCore import (
QCoreApplication
)
_translate = QCoreApplication.translate
class PlotAC(APlot):
def __init__(self, canvas=None, results=None,
reach_id=0, profile_id=0,
toolbar=None):
super(PlotAC, self).__init__(
canvas=canvas,
data=results,
toolbar=toolbar
)
self._current_timestamp = max(results.get("timestamps"))
self._current_reach_id = reach_id
self._current_profile_id = profile_id
@property
def results(self):
return self.data
@timer
def draw(self, highlight=None):
self.canvas.axes.cla()
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
if self.results is None:
return
self.canvas.axes.set_xlabel(
_translate("MainWindow_reach", "X (m)"),
color='green', fontsize=11
)
self.canvas.axes.set_ylabel(
_translate("MainWindow_reach", "Elevation (m)"),
color='green', fontsize=11
)
reach = self.results.river.reach(self._current_reach_id)
profile = reach.profile(self._current_profile_id)
x = profile.geometry.get_station()
z = profile.geometry.z()
self.canvas.axes.set_xlim(
left = min(x), right = max(x)
)
self.line_kp, = self.canvas.axes.plot(
x, z,
linestyle="solid",
lw=1.8,
color='grey',
)
kp = reach.geometry.get_kp()
# Water elevation
water_z = profile.get_ts_key(self._current_timestamp, "Z")
self.canvas.axes.plot(
[min(x), max(x)], [water_z, water_z],
lw=1., color='b',
)
x_z = list(map(lambda _: water_z, x))
self.canvas.axes.fill_between(
x, z, water_z,
where=z <= water_z,
color='blue', alpha=0.5, interpolate=True
)
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
self._current_profile_id = 0
self.draw()
def set_profile(self, profile_id):
self._current_profile_id = profile_id
self.draw()
def set_timestamp(self, timestamp):
self._current_timestamp = timestamp
self.draw()
def update(self):
self.draw()
...@@ -15,3 +15,98 @@ ...@@ -15,3 +15,98 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from tools import timer
from View.Plot.APlot import APlot
from PyQt5.QtCore import (
QCoreApplication
)
_translate = QCoreApplication.translate
class PlotKPC(APlot):
def __init__(self, canvas=None, results=None,
reach_id=0, profile_id=0,
toolbar=None):
super(PlotKPC, self).__init__(
canvas=canvas,
data=results,
toolbar=toolbar
)
self._current_timestamp = max(results.get("timestamps"))
self._current_reach_id = reach_id
self._current_profile_id = profile_id
@property
def results(self):
return self.data
@timer
def draw(self, highlight=None):
self.canvas.axes.cla()
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
if self.results is None:
return
reach = self.results.river.reach(self._current_reach_id)
self.canvas.axes.set_ylabel(
_translate("MainWindow_reach", "Elevation (m)"),
color='green', fontsize=11
)
self.canvas.axes.set_xlabel(
_translate("MainWindow_reach", "KP (m)"),
color='green', fontsize=11
)
kp = reach.geometry.get_kp()
z_min = reach.geometry.get_z_min()
self.canvas.axes.set_xlim(
left = min(kp), right = max(kp)
)
self.line_kp_zmin = self.canvas.axes.plot(
kp, z_min,
color='grey', lw=1.
)
if len(reach.geometry.profiles) != 0:
kp = reach.geometry.get_kp()
# Water elevation
water_z = list(
map(
lambda p: p.get_ts_key(self._current_timestamp, "Z"),
reach.profiles
)
)
self.canvas.axes.plot(
kp, water_z, lw=1.,
color='b',
)
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
self._current_profile_id = 0
self.draw()
def set_profile(self, profile_id):
self._current_profile_id = profile_id
self.draw()
def set_timestamp(self, timestamp):
self._current_timestamp = timestamp
self.draw()
def update(self):
self.draw()
...@@ -88,7 +88,7 @@ class PlotXY(APlot): ...@@ -88,7 +88,7 @@ class PlotXY(APlot):
self.line_xy = [ self.line_xy = [
self.canvas.axes.plot( self.canvas.axes.plot(
x, y, lw=1., x, y, lw=1.,
color='b' if kp_min <= kp <= kp_max else 'r', color='b' if kp_min <= kp <= kp_max else 'grey',
markersize=3, marker='+' markersize=3, marker='+'
) )
for x, y, kp in zip( for x, y, kp in zip(
......
...@@ -43,6 +43,9 @@ from PyQt5.QtWidgets import ( ...@@ -43,6 +43,9 @@ from PyQt5.QtWidgets import (
from View.Plot.MplCanvas import MplCanvas from View.Plot.MplCanvas import MplCanvas
from View.Results.PlotXY import PlotXY from View.Results.PlotXY import PlotXY
from View.Results.PlotAC import PlotAC
from View.Results.PlotKPC import PlotKPC
from View.Results.Table import TableModel from View.Results.Table import TableModel
from View.Results.translate import * from View.Results.translate import *
from View.Stricklers.Window import StricklersWindow from View.Stricklers.Window import StricklersWindow
...@@ -112,9 +115,11 @@ class ResultsWindow(ASubMainWindow, ListedSubWindow): ...@@ -112,9 +115,11 @@ class ResultsWindow(ASubMainWindow, ListedSubWindow):
self._slider_profile = self.find(QSlider, f"verticalSlider_profile") self._slider_profile = self.find(QSlider, f"verticalSlider_profile")
default_reach = self._results.river.reach(0) default_reach = self._results.river.reach(0)
self._slider_profile.setMaximum(len(default_reach.profiles) - 1) self._slider_profile.setMaximum(len(default_reach.profiles) - 1)
self._slider_profile.setValue(0)
self._slider_time = self.find(QSlider, f"horizontalSlider_time") self._slider_time = self.find(QSlider, f"horizontalSlider_time")
self._slider_time.setMaximum(len(self._timestamps) - 1) self._slider_time.setMaximum(len(self._timestamps) - 1)
self._slider_time.setValue(len(self._timestamps) - 1)
def setup_graph(self): def setup_graph(self):
self.canvas = MplCanvas(width=5, height=4, dpi=100) self.canvas = MplCanvas(width=5, height=4, dpi=100)
...@@ -137,18 +142,28 @@ class ResultsWindow(ASubMainWindow, ListedSubWindow): ...@@ -137,18 +142,28 @@ class ResultsWindow(ASubMainWindow, ListedSubWindow):
self.plot_layout_2 = self.find(QVBoxLayout, "verticalLayout_2") self.plot_layout_2 = self.find(QVBoxLayout, "verticalLayout_2")
self.plot_layout_2.addWidget(self.canvas_2) self.plot_layout_2.addWidget(self.canvas_2)
# self.plot_2 = PlotStricklers( self.plot_kpc = PlotKPC(
# canvas = self.canvas_2, canvas = self.canvas_2,
# data = self._reach, results = self._results,
# toolbar = None reach_id = 0,
# ) profile_id = 0,
# self.plot_2.draw() toolbar = None
)
self.plot_kpc.draw()
self.canvas_3 = MplCanvas(width=5, height=4, dpi=100) self.canvas_3 = MplCanvas(width=5, height=4, dpi=100)
self.canvas_3.setObjectName("canvas_3") self.canvas_3.setObjectName("canvas_3")
self.plot_layout_3 = self.find(QVBoxLayout, "verticalLayout_3") self.plot_layout_3 = self.find(QVBoxLayout, "verticalLayout_3")
self.plot_layout_3.addWidget(self.canvas_3) self.plot_layout_3.addWidget(self.canvas_3)
self.plot_ac = PlotAC(
canvas = self.canvas_3,
results = self._results,
reach_id = 0,
profile_id = 0,
toolbar = None
)
self.plot_ac.draw()
def setup_connections(self): def setup_connections(self):
self.undo_sc.activated.connect(self.undo) self.undo_sc.activated.connect(self.undo)
...@@ -177,25 +192,35 @@ class ResultsWindow(ASubMainWindow, ListedSubWindow): ...@@ -177,25 +192,35 @@ class ResultsWindow(ASubMainWindow, ListedSubWindow):
def update(self, reach_id = None, profile_id = None, timestamp = None): def update(self, reach_id = None, profile_id = None, timestamp = None):
if reach_id is not None: if reach_id is not None:
self.plot_xy.set_reach(reach_id) self.plot_xy.set_reach(reach_id)
self.plot_ac.set_reach(reach_id)
self.plot_kpc.set_reach(reach_id)
if profile_id is not None: if profile_id is not None:
self.plot_xy.set_profile(profile_id) self.plot_xy.set_profile(profile_id)
self.plot_ac.set_profile(profile_id)
self.plot_kpc.set_profile(profile_id)
if timestamp is not None: if timestamp is not None:
self.plot_xy.set_timestamp(timestamp) self.plot_xy.set_timestamp(timestamp)
self.plot_ac.set_timestamp(timestamp)
self.plot_kpc.set_timestamp(timestamp)
self.plot_xy.draw() self.plot_xy.draw()
self.plot_ac.draw()
self.plot_kpc.draw()
def _set_current_reach(self): def _set_current_reach(self):
table = self.find(QTableView, f"tableView_reach") table = self.find(QTableView, f"tableView_reach")
indexes = table.selectedIndexes() indexes = table.selectedIndexes()
self.update(reach_id = indexes[0]) self.update(reach_id = indexes[0].row())
def _set_current_profile(self): def _set_current_profile(self):
table = self.find(QTableView, f"tableView_profile") table = self.find(QTableView, f"tableView_profile")
indexes = table.selectedIndexes() indexes = table.selectedIndexes()
self.update(profile_id = indexes[0]) ind = indexes[0].row()
self.update(profile_id = ind)
self._slider_profile.setValue(ind)
def _set_current_profile_slider(self): def _set_current_profile_slider(self):
pid = self._slider_profile.value() pid = self._slider_profile.value()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment