gov-uk-dashboards 21.2.2__py3-none-any.whl → 22.1.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/assets/download-map.js +39 -0
- gov_uk_dashboards/assets/index.html +3 -0
- gov_uk_dashboards/assets/scripts.js +4 -0
- gov_uk_dashboards/components/dash/download_button.py +14 -5
- gov_uk_dashboards/components/helpers/display_chart_or_table_with_header.py +15 -2
- gov_uk_dashboards/components/leaflet/leaflet_choropleth_map.py +41 -3
- {gov_uk_dashboards-21.2.2.dist-info → gov_uk_dashboards-22.1.0.dist-info}/METADATA +1 -1
- {gov_uk_dashboards-21.2.2.dist-info → gov_uk_dashboards-22.1.0.dist-info}/RECORD +11 -8
- {gov_uk_dashboards-21.2.2.dist-info → gov_uk_dashboards-22.1.0.dist-info}/WHEEL +1 -1
- {gov_uk_dashboards-21.2.2.dist-info → gov_uk_dashboards-22.1.0.dist-info}/licenses/LICENSE +0 -0
- {gov_uk_dashboards-21.2.2.dist-info → gov_uk_dashboards-22.1.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
window.mynamespace = window.mynamespace || {};
|
2
|
+
|
3
|
+
window.mynamespace = {
|
4
|
+
downloadMap: function(buttonId) {
|
5
|
+
if (typeof buttonId !== "string") {
|
6
|
+
console.warn("Invalid buttonId passed to downloadMap:", buttonId);
|
7
|
+
return;
|
8
|
+
}
|
9
|
+
|
10
|
+
const mapDiv = document.getElementById(`${buttonId}-hidden-map-container`);
|
11
|
+
|
12
|
+
if (!mapDiv) {
|
13
|
+
console.error("Map container not found");
|
14
|
+
return;
|
15
|
+
}
|
16
|
+
|
17
|
+
html2canvas(mapDiv, { useCORS: true, scale: 1 }).then(originalCanvas => {
|
18
|
+
const cropHeight = originalCanvas.height - 300;
|
19
|
+
const cropWidth = originalCanvas.width;
|
20
|
+
|
21
|
+
const croppedCanvas = document.createElement("canvas");
|
22
|
+
croppedCanvas.width = cropWidth;
|
23
|
+
croppedCanvas.height = cropHeight;
|
24
|
+
|
25
|
+
const ctx = croppedCanvas.getContext("2d");
|
26
|
+
ctx.drawImage(originalCanvas, 0, 0, cropWidth, cropHeight, 0, 0, cropWidth, cropHeight);
|
27
|
+
|
28
|
+
const link = document.createElement("a");
|
29
|
+
link.download = `${buttonId}.png`;
|
30
|
+
link.href = croppedCanvas.toDataURL("image/png");
|
31
|
+
document.body.appendChild(link);
|
32
|
+
link.click();
|
33
|
+
document.body.removeChild(link);
|
34
|
+
}).catch(error => {
|
35
|
+
console.error("html2canvas error:", error);
|
36
|
+
alert("Failed to capture the map.");
|
37
|
+
});
|
38
|
+
}
|
39
|
+
};
|
@@ -1,4 +1,5 @@
|
|
1
1
|
"""download_button"""
|
2
|
+
from typing import Union
|
2
3
|
import warnings
|
3
4
|
from dash import html
|
4
5
|
|
@@ -35,26 +36,34 @@ def download_button(button_text: str, button_id: str = "download-button"):
|
|
35
36
|
|
36
37
|
|
37
38
|
def create_download_button_with_icon(
|
38
|
-
button_text: str, button_id_name: str
|
39
|
+
button_text: str, button_id_name: str, instance: Union[str, int] = None
|
39
40
|
) -> html.Button:
|
40
41
|
"""Create a download button with icon, aligned to the left.
|
41
42
|
|
42
43
|
Parameters:
|
44
|
+
- button_text (str): Text to display on button.
|
43
45
|
- button_id_name (str): A unique identifier for the button.
|
46
|
+
- instance (Union[int,str]): Optional additional id parameter for when button_text is
|
47
|
+
"Download map".
|
44
48
|
|
45
49
|
Returns:
|
46
50
|
- html.Button: Download button.
|
47
51
|
"""
|
48
52
|
download_type = button_text.lower().replace(" ", "-")
|
53
|
+
if button_text == "Download map":
|
54
|
+
id_dict = {
|
55
|
+
"download-type": download_type,
|
56
|
+
"name": button_id_name,
|
57
|
+
"instance": instance,
|
58
|
+
}
|
59
|
+
else:
|
60
|
+
id_dict = {"download-type": download_type, "name": button_id_name}
|
49
61
|
return html.Button(
|
50
62
|
[
|
51
63
|
html.Div("", className="download-icon"),
|
52
64
|
button_text,
|
53
65
|
],
|
54
|
-
id=
|
55
|
-
"download-type": download_type,
|
56
|
-
"name": button_id_name,
|
57
|
-
},
|
66
|
+
id=id_dict,
|
58
67
|
n_clicks=0,
|
59
68
|
className=DOWNLOAD_BUTTON_CLASSES,
|
60
69
|
type="submit",
|
@@ -18,7 +18,10 @@ def display_chart_or_table_with_header(
|
|
18
18
|
sub_heading: str = None,
|
19
19
|
download_button_id: str = None,
|
20
20
|
download_data_button_id: str = None,
|
21
|
+
download_map_button_id: str = None,
|
21
22
|
footnote: str = None,
|
23
|
+
instance=1,
|
24
|
+
text_below_subheading: str = None,
|
22
25
|
) -> html.Div:
|
23
26
|
"""Generate the wrapping information/header for a chart or table.
|
24
27
|
|
@@ -29,7 +32,11 @@ def display_chart_or_table_with_header(
|
|
29
32
|
download_button_id (str, optional): id for download button if required. Defaults to None.
|
30
33
|
if None then the button will not be included.
|
31
34
|
download_data_button_id (str, optional): the id to be applied to the download data button.
|
35
|
+
download_map_button_id (str, optional): the id to be applied to the download map button.
|
32
36
|
footnote (str, optional): the footnote to be added to charts and downloads.
|
37
|
+
instance (int or str): Optional additional paramter for id dict.
|
38
|
+
text_below_subheading (str, optional): Optional text to go below subheading but above
|
39
|
+
chart_or_table.
|
33
40
|
|
34
41
|
Returns:
|
35
42
|
html.Div: Div containing Header and chart/table.
|
@@ -54,6 +61,7 @@ def display_chart_or_table_with_header(
|
|
54
61
|
),
|
55
62
|
]
|
56
63
|
),
|
64
|
+
paragraph(text_below_subheading),
|
57
65
|
chart_or_table,
|
58
66
|
html.Div([paragraph(footnote)], style={"padding-top": "20px"}),
|
59
67
|
html.Div(
|
@@ -62,12 +70,17 @@ def display_chart_or_table_with_header(
|
|
62
70
|
html.Div(
|
63
71
|
[
|
64
72
|
create_download_button_with_icon(
|
65
|
-
"Download chart", download_button_id
|
73
|
+
"Download chart", download_button_id, instance
|
66
74
|
)
|
67
75
|
if download_button_id
|
68
76
|
else [],
|
69
77
|
create_download_button_with_icon(
|
70
|
-
"Download
|
78
|
+
"Download map", download_map_button_id, instance
|
79
|
+
)
|
80
|
+
if download_map_button_id
|
81
|
+
else [],
|
82
|
+
create_download_button_with_icon(
|
83
|
+
"Download data", download_data_button_id, instance
|
71
84
|
)
|
72
85
|
if download_data_button_id
|
73
86
|
else [],
|
@@ -36,6 +36,7 @@ class LeafletChoroplethMap:
|
|
36
36
|
legend_column: str,
|
37
37
|
area_column: str,
|
38
38
|
title: str,
|
39
|
+
instance: int,
|
39
40
|
subtitle: Optional[str] = None,
|
40
41
|
enable_zoom: bool = True,
|
41
42
|
download_chart_button_id: Optional[str] = None,
|
@@ -57,6 +58,7 @@ class LeafletChoroplethMap:
|
|
57
58
|
self.color_scale_is_discrete = color_scale_is_discrete
|
58
59
|
self.show_tile_layer = show_tile_layer
|
59
60
|
self._add_data_to_geojson()
|
61
|
+
self.instance = instance
|
60
62
|
|
61
63
|
def get_leaflet_choropleth_map(self):
|
62
64
|
"""Creates and returns leaflet choropleth map chart for display on application.
|
@@ -88,14 +90,49 @@ class LeafletChoroplethMap:
|
|
88
90
|
attributionControl=False,
|
89
91
|
style={"width": "100%", "height": "800px", "background": "white"},
|
90
92
|
)
|
91
|
-
|
93
|
+
download_choropleth_map = dl.Map(
|
94
|
+
children=[
|
95
|
+
dl.TileLayer() if self.show_tile_layer else None,
|
96
|
+
self._get_colorbar(),
|
97
|
+
self._get_colorbar_title(),
|
98
|
+
self._get_dl_geojson(),
|
99
|
+
],
|
100
|
+
center=[54.5, -25.0],
|
101
|
+
zoom=7.5,
|
102
|
+
maxBounds=[[49.5, -30], [60, 2]],
|
103
|
+
zoomControl=False,
|
104
|
+
attributionControl=False,
|
105
|
+
style={"width": "1200px", "height": "1200px", "background": "white"},
|
106
|
+
)
|
107
|
+
choropleth_map = display_chart_or_table_with_header(
|
92
108
|
choropleth_map,
|
93
109
|
self.title,
|
94
110
|
self.subtitle,
|
95
|
-
|
111
|
+
None,
|
96
112
|
self.download_data_button_id,
|
113
|
+
self.download_chart_button_id,
|
114
|
+
None,
|
115
|
+
self.instance,
|
116
|
+
)
|
117
|
+
download_choropleth_map_display = display_chart_or_table_with_header(
|
118
|
+
download_choropleth_map,
|
119
|
+
self.title,
|
120
|
+
self.subtitle,
|
97
121
|
)
|
98
122
|
|
123
|
+
return [
|
124
|
+
choropleth_map,
|
125
|
+
html.Div(
|
126
|
+
[download_choropleth_map_display],
|
127
|
+
id=f"{self.download_chart_button_id}-hidden-map-container",
|
128
|
+
style={
|
129
|
+
"position": "absolute",
|
130
|
+
"top": "-10000px",
|
131
|
+
"left": "-10000px",
|
132
|
+
}, # hide off screen
|
133
|
+
),
|
134
|
+
]
|
135
|
+
|
99
136
|
def _add_data_to_geojson(self):
|
100
137
|
info_map = {
|
101
138
|
row["Area_Code"]: {
|
@@ -230,11 +267,12 @@ class LeafletChoroplethMap:
|
|
230
267
|
def _get_colorbar_title(self):
|
231
268
|
if self.color_scale_is_discrete:
|
232
269
|
return None
|
270
|
+
top = "70px" if self.enable_zoom is False else "140px"
|
233
271
|
return html.Div(
|
234
272
|
self.hover_text_columns[0],
|
235
273
|
style={
|
236
274
|
"position": "absolute",
|
237
|
-
"
|
275
|
+
"top": top, # Adjusted to place above the colorbar
|
238
276
|
"left": "10px", # Align with the left side of the colorbar
|
239
277
|
"background": "white",
|
240
278
|
"padding": "2px 6px",
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: gov_uk_dashboards
|
3
|
-
Version:
|
3
|
+
Version: 22.1.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
|
@@ -9,9 +9,12 @@ gov_uk_dashboards/assets/__init__.py,sha256=SwV4sjjMQmuZXloVcvf2H86XFiAd8xhPLJva
|
|
9
9
|
gov_uk_dashboards/assets/attach-event-to-dash.js,sha256=mbea5TaxEnjMN-MebR3J0hVjOb1B27-zXwWw9ZYqBBw,562
|
10
10
|
gov_uk_dashboards/assets/custom_map_style_functions.js,sha256=UnLxX2TpeTxXCDDa4bBcTWXZoAe2RKH-bRU3ISX1bQs,2655
|
11
11
|
gov_uk_dashboards/assets/dashboard.css,sha256=PBCe11JdGGfsfLCng-zJwqUyKy6RKdwv5aE9Ft40XwM,202194
|
12
|
+
gov_uk_dashboards/assets/download-map.js,sha256=1IyCdC6WKYs4Y2MA-L96KEE4Q5yGET3_RR8SJLIA_dk,1319
|
12
13
|
gov_uk_dashboards/assets/get_assets_folder.py,sha256=ozYOmuO2r36vaTdWMU5cBuskl47RHBp8z9KIO06BXBM,171
|
13
14
|
gov_uk_dashboards/assets/govuk-frontend-3.14.0.min.js,sha256=kKi_r2hAqumi2pKM43W8NKpR2UtksUww9lSQOjkOmMI,34806
|
15
|
+
gov_uk_dashboards/assets/index.html,sha256=-ztvxxzmR68WQrH8LP247zZdRw5hvsybomHZj-fChow,111
|
14
16
|
gov_uk_dashboards/assets/mobile-nav.js,sha256=wsmOQtunN6HiA4EimNWPsr-qXomp9UruS2zr09Tsbeg,1772
|
17
|
+
gov_uk_dashboards/assets/scripts.js,sha256=cioIQuZoSX9mZFYE9JMbqvNNXZNMk-LtxfiD4Py_uNU,227
|
15
18
|
gov_uk_dashboards/assets/fonts/bold-affa96571d-v2.woff,sha256=WiqSUjeGmDfRr90KcP_e0HFyltLSWIWGXRnA2n8-zl0,40816
|
16
19
|
gov_uk_dashboards/assets/fonts/bold-b542beb274-v2.woff2,sha256=BuugGxrw9AFLSExxF3H-8dswvsvw7fSBSY2h5JWNPUc,31480
|
17
20
|
gov_uk_dashboards/assets/fonts/light-94a07e06a1-v2.woff2,sha256=7t-zwveUXK69CxVSK1nWx_Ab4X_s1hAv12RSrUBC97A,33382
|
@@ -45,7 +48,7 @@ gov_uk_dashboards/components/dash/comparison_la_filter_button.py,sha256=mhtmYVyT
|
|
45
48
|
gov_uk_dashboards/components/dash/context_banner.py,sha256=2o44AzS0pTYTY0r3OVbKW7dJg2lA1J8PW4RCeGQ15gg,1010
|
46
49
|
gov_uk_dashboards/components/dash/dashboard_container.py,sha256=KC2isR0NShxUYCl_pzDEAS4WK5pFrLMp4m2We3AqiwM,512
|
47
50
|
gov_uk_dashboards/components/dash/details.py,sha256=-Rgat95pCnU3fF4O0MkyymzMQPCZhRvuq0U0a5gHZBU,1106
|
48
|
-
gov_uk_dashboards/components/dash/download_button.py,sha256=
|
51
|
+
gov_uk_dashboards/components/dash/download_button.py,sha256=gau9axOMNLJlKllFQsMGoHdLLsOMGEkwSCuYb9QXKmA,2189
|
49
52
|
gov_uk_dashboards/components/dash/filter_panel.py,sha256=lQZYc5g7xUOpHfLWpPXiBKkIRKXoFb1p9NhJgS21tNo,1996
|
50
53
|
gov_uk_dashboards/components/dash/footer.py,sha256=RnJKN1YTP88GuJ4e7ci2T-jDqIe0-jDuHAQ8OhSCK50,3155
|
51
54
|
gov_uk_dashboards/components/dash/graph.py,sha256=bd49W5sVyhtWd4lNBfQST1RyLNlTLA0KRxS7jTgVMwE,886
|
@@ -69,13 +72,13 @@ gov_uk_dashboards/components/dash/visualisation_commentary.py,sha256=jBy8qy2DWYq
|
|
69
72
|
gov_uk_dashboards/components/dash/visualisation_title.py,sha256=xXHsyVRIGkngBXCuhv8z0PmZLOeicjpMvmTbA5HhRvQ,561
|
70
73
|
gov_uk_dashboards/components/dash/warning_text.py,sha256=31XvPUINt2QsWIaaMnqEvn23G-MpzWbDvGnzYcXIyAY,1622
|
71
74
|
gov_uk_dashboards/components/helpers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
72
|
-
gov_uk_dashboards/components/helpers/display_chart_or_table_with_header.py,sha256=
|
75
|
+
gov_uk_dashboards/components/helpers/display_chart_or_table_with_header.py,sha256=KimvsTYocvSL-sWxer2Rrl1v9pCj5HgyWXhk8MZU-hY,3992
|
73
76
|
gov_uk_dashboards/components/helpers/generate_dash_graph_from_figure.py,sha256=sdhC6Mjfw6kqs1MDRDoMuOt8dNS9Bl1WEoJX9S5AssA,1813
|
74
77
|
gov_uk_dashboards/components/helpers/get_chart_for_download.py,sha256=I0IH7bE3B8UmdIHTn5tM26iGR6bfnB_fCfgnFQEIF4o,1179
|
75
78
|
gov_uk_dashboards/components/helpers/plotting_helper_functions.py,sha256=WUif1mlSgWPuTZptBqaElWpJTlitmuiJofMTpOe_Bsg,1833
|
76
79
|
gov_uk_dashboards/components/helpers/update_layout_bgcolor_margin.py,sha256=i7Nwp0CxFpkyQeR8KfOBVMBkzctG7hMpWI2OzgxB2jY,740
|
77
80
|
gov_uk_dashboards/components/leaflet/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
78
|
-
gov_uk_dashboards/components/leaflet/leaflet_choropleth_map.py,sha256=
|
81
|
+
gov_uk_dashboards/components/leaflet/leaflet_choropleth_map.py,sha256=wkBw8x-x8XKuSzzEEW7hAFqh-5keWRardw1u0ZT_vBk,10193
|
79
82
|
gov_uk_dashboards/components/plotly/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
80
83
|
gov_uk_dashboards/components/plotly/captioned_figure.py,sha256=T0sbtGTiJ79FXxVdPb__hqISuyTc3Dl11cKhgcuW-5U,2804
|
81
84
|
gov_uk_dashboards/components/plotly/choropleth_map.py,sha256=U9RmS3MZGloQAt9HoSYh3Xad205DDfZOjz91ZD_ydbI,9849
|
@@ -106,8 +109,8 @@ gov_uk_dashboards/lib/datetime_functions/datetime_functions.py,sha256=BQgr8I_vFN
|
|
106
109
|
gov_uk_dashboards/lib/download_functions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
107
110
|
gov_uk_dashboards/lib/download_functions/convert_fig_to_image_and_download.py,sha256=-dkYbpTL6txftFfAZW-vfW_O9efb6Dse9WJ9MM6mAqw,534
|
108
111
|
gov_uk_dashboards/lib/download_functions/download_csv_with_headers.py,sha256=aLL3UodmilZA_1bQhtjtKi3FoB-4X_MtLOcDw5e1Nwo,4412
|
109
|
-
gov_uk_dashboards-
|
110
|
-
gov_uk_dashboards-
|
111
|
-
gov_uk_dashboards-
|
112
|
-
gov_uk_dashboards-
|
113
|
-
gov_uk_dashboards-
|
112
|
+
gov_uk_dashboards-22.1.0.dist-info/licenses/LICENSE,sha256=GDiD7Y2Gx7JucPV1JfVySJeah-qiSyBPdpJ6RHCEHTc,1126
|
113
|
+
gov_uk_dashboards-22.1.0.dist-info/METADATA,sha256=tCyHhM2VlhsZMqArb1FRNkmFQBbML4V0jsH_ZgwLBGo,5917
|
114
|
+
gov_uk_dashboards-22.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
115
|
+
gov_uk_dashboards-22.1.0.dist-info/top_level.txt,sha256=gPaN1P3-H3Rgi2me6tt-fX_cxo19CZfA4PjlZPjGRpo,18
|
116
|
+
gov_uk_dashboards-22.1.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|