mirror of https://gitlab.com/pamhyr/pamhyr2
102 lines
2.5 KiB
Python
102 lines
2.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
import logging
|
|
|
|
from functools import reduce
|
|
|
|
from tools import timer
|
|
from View.Tools.PamhyrPlot import PamhyrPlot
|
|
|
|
from PyQt5.QtCore import (
|
|
QCoreApplication
|
|
)
|
|
|
|
_translate = QCoreApplication.translate
|
|
|
|
logger = logging.getLogger()
|
|
|
|
|
|
class Plot(PamhyrPlot):
|
|
def __init__(self, data=None, display_current=True,
|
|
canvas=None, trad=None, toolbar=None,
|
|
parent=None):
|
|
super(Plot, self).__init__(
|
|
canvas=canvas,
|
|
trad=trad,
|
|
data=data,
|
|
toolbar=toolbar,
|
|
parent=parent
|
|
)
|
|
|
|
self._display_current = display_current
|
|
|
|
self.line_kp_zmin = None
|
|
self.line_kp_sl = []
|
|
|
|
@timer
|
|
def draw(self):
|
|
self.canvas.axes.cla()
|
|
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
|
|
|
|
if self.data is None:
|
|
return
|
|
|
|
if self.data.number_points == 0:
|
|
return
|
|
|
|
self.canvas.axes.set_xlabel(
|
|
_translate("MainWindow_reach", "X (m)"),
|
|
color='green', fontsize=10
|
|
)
|
|
self.canvas.axes.set_ylabel(
|
|
_translate("MainWindow_reach", "Height (m)"),
|
|
color='green', fontsize=10
|
|
)
|
|
|
|
x = self.data.get_station()
|
|
z = self.data.z()
|
|
sl = self.data.get_sl()
|
|
|
|
self.canvas.axes.set_xlim(
|
|
left=min(x), right=max(x)
|
|
)
|
|
|
|
# Compute sediment layer in function to point z
|
|
z_sl = reduce(
|
|
lambda acc, v: acc + [
|
|
list(
|
|
map(lambda x, y: y - x, v, acc[-1])
|
|
)
|
|
],
|
|
sl,
|
|
[z]
|
|
)
|
|
|
|
for i, zsl in enumerate(reversed(z_sl)):
|
|
self.line_kp_sl.append(None)
|
|
self.line_kp_sl[i], = self.canvas.axes.plot(
|
|
x, zsl,
|
|
linestyle="solid" if i == len(z_sl) - 1 else "--",
|
|
lw=1.8,
|
|
color='grey' if i == len(z_sl) - 1 else None
|
|
)
|
|
|
|
self.canvas.figure.tight_layout()
|
|
self.canvas.figure.canvas.draw_idle()
|
|
if self.toolbar is not None:
|
|
self.toolbar.update()
|
|
|
|
self._init = True
|
|
|
|
@timer
|
|
def update(self, ind=None):
|
|
if not self._init:
|
|
self.draw()
|
|
return
|
|
|
|
if ind is None:
|
|
logger.info("TODO: Update")
|
|
|
|
self.canvas.axes.autoscale_view(True, True, True)
|
|
self.canvas.figure.canvas.draw_idle()
|