# -*- coding: utf-8 -*- from tools import timer, flatten from View.Plot.APlot import APlot from PyQt5.QtCore import ( QCoreApplication ) _translate = QCoreApplication.translate class PlotStricklers(APlot): def __init__(self, canvas=None, data=None, toolbar=None): super(PlotStricklers, self).__init__( canvas=canvas, data=data, toolbar=toolbar ) def draw_frictions(self, frictions, color="r"): lst = frictions lst.sort(key = lambda s: s.begin_kp) coef = flatten( map( lambda s: [s.begin_strickler, s.end_strickler], lst ) ) kp = flatten( map( lambda s: [s.begin_kp, s.end_kp], lst ) ) coef_minor = list(map(lambda s: s.minor, coef)) coef_medium = list(map(lambda s: s.medium, coef)) self.line_kp_elevation = self.canvas.axes.plot( kp, coef_minor, color=color, lw=1. ) self.line_kp_elevation = self.canvas.axes.plot( kp, coef_medium, color=color, lw=1. ) @timer def draw(self, highlight=None): self.canvas.axes.cla() self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5) if self.data is None: return self.canvas.axes.set_ylabel( _translate("MainWindow_reach", "Stricklers"), color='green', fontsize=11 ) self.canvas.axes.set_xlabel( _translate("MainWindow_reach", "Kp (m)"), color='green', fontsize=11 ) kp = self.data.reach.get_kp() self.canvas.axes.set_xlim( left = min(kp), right = max(kp) ) frictions = self.data.frictions if len(frictions) != 0: lst = frictions.frictions self.draw_frictions(lst) # HightLight kp_min, kp_max = (-1, -1) if highlight is not None: kp_min, kp_max = highlight lst = list( filter( lambda s: (s.begin_kp == kp_min and s.end_kp == kp_max), frictions.frictions ) ) self.draw_frictions(lst, color="b") 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 self._init == False: self.draw() return