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

LC: Update plot with PmahyrPlot new features.

Showing with 42 additions and 77 deletions
+42 -77
......@@ -27,8 +27,6 @@ from PyQt5.QtCore import (
QCoreApplication
)
from View.BoundaryCondition.Edit.translate import BCETranslate
_translate = QCoreApplication.translate
logger = logging.getLogger()
......@@ -55,6 +53,8 @@ class Plot(PamhyrPlot):
self._mode = mode
self._isometric_axis = False
self._auto_relim_update = True
self._autoscale_update = True
def custom_ticks(self):
if self.data.header[0] != "time":
......@@ -94,7 +94,6 @@ class Plot(PamhyrPlot):
return
self.update_data()
self.custom_ticks()
self.update_idle()
......
......@@ -16,6 +16,8 @@
# -*- coding: utf-8 -*-
import logging
from datetime import datetime
from tools import timer, trace
......@@ -25,14 +27,14 @@ from PyQt5.QtCore import (
QCoreApplication
)
from View.LateralContribution.Edit.translate import *
_translate = QCoreApplication.translate
logger = logging.getLogger()
class Plot(PamhyrPlot):
def __init__(self, mode="time", data=None,
canvas=None, trad=None, toolbar=None,
trad=None, canvas=None, toolbar=None,
parent=None):
super(Plot, self).__init__(
canvas=canvas,
......@@ -43,99 +45,60 @@ class Plot(PamhyrPlot):
)
self._table_headers = self._trad.get_dict("table_headers")
header = self.data.header
self.label_x = self._table_headers[header[0]]
self.label_y = self._table_headers[header[1]]
self._mode = mode
self._isometric_axis = False
self._auto_relim_update = True
self._autoscale_update = True
def custom_ticks(self):
if self.data.header[0] != "time":
return
t0 = datetime.fromtimestamp(0)
nb = len(self.data.data)
mod = int(nb / 5)
mod = mod if mod > 0 else nb
fx = list(
map(
lambda x: x[1],
filter(
lambda x: x[0] % mod == 0,
enumerate(self.data.data)
)
)
)
xx = list(map(lambda v: v[0], fx))
if self._mode == "time":
xt = list(
map(
lambda v: str(
datetime.fromtimestamp(v[0]) - t0
).split(",")[0]
.replace("days", _translate("LateralContribution", "days"))
.replace("day", _translate("LateralContribution", "day")),
fx
)
)
else:
xt = list(
map(
lambda v: str(datetime.fromtimestamp(v[0]).date()),
fx
)
)
self.canvas.axes.set_xticks(ticks=xx, labels=xt, rotation=45)
self.set_ticks_time_formater()
@timer
def draw(self):
self.canvas.axes.cla()
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
self.init_axes()
if len(self.data) == 0:
self._init = False
return
self.draw_data()
self.custom_ticks()
self.idle()
self._init = True
def draw_data(self):
# Plot data
x = list(map(lambda v: v[0], self.data.data))
y = list(map(lambda v: v[1], self.data.data))
self._line, = self.canvas.axes.plot(
x, y,
color='r', lw=1.,
markersize=5, marker='+',
picker=30,
color=self.color_plot,
**self.plot_default_kargs
)
self.custom_ticks()
# Plot label
header = self.data.header
self.canvas.axes.set_xlabel(
self._table_headers[header[0]], color='black', fontsize=10
)
self.canvas.axes.set_ylabel(
self._table_headers[header[1]], color='black', fontsize=10
)
self.canvas.axes.autoscale_view(True, True, True)
self.canvas.figure.tight_layout()
self.canvas.figure.canvas.draw_idle()
# self.toolbar.update()
self._init = True
@timer
def update(self, ind=None):
if not self._init:
self.draw()
return
self.update_data()
self.update_idle()
def update_data(self):
x = list(map(lambda v: v[0], self.data.data))
y = list(map(lambda v: v[1], self.data.data))
self._line.set_data(x, y)
self.custom_ticks()
self.canvas.axes.relim()
self.canvas.axes.autoscale()
self.canvas.figure.tight_layout()
self.canvas.figure.canvas.draw_idle()
......@@ -20,7 +20,11 @@ import logging
import traceback
from datetime import date, time, datetime, timedelta
from tools import trace, timer
from tools import (
trace, timer,
timestamp_to_old_pamhyr_date,
old_pamhyr_date_to_timestamp
)
from View.Tools.PamhyrTable import PamhyrTableModel
......@@ -70,9 +74,7 @@ class TableModel(PamhyrTableModel):
value = f"{v:.4f}"
elif self._data.header[column] == "time":
if self._opt_data == "time":
t0 = datetime.fromtimestamp(0)
t = datetime.fromtimestamp(v)
value = str(t - t0)
value = timestamp_to_old_pamhyr_date(int(v))
else:
value = str(datetime.fromtimestamp(v))
else:
......
......@@ -199,7 +199,8 @@ class LateralContributionWindow(PamhyrWindow):
data=data,
toolbar=None,
)
self.plot.draw(highlight=highlight)
self.plot.highlight = highlight
self.plot.draw()
def add(self):
tab = self.current_tab()
......
......@@ -251,7 +251,7 @@ def old_pamhyr_date_to_timestamp(date: str):
return ts
def timestamp_to_old_pamhyr_date(time:int):
def timestamp_to_old_pamhyr_date(time: int):
t0 = datetime.fromtimestamp(0)
t = datetime.fromtimestamp(time)
......
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