Results: CustomPlot: Add custom time axes.

setup.py
Pierre-Antoine Rouby 2023-10-20 16:27:07 +02:00
parent 021971816a
commit cdfb867037
2 changed files with 50 additions and 0 deletions

View File

@ -19,6 +19,7 @@
import logging import logging
from functools import reduce from functools import reduce
from datetime import datetime
from tools import timer from tools import timer
from View.Tools.PamhyrPlot import PamhyrPlot from View.Tools.PamhyrPlot import PamhyrPlot
@ -139,6 +140,46 @@ class CustomPlot(PamhyrPlot):
color='r', color='r',
) )
def _customize_x_axes_time(self, ts, mode="time"):
# Custom time display
nb = len(ts)
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(ts)
)
)
)
if mode == "time":
t0 = datetime.fromtimestamp(0)
xt = list(
map(
lambda v: (
str(
datetime.fromtimestamp(v) - t0
).split(",")[0]
.replace("days", self._trad["days"])
.replace("day", self._trad["day"])
),
fx
)
)
else:
xt = list(
map(
lambda v: str(datetime.fromtimestamp(v).date()),
fx
)
)
self.canvas.axes.set_xticks(ticks=fx, labels=xt, rotation=45)
def _draw_time(self): def _draw_time(self):
results = self.data results = self.data
reach = results.river.reach(self._reach) reach = results.river.reach(self._reach)
@ -213,6 +254,8 @@ class CustomPlot(PamhyrPlot):
color='r', color='r',
) )
self._customize_x_axes_time(ts)
@timer @timer
def draw(self): def draw(self):
self.canvas.axes.cla() self.canvas.axes.cla()

View File

@ -27,6 +27,13 @@ class ResultsTranslate(PamhyrTranslate):
def __init__(self): def __init__(self):
super(ResultsTranslate, self).__init__() super(ResultsTranslate, self).__init__()
self._dict['day'] = _translate(
"Results", "day"
)
self._dict['days'] = _translate(
"Results", "days"
)
self._sub_dict["table_headers_reach"] = { self._sub_dict["table_headers_reach"] = {
"name": _translate("Results", "Reach name"), "name": _translate("Results", "Reach name"),
} }