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

Results: CustomPlot: Add custom time axes.

Showing with 50 additions and 0 deletions
+50 -0
...@@ -19,6 +19,7 @@ ...@@ -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): ...@@ -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): ...@@ -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()
......
...@@ -27,6 +27,13 @@ class ResultsTranslate(PamhyrTranslate): ...@@ -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"),
} }
......
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