From fbdcfae30b179c3a17ae7b5704d33e8e8269c4ee Mon Sep 17 00:00:00 2001 From: AlexChaloner Date: Thu, 26 Dec 2024 17:03:51 +0000 Subject: [PATCH 1/2] Add better hover view information format Formatted some labels to look like: HH:mm: price p/kWh Which more closely matches Octopus's agile UX, and is slightly nicer on hovering. --- prices/views.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/prices/views.py b/prices/views.py index 21652cd..6891b38 100644 --- a/prices/views.py +++ b/prices/views.py @@ -180,6 +180,8 @@ def update_chart(self, context, **kwargs): day_ahead = pd.Series(index=[a.date_time for a in p], data=[a.day_ahead for a in p]) agile = day_ahead_to_agile(day_ahead, region=region).sort_index() + hover_template_time_price = "%{x|%H:%M}: %{y:.2f}p/kWh" + data = data + [ go.Scatter( x=agile.loc[:forecast_end].index.tz_convert("GB"), @@ -187,6 +189,7 @@ def update_chart(self, context, **kwargs): marker={"symbol": 104, "size": 1, "color": "white"}, mode="lines", name="Actual", + hovertemplate=hover_template_time_price ) ] @@ -216,7 +219,8 @@ def update_chart(self, context, **kwargs): marker={"symbol": 104, "size": 10}, mode="lines", line=dict(width=width), - name=f.name, + name="Prediction", + hovertemplate=hover_template_time_price ) ] @@ -355,6 +359,7 @@ def update_chart(self, context, **kwargs): legend=legend, height=height, template="plotly_dark", + hovermode='x', ) figure.update_layout(**layout) From ae3fd468074b4d799c646d58066fd900e7424b93 Mon Sep 17 00:00:00 2001 From: AlexChaloner Date: Thu, 26 Dec 2024 21:39:57 +0000 Subject: [PATCH 2/2] Show half-hour intervals by default --- prices/views.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/prices/views.py b/prices/views.py index 6891b38..2216592 100644 --- a/prices/views.py +++ b/prices/views.py @@ -180,7 +180,8 @@ def update_chart(self, context, **kwargs): day_ahead = pd.Series(index=[a.date_time for a in p], data=[a.day_ahead for a in p]) agile = day_ahead_to_agile(day_ahead, region=region).sort_index() - hover_template_time_price = "%{x|%H:%M}: %{y:.2f}p/kWh" + hover_template_time_price = "%{x|%H:%M}
%{y:.2f}p/kWh" + hover_template_price = "%{y:.2f}p/kWh" data = data + [ go.Scatter( @@ -189,7 +190,7 @@ def update_chart(self, context, **kwargs): marker={"symbol": 104, "size": 1, "color": "white"}, mode="lines", name="Actual", - hovertemplate=hover_template_time_price + hovertemplate=hover_template_price, ) ] @@ -220,7 +221,7 @@ def update_chart(self, context, **kwargs): mode="lines", line=dict(width=width), name="Prediction", - hovertemplate=hover_template_time_price + hovertemplate=hover_template_price, ) ] @@ -234,6 +235,7 @@ def update_chart(self, context, **kwargs): line=dict(width=1, color="red"), name="Low", showlegend=False, + hovertemplate=hover_template_price ), go.Scatter( x=df.index, @@ -245,6 +247,7 @@ def update_chart(self, context, **kwargs): showlegend=False, fill="tonexty", fillcolor="rgba(255,127,127,0.5)", + hovertemplate=hover_template_price, ), ] width = 1 @@ -381,8 +384,8 @@ def update_chart(self, context, **kwargs): ) figure.update_xaxes( tickformatstops=[ - dict(dtickrange=[None, 86000000], value="%H:%M\n%a %d %b"), - dict(dtickrange=[86000000, None], value="%a\n%b %d"), + dict(dtickrange=[None, 86000000], value="%H:%M
%a %d %b"), + dict(dtickrange=[86000000, None], value="%H:%M
%a %d %b"), ], # fixedrange=True, )