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):
return
self.canvas.axes.set_ylabel(
_translate("MainWindow_reach", "Draft (m)"),
_translate("MainWindow_reach", "Elevation (m)"),
color='green', fontsize=11
)
self.canvas.axes.set_xlabel(
......
......@@ -15,3 +15,101 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# -*- 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 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# -*- 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):
self.line_xy = [
self.canvas.axes.plot(
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='+'
)
for x, y, kp in zip(
......
......@@ -43,6 +43,9 @@ from PyQt5.QtWidgets import (
from View.Plot.MplCanvas import MplCanvas
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.translate import *
from View.Stricklers.Window import StricklersWindow
......@@ -112,9 +115,11 @@ class ResultsWindow(ASubMainWindow, ListedSubWindow):
self._slider_profile = self.find(QSlider, f"verticalSlider_profile")
default_reach = self._results.river.reach(0)
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.setMaximum(len(self._timestamps) - 1)
self._slider_time.setValue(len(self._timestamps) - 1)
def setup_graph(self):
self.canvas = MplCanvas(width=5, height=4, dpi=100)
......@@ -137,18 +142,28 @@ class ResultsWindow(ASubMainWindow, ListedSubWindow):
self.plot_layout_2 = self.find(QVBoxLayout, "verticalLayout_2")
self.plot_layout_2.addWidget(self.canvas_2)
# self.plot_2 = PlotStricklers(
# canvas = self.canvas_2,
# data = self._reach,
# toolbar = None
# )
# self.plot_2.draw()
self.plot_kpc = PlotKPC(
canvas = self.canvas_2,
results = self._results,
reach_id = 0,
profile_id = 0,
toolbar = None
)
self.plot_kpc.draw()
self.canvas_3 = MplCanvas(width=5, height=4, dpi=100)
self.canvas_3.setObjectName("canvas_3")
self.plot_layout_3 = self.find(QVBoxLayout, "verticalLayout_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):
self.undo_sc.activated.connect(self.undo)
......@@ -177,25 +192,35 @@ class ResultsWindow(ASubMainWindow, ListedSubWindow):
def update(self, reach_id = None, profile_id = None, timestamp = None):
if reach_id is not None:
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:
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:
self.plot_xy.set_timestamp(timestamp)
self.plot_ac.set_timestamp(timestamp)
self.plot_kpc.set_timestamp(timestamp)
self.plot_xy.draw()
self.plot_ac.draw()
self.plot_kpc.draw()
def _set_current_reach(self):
table = self.find(QTableView, f"tableView_reach")
indexes = table.selectedIndexes()
self.update(reach_id = indexes[0])
self.update(reach_id = indexes[0].row())
def _set_current_profile(self):
table = self.find(QTableView, f"tableView_profile")
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):
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