gov-uk-dashboards 15.2.1__py3-none-any.whl → 16.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gov_uk_dashboards/components/helpers/plotting_helper_functions.py +1 -3
- gov_uk_dashboards/components/plotly/time_series_chart.py +84 -44
- gov_uk_dashboards/constants.py +1 -0
- {gov_uk_dashboards-15.2.1.dist-info → gov_uk_dashboards-16.0.0.dist-info}/METADATA +1 -1
- {gov_uk_dashboards-15.2.1.dist-info → gov_uk_dashboards-16.0.0.dist-info}/RECORD +8 -8
- {gov_uk_dashboards-15.2.1.dist-info → gov_uk_dashboards-16.0.0.dist-info}/WHEEL +0 -0
- {gov_uk_dashboards-15.2.1.dist-info → gov_uk_dashboards-16.0.0.dist-info}/licenses/LICENSE +0 -0
- {gov_uk_dashboards-15.2.1.dist-info → gov_uk_dashboards-16.0.0.dist-info}/top_level.txt +0 -0
@@ -12,7 +12,6 @@ from gov_uk_dashboards.constants import (
|
|
12
12
|
CHART_LABEL_FONT_SIZE,
|
13
13
|
CUSTOM_DATA,
|
14
14
|
DATE_VALID,
|
15
|
-
FILL_TO_PREVIOUS_TRACE,
|
16
15
|
HOVER_TEXT_HEADERS,
|
17
16
|
MAIN_TITLE,
|
18
17
|
REMOVE_INITIAL_MARKER,
|
@@ -66,15 +65,17 @@ class TimeSeriesChart:
|
|
66
65
|
trace_name_column: Optional[str] = None,
|
67
66
|
xaxis_tick_text_format: XAxisFormat = XAxisFormat.YEAR.value,
|
68
67
|
verticle_line_x_value_and_name: tuple = None,
|
69
|
-
|
68
|
+
filled_traces_dict: dict[str] = None,
|
70
69
|
trace_names_to_prevent_hover_of_first_point_list=None,
|
71
70
|
x_axis_column=DATE_VALID,
|
72
71
|
x_unified_hovermode: Optional[bool] = False,
|
73
72
|
x_hoverformat: Optional[str] = None,
|
73
|
+
x_unified_hovertemplate: Optional[str] = None,
|
74
74
|
x_axis_title: Optional[str] = None,
|
75
75
|
download_chart_button_id: Optional[str] = None,
|
76
76
|
download_data_button_id: Optional[str] = None,
|
77
77
|
number_of_traces_colour_shift_dict: Optional[dict] = None,
|
78
|
+
additional_line: Optional[dict] = None,
|
78
79
|
):
|
79
80
|
self.title_data = title_data
|
80
81
|
self.y_axis_column = y_column
|
@@ -88,18 +89,20 @@ class TimeSeriesChart:
|
|
88
89
|
self.trace_name_column = trace_name_column
|
89
90
|
self.xaxis_tick_text_format = xaxis_tick_text_format
|
90
91
|
self.verticle_line_x_value_and_name = verticle_line_x_value_and_name
|
91
|
-
self.
|
92
|
+
self.filled_traces_dict = filled_traces_dict
|
92
93
|
self.trace_names_to_prevent_hover_of_first_point = (
|
93
94
|
trace_names_to_prevent_hover_of_first_point_list
|
94
95
|
)
|
95
96
|
self.x_axis_column = x_axis_column
|
96
97
|
self.x_unified_hovermode = x_unified_hovermode
|
97
98
|
self.x_hoverformat = x_hoverformat
|
99
|
+
self.x_unified_hovertemplate = x_unified_hovertemplate
|
98
100
|
self.x_axis_title = x_axis_title
|
99
101
|
self.download_chart_button_id = download_chart_button_id
|
100
102
|
self.download_data_button_id = download_data_button_id
|
101
103
|
self.markers = ["square", "diamond", "circle", "triangle-up"]
|
102
104
|
self.number_of_traces_colour_shift_dict = number_of_traces_colour_shift_dict
|
105
|
+
self.additional_line = additional_line
|
103
106
|
self.colour_list = self._get_colour_list()
|
104
107
|
self.fig = self.create_time_series_chart()
|
105
108
|
|
@@ -136,7 +139,24 @@ class TimeSeriesChart:
|
|
136
139
|
)
|
137
140
|
|
138
141
|
fig = go.Figure()
|
139
|
-
|
142
|
+
if self.additional_line:
|
143
|
+
x_0 = self.additional_line["x0"]
|
144
|
+
y_0 = self.additional_line["y0"]
|
145
|
+
x_1 = self.additional_line["x1"]
|
146
|
+
y_1 = self.additional_line["y1"]
|
147
|
+
line_color = self.additional_line["color"]
|
148
|
+
trace_connector = go.Scatter(
|
149
|
+
x=[x_0, x_1],
|
150
|
+
y=[y_0, y_1],
|
151
|
+
mode="lines",
|
152
|
+
name="Transition",
|
153
|
+
line={"color": line_color},
|
154
|
+
hoverinfo="skip", # 👈 This line disables hover for this trace
|
155
|
+
showlegend=False, # Optional: hide it from legend too
|
156
|
+
)
|
157
|
+
fig.add_trace(trace_connector)
|
158
|
+
# pylint: disable=unused-variable
|
159
|
+
for i, (df, trace_name, colour, marker,) in enumerate(
|
140
160
|
zip(
|
141
161
|
self._get_df_list_for_time_series(),
|
142
162
|
self.trace_name_list,
|
@@ -144,11 +164,6 @@ class TimeSeriesChart:
|
|
144
164
|
self.markers,
|
145
165
|
)
|
146
166
|
):
|
147
|
-
is_last = is_second_last = False
|
148
|
-
if self.last_2_traces_filled is True:
|
149
|
-
number_of_traces = len(self._get_df_list_for_time_series())
|
150
|
-
is_last = i == number_of_traces - 1
|
151
|
-
is_second_last = i == number_of_traces - 2
|
152
167
|
if REMOVE_INITIAL_MARKER in df.columns and True in df.get_column(
|
153
168
|
REMOVE_INITIAL_MARKER
|
154
169
|
):
|
@@ -159,27 +174,61 @@ class TimeSeriesChart:
|
|
159
174
|
self.create_time_series_trace(
|
160
175
|
df.sort(self.x_axis_column),
|
161
176
|
trace_name,
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
177
|
+
line_style={"dash": "solid", "color": colour},
|
178
|
+
marker={"symbol": marker, "size": marker_sizes, "opacity": 1},
|
179
|
+
),
|
180
|
+
)
|
181
|
+
|
182
|
+
if self.filled_traces_dict:
|
183
|
+
fill_df = self.filtered_df.filter(
|
184
|
+
pl.col(self.trace_name_column).is_in(
|
185
|
+
[
|
186
|
+
self.filled_traces_dict["upper"],
|
187
|
+
self.filled_traces_dict["lower"],
|
188
|
+
]
|
189
|
+
)
|
190
|
+
).sort(self.x_axis_column)
|
191
|
+
x_series = fill_df[self.x_axis_column].unique().sort().to_list()
|
192
|
+
upper_trace = self.filled_traces_dict["upper"]
|
193
|
+
lower_trace = self.filled_traces_dict["lower"]
|
194
|
+
y_upper = fill_df.filter(pl.col(self.trace_name_column) == upper_trace)[
|
195
|
+
self.y_axis_column
|
196
|
+
].to_list()
|
197
|
+
y_lower = fill_df.filter(pl.col(self.trace_name_column) == lower_trace)[
|
198
|
+
self.y_axis_column
|
199
|
+
].to_list()
|
200
|
+
y_upper_formatted_value = fill_df.filter(
|
201
|
+
pl.col(self.trace_name_column) == upper_trace
|
202
|
+
)["FORMATTED_VALUE"].to_list()
|
203
|
+
y_lower_formatted_value = fill_df.filter(
|
204
|
+
pl.col(self.trace_name_column) == lower_trace
|
205
|
+
)["FORMATTED_VALUE"].to_list()
|
206
|
+
formatted_dates = fill_df.filter(
|
207
|
+
pl.col(self.trace_name_column) == upper_trace
|
208
|
+
)["FORMATTED_DATE"].to_list()
|
209
|
+
hover_text = [
|
210
|
+
f"{self.filled_traces_dict['name']} - {date}: "
|
211
|
+
f"{low_value} - {high_value}<extra></extra>"
|
212
|
+
for low_value, high_value, date in zip(
|
213
|
+
y_lower_formatted_value,
|
214
|
+
y_upper_formatted_value,
|
215
|
+
formatted_dates,
|
216
|
+
)
|
217
|
+
]
|
218
|
+
|
219
|
+
hover_text_full = hover_text + hover_text[::-1]
|
220
|
+
fig.add_trace(
|
221
|
+
go.Scatter(
|
222
|
+
x=x_series + x_series[::-1],
|
223
|
+
y=y_upper + y_lower[::-1],
|
224
|
+
fill="toself",
|
225
|
+
fillcolor=get_rgba_from_hex_colour_and_alpha(
|
226
|
+
AFAccessibleColours.TURQUOISE.value, alpha=0.2
|
182
227
|
),
|
228
|
+
line={"color": "rgba(255,255,255,0)"},
|
229
|
+
name=self.filled_traces_dict["name"],
|
230
|
+
hovertemplate=hover_text_full,
|
231
|
+
hoveron="points",
|
183
232
|
)
|
184
233
|
)
|
185
234
|
self._format_x_axis(fig)
|
@@ -243,7 +292,7 @@ class TimeSeriesChart:
|
|
243
292
|
font={"size": CHART_LABEL_FONT_SIZE},
|
244
293
|
yaxis_tickformat=",",
|
245
294
|
hovermode="x unified" if self.x_unified_hovermode is True else "closest",
|
246
|
-
hoverdistance=
|
295
|
+
hoverdistance=1, # Increase distance to simulate hover 'always on'
|
247
296
|
)
|
248
297
|
return fig
|
249
298
|
|
@@ -264,8 +313,6 @@ class TimeSeriesChart:
|
|
264
313
|
df: pl.DataFrame,
|
265
314
|
trace_name: str,
|
266
315
|
line_style: dict[str, str],
|
267
|
-
fill: str,
|
268
|
-
hover_label: dict[str, str],
|
269
316
|
marker: dict[str, str],
|
270
317
|
):
|
271
318
|
"""Creates a trace for the plot.
|
@@ -275,8 +322,6 @@ class TimeSeriesChart:
|
|
275
322
|
y_value column and columns defined in self.hover_data[CUSTOM_DATA].
|
276
323
|
trace_name (str): Name of trace.
|
277
324
|
line_style (dict[str, str]): Properties for line_style parameter.
|
278
|
-
fill (str): Properties for fill parameter.
|
279
|
-
hover_label (dict[str,str]): Properties for hoverlabel parameter.
|
280
325
|
marker (dict[str,str]): Properties for marker parameter.
|
281
326
|
"""
|
282
327
|
return go.Scatter(
|
@@ -287,15 +332,7 @@ class TimeSeriesChart:
|
|
287
332
|
hovertemplate=self._get_hover_template(df, trace_name),
|
288
333
|
customdata=self._get_custom_data(df, trace_name),
|
289
334
|
marker=marker,
|
290
|
-
|
291
|
-
hoverlabel=hover_label,
|
292
|
-
fillcolor=(
|
293
|
-
get_rgba_from_hex_colour_and_alpha(
|
294
|
-
AFAccessibleColours.TURQUOISE.value, alpha=0.2
|
295
|
-
)
|
296
|
-
if fill
|
297
|
-
else None
|
298
|
-
),
|
335
|
+
hoverlabel=None,
|
299
336
|
showlegend=(
|
300
337
|
trace_name in self.legend_dict if self.legend_dict is not None else True
|
301
338
|
),
|
@@ -315,7 +352,10 @@ class TimeSeriesChart:
|
|
315
352
|
|
316
353
|
def _get_custom_hover_template(self, i, df, trace_name):
|
317
354
|
if self.x_unified_hovermode is True:
|
355
|
+
if self.x_unified_hovertemplate is not None:
|
356
|
+
return self.x_unified_hovertemplate.format(trace_name=trace_name)
|
318
357
|
return f"{trace_name}: " + "%{customdata[0]}<extra></extra>"
|
358
|
+
|
319
359
|
hover_text_headers = self.hover_data[trace_name][HOVER_TEXT_HEADERS]
|
320
360
|
if (
|
321
361
|
self.hover_data_for_traces_with_different_hover_for_last_point is not None
|
@@ -494,7 +534,7 @@ class TimeSeriesChart:
|
|
494
534
|
def _get_colour_list(self):
|
495
535
|
"""Returns a list of colours."""
|
496
536
|
number_of_traces = len(self.trace_name_list)
|
497
|
-
if number_of_traces == 2:
|
537
|
+
if number_of_traces == 2 and self.filled_traces_dict is None:
|
498
538
|
colour_list = [
|
499
539
|
AFAccessibleColours.DARK_BLUE.value,
|
500
540
|
AFAccessibleColours.ORANGE.value,
|
gov_uk_dashboards/constants.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: gov_uk_dashboards
|
3
|
-
Version:
|
3
|
+
Version: 16.0.0
|
4
4
|
Summary: Provides access to functionality common to creating a data dashboard.
|
5
5
|
Author: Department for Levelling Up, Housing and Communities
|
6
6
|
Description-Content-Type: text/markdown
|
@@ -1,7 +1,7 @@
|
|
1
1
|
gov_uk_dashboards/__init__.py,sha256=4y4hozrL4hzRUna8b22UQwtkZcvvCgeXsAtA6AJww8g,1299
|
2
2
|
gov_uk_dashboards/axes.py,sha256=Oh8zyWzxwZWq8bQl-vJoXwTANZ7ACZiYPmIXlM62Fvk,712
|
3
3
|
gov_uk_dashboards/colours.py,sha256=MezFI_3hgEuZ7f8F5TdtgaQO00B3G7ylRTCVq3SlSF4,2371
|
4
|
-
gov_uk_dashboards/constants.py,sha256=
|
4
|
+
gov_uk_dashboards/constants.py,sha256=o29g1rKeZ7ZZi-cKpmFtiTU6QBK6wm0PGHKVPn1rPFw,480
|
5
5
|
gov_uk_dashboards/symbols.py,sha256=6_lq8yl1l7sGUlOY29wip_PXeUUoM53_fakKY1omVwY,424
|
6
6
|
gov_uk_dashboards/template.html,sha256=uFAki9bEpcei5dP_NZYP8dsxpxXpNIDQPn7ezsE7VXc,498
|
7
7
|
gov_uk_dashboards/template.py,sha256=WNVkAW3LCNoUHcxQ1kiUPkGCKIan5DgZQaAA_ZbE5WA,534
|
@@ -72,14 +72,14 @@ gov_uk_dashboards/components/dash/warning_text.py,sha256=31XvPUINt2QsWIaaMnqEvn2
|
|
72
72
|
gov_uk_dashboards/components/helpers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
73
73
|
gov_uk_dashboards/components/helpers/display_chart_or_table_with_header.py,sha256=7Z52uZGrs15Q31OJjztnF0iqA5VRUrfJB_nPy6aZMMc,3060
|
74
74
|
gov_uk_dashboards/components/helpers/generate_dash_graph_from_figure.py,sha256=sdhC6Mjfw6kqs1MDRDoMuOt8dNS9Bl1WEoJX9S5AssA,1813
|
75
|
-
gov_uk_dashboards/components/helpers/plotting_helper_functions.py,sha256=
|
75
|
+
gov_uk_dashboards/components/helpers/plotting_helper_functions.py,sha256=8OMplDZSc0yPI6KjcHzBsV1hA35I6b09fKCiByfAFtY,1635
|
76
76
|
gov_uk_dashboards/components/helpers/update_layout_bgcolor_margin.py,sha256=i7Nwp0CxFpkyQeR8KfOBVMBkzctG7hMpWI2OzgxB2jY,740
|
77
77
|
gov_uk_dashboards/components/plotly/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
78
78
|
gov_uk_dashboards/components/plotly/captioned_figure.py,sha256=T0sbtGTiJ79FXxVdPb__hqISuyTc3Dl11cKhgcuW-5U,2804
|
79
79
|
gov_uk_dashboards/components/plotly/choropleth_map.py,sha256=U9RmS3MZGloQAt9HoSYh3Xad205DDfZOjz91ZD_ydbI,9849
|
80
80
|
gov_uk_dashboards/components/plotly/enums.py,sha256=ebHiFQljA7O4HJxKoslqlNXcAjUZi1askpTSwxKEcYQ,850
|
81
81
|
gov_uk_dashboards/components/plotly/stacked_barchart.py,sha256=y2XOf96tMfy5ythPb5RzqW5qGc2sKU3W508UbWO2iC0,12175
|
82
|
-
gov_uk_dashboards/components/plotly/time_series_chart.py,sha256=
|
82
|
+
gov_uk_dashboards/components/plotly/time_series_chart.py,sha256=Hqs4LW99ymUIVQvkQZtYRAiPZpEBa84Z9Jjpz_p12VU,21900
|
83
83
|
gov_uk_dashboards/figures/__init__.py,sha256=_snQeNlM81nNKERl4gg9ScH2HYbtwaBjl8yQonccx34,712
|
84
84
|
gov_uk_dashboards/figures/chart_data.py,sha256=fEsNkQFzXKIQ0h7aLBWq3J1qAxHbxvJeKU23JrVodVc,757
|
85
85
|
gov_uk_dashboards/figures/line_chart.py,sha256=rEB51_z9cPl7BcT94iA6ZsZXzecnVCnGpQWW_9SNGUY,2813
|
@@ -100,8 +100,8 @@ gov_uk_dashboards/lib/dap/dap_deployment.py,sha256=ZXixeOAtRNjMsPdGKLwwLNamlo0mi
|
|
100
100
|
gov_uk_dashboards/lib/dap/get_dataframe_from_cds.py,sha256=OiusRCgYnkBjK_GZgYLGzNrxOGizYt8CgThiWRCVKK0,3921
|
101
101
|
gov_uk_dashboards/lib/datetime_functions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
102
102
|
gov_uk_dashboards/lib/datetime_functions/datetime_functions.py,sha256=BQgr8I_vFNYwLi-fE4YC6jZ5PpbPea2rnD_2a_lw0YE,12209
|
103
|
-
gov_uk_dashboards-
|
104
|
-
gov_uk_dashboards-
|
105
|
-
gov_uk_dashboards-
|
106
|
-
gov_uk_dashboards-
|
107
|
-
gov_uk_dashboards-
|
103
|
+
gov_uk_dashboards-16.0.0.dist-info/licenses/LICENSE,sha256=GDiD7Y2Gx7JucPV1JfVySJeah-qiSyBPdpJ6RHCEHTc,1126
|
104
|
+
gov_uk_dashboards-16.0.0.dist-info/METADATA,sha256=0ftn3jstpqyF2k913ym1UarZusc0cteZjJgOcVgW3YE,5917
|
105
|
+
gov_uk_dashboards-16.0.0.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
106
|
+
gov_uk_dashboards-16.0.0.dist-info/top_level.txt,sha256=gPaN1P3-H3Rgi2me6tt-fX_cxo19CZfA4PjlZPjGRpo,18
|
107
|
+
gov_uk_dashboards-16.0.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|