mirror of https://gitlab.com/pamhyr/pamhyr2
Results: CustomPlot: Add custom time axes.
parent
021971816a
commit
cdfb867037
|
|
@ -19,6 +19,7 @@
|
|||
import logging
|
||||
|
||||
from functools import reduce
|
||||
from datetime import datetime
|
||||
|
||||
from tools import timer
|
||||
from View.Tools.PamhyrPlot import PamhyrPlot
|
||||
|
|
@ -139,6 +140,46 @@ class CustomPlot(PamhyrPlot):
|
|||
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):
|
||||
results = self.data
|
||||
reach = results.river.reach(self._reach)
|
||||
|
|
@ -213,6 +254,8 @@ class CustomPlot(PamhyrPlot):
|
|||
color='r',
|
||||
)
|
||||
|
||||
self._customize_x_axes_time(ts)
|
||||
|
||||
@timer
|
||||
def draw(self):
|
||||
self.canvas.axes.cla()
|
||||
|
|
|
|||
|
|
@ -27,6 +27,13 @@ class ResultsTranslate(PamhyrTranslate):
|
|||
def __init__(self):
|
||||
super(ResultsTranslate, self).__init__()
|
||||
|
||||
self._dict['day'] = _translate(
|
||||
"Results", "day"
|
||||
)
|
||||
self._dict['days'] = _translate(
|
||||
"Results", "days"
|
||||
)
|
||||
|
||||
self._sub_dict["table_headers_reach"] = {
|
||||
"name": _translate("Results", "Reach name"),
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue