gov-uk-dashboards 17.1.0__tar.gz → 18.0.0__tar.gz

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.
Files changed (119) hide show
  1. {gov_uk_dashboards-17.1.0/gov_uk_dashboards.egg-info → gov_uk_dashboards-18.0.0}/PKG-INFO +1 -1
  2. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/assets/custom_map_style_functions.js +29 -0
  3. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/assets/dashboard.css +4 -0
  4. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/leaflet/leaflet_choropleth_map.py +97 -26
  5. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0/gov_uk_dashboards.egg-info}/PKG-INFO +1 -1
  6. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/setup.py +1 -1
  7. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/LICENSE +0 -0
  8. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/MANIFEST.in +0 -0
  9. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/README.md +0 -0
  10. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/__init__.py +0 -0
  11. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/assets/__init__.py +0 -0
  12. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/assets/attach-event-to-dash.js +0 -0
  13. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/assets/fonts/bold-affa96571d-v2.woff +0 -0
  14. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/assets/fonts/bold-b542beb274-v2.woff2 +0 -0
  15. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/assets/fonts/light-94a07e06a1-v2.woff2 +0 -0
  16. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/assets/fonts/light-f591b13f7d-v2.woff +0 -0
  17. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/assets/get_assets_folder.py +0 -0
  18. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/assets/govuk-frontend-3.14.0.min.js +0 -0
  19. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/assets/images/DLUHC_WHITE_Master_AW_sm.png +0 -0
  20. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/assets/images/MHCLG-favicon.png +0 -0
  21. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/assets/images/MHCLG_favicon.png +0 -0
  22. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/assets/images/dcms_coatofarms.png +0 -0
  23. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/assets/images/dluhc_favicon.ico +0 -0
  24. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/assets/images/gov_favicon.ico +0 -0
  25. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/assets/images/govuk-crest.svg +0 -0
  26. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/assets/images/hm-government-logo.png +0 -0
  27. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/assets/images/mhclg_coat_of_arms.png +0 -0
  28. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/assets/images/mhclg_white_no_background.png +0 -0
  29. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/assets/images/oflog/MedianAbsolute.png +0 -0
  30. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/assets/images/oflog/how_to_1_selecting_data.png +0 -0
  31. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/assets/images/oflog/how_to_2_viewing_tabs.png +0 -0
  32. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/assets/images/oflog/how_to_3_viewing_charts.png +0 -0
  33. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/assets/images/oflog/how_to_4_viewing_trends.png +0 -0
  34. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/assets/images/oflog/how_to_5_viewing_tables.png +0 -0
  35. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/assets/mobile-nav.js +0 -0
  36. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/assets/topojson/usa_110m.json +0 -0
  37. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/assets/topojson/world_110m.json +0 -0
  38. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/axes.py +0 -0
  39. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/colours.py +0 -0
  40. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/__init__.py +0 -0
  41. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/__init__.py +0 -0
  42. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/apply_and_reset_filters_buttons.py +0 -0
  43. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/banners.py +0 -0
  44. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/card.py +0 -0
  45. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/card_full_width.py +0 -0
  46. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/collapsible_panel.py +0 -0
  47. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/comparison_la_filter_button.py +0 -0
  48. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/context_banner.py +0 -0
  49. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/dashboard_container.py +0 -0
  50. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/details.py +0 -0
  51. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/download_button.py +0 -0
  52. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/filter_panel.py +0 -0
  53. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/footer.py +0 -0
  54. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/graph.py +0 -0
  55. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/header.py +0 -0
  56. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/heading.py +0 -0
  57. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/home_page_link_button.py +0 -0
  58. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/html_list.py +0 -0
  59. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/key_value_pair.py +0 -0
  60. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/main_content.py +0 -0
  61. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/navbar.py +0 -0
  62. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/no_data_message.py +0 -0
  63. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/notification_banner.py +0 -0
  64. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/paragraph.py +0 -0
  65. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/phase_banner.py +0 -0
  66. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/row_component.py +0 -0
  67. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/side_navbar.py +0 -0
  68. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/table.py +0 -0
  69. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/tooltip.py +0 -0
  70. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/tooltip_title.py +0 -0
  71. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/visualisation_commentary.py +0 -0
  72. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/visualisation_title.py +0 -0
  73. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/dash/warning_text.py +0 -0
  74. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/helpers/__init__.py +0 -0
  75. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/helpers/display_chart_or_table_with_header.py +0 -0
  76. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/helpers/generate_dash_graph_from_figure.py +0 -0
  77. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/helpers/get_chart_for_download.py +0 -0
  78. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/helpers/plotting_helper_functions.py +0 -0
  79. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/helpers/update_layout_bgcolor_margin.py +0 -0
  80. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/leaflet/__init__.py +0 -0
  81. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/plotly/__init__.py +0 -0
  82. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/plotly/captioned_figure.py +0 -0
  83. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/plotly/choropleth_map.py +0 -0
  84. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/plotly/enums.py +0 -0
  85. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/plotly/stacked_barchart.py +0 -0
  86. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/components/plotly/time_series_chart.py +0 -0
  87. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/constants.py +0 -0
  88. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/figures/__init__.py +0 -0
  89. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/figures/chart_data.py +0 -0
  90. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/figures/enums/__init__.py +0 -0
  91. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/figures/enums/dash_patterns.py +0 -0
  92. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/figures/line_chart.py +0 -0
  93. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/figures/styles/__init__.py +0 -0
  94. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/figures/styles/line_style.py +0 -0
  95. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/formatting/__init__.py +0 -0
  96. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/formatting/human_readable.py +0 -0
  97. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/formatting/number_formatting.py +0 -0
  98. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/formatting/round_and_add_prefix_and_suffix.py +0 -0
  99. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/formatting/rounding.py +0 -0
  100. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/lib/__init__.py +0 -0
  101. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/lib/dap/__init__.py +0 -0
  102. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/lib/dap/dap_deployment.py +0 -0
  103. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/lib/dap/get_dataframe_from_cds.py +0 -0
  104. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/lib/datetime_functions/__init__.py +0 -0
  105. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/lib/datetime_functions/datetime_functions.py +0 -0
  106. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/lib/download_functions/__init__.py +0 -0
  107. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/lib/download_functions/convert_fig_to_image_and_download.py +0 -0
  108. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/lib/download_functions/download_csv_with_headers.py +0 -0
  109. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/lib/enable_basic_auth.py +0 -0
  110. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/lib/http_headers.py +0 -0
  111. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/lib/logging.py +0 -0
  112. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/symbols.py +0 -0
  113. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/template.html +0 -0
  114. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards/template.py +0 -0
  115. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards.egg-info/SOURCES.txt +0 -0
  116. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards.egg-info/dependency_links.txt +0 -0
  117. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards.egg-info/requires.txt +0 -0
  118. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/gov_uk_dashboards.egg-info/top_level.txt +0 -0
  119. {gov_uk_dashboards-17.1.0 → gov_uk_dashboards-18.0.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gov_uk_dashboards
3
- Version: 17.1.0
3
+ Version: 18.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
@@ -35,6 +35,35 @@ window.myNamespace = Object.assign({}, window.myNamespace, {
35
35
  const local_t = (t * n) - idx;
36
36
  const fillColor = interpolateColor(colors[idx], colors[idx + 1], local_t);
37
37
 
38
+ return {
39
+ ...style,
40
+ fillColor: fillColor
41
+ };
42
+ },
43
+ discreteColorScale: function(feature, context) {
44
+ const {
45
+ colorscale, // e.g., ["#d7191c", "#fdae61", "#abdda4", "#2b83ba"]
46
+ colorProp, // e.g., "category"
47
+ style,
48
+ min // e.g., 1
49
+ } = context.hideout;
50
+
51
+ const value = feature.properties[colorProp];
52
+ const colors = Array.from(colorscale); // ensure no mutation
53
+
54
+ if (value === null || value === undefined) {
55
+ return {
56
+ ...style,
57
+ fillColor: "#b1b4b6" // default gray
58
+ };
59
+ }
60
+
61
+ // Convert value to zero-based index
62
+ const idx = value - min;
63
+
64
+ // Defensive check
65
+ const fillColor = colors[idx] || "#b1b4b6";
66
+
38
67
  return {
39
68
  ...style,
40
69
  fillColor: fillColor
@@ -9347,4 +9347,8 @@ mark.expenditure {
9347
9347
 
9348
9348
  .font-weight-normal-override {
9349
9349
  font-weight: normal !important;
9350
+ }
9351
+
9352
+ .leaflet-interactive:focus {
9353
+ outline: none !important;
9350
9354
  }
@@ -1,10 +1,15 @@
1
1
  """Leaflet choropleth map class"""
2
2
 
3
+ from typing import Optional
3
4
  from dash_extensions.javascript import arrow_function, Namespace
4
5
  import dash_leaflet as dl
6
+ import dash_leaflet.express as dlx
5
7
  from dash import html
6
8
  import polars as pl
7
9
 
10
+ from gov_uk_dashboards.components.helpers.display_chart_or_table_with_header import (
11
+ display_chart_or_table_with_header,
12
+ )
8
13
  from gov_uk_dashboards.formatting.number_formatting import (
9
14
  format_number_into_thousands_or_millions,
10
15
  )
@@ -18,18 +23,39 @@ class LeafletChoroplethMap:
18
23
  discrete"""
19
24
 
20
25
  # pylint: disable=too-few-public-methods
26
+ # pylint: disable=too-many-instance-attributes
27
+ # pylint: disable=too-many-arguments
28
+ # pylint: disable=too-many-positional-arguments
21
29
 
22
30
  def __init__(
23
31
  self,
24
- get_geojson_function,
25
- get_df_function,
26
- hover_text_columns,
27
- color_scale_is_discrete=True,
32
+ geojson: dict,
33
+ df: pl.DataFrame,
34
+ hover_text_columns: list[str],
35
+ column_to_plot: str,
36
+ legend_column: str,
37
+ area_column: str,
38
+ title: str,
39
+ subtitle: Optional[str] = None,
40
+ enable_zoom: bool = True,
41
+ download_chart_button_id: Optional[str] = None,
42
+ download_data_button_id: Optional[str] = None,
43
+ color_scale_is_discrete: bool = True,
44
+ show_tile_layer: bool = False,
28
45
  ):
29
- self.geojson_data = get_geojson_function()
30
- self.df = get_df_function()
46
+ self.geojson_data = geojson
47
+ self.df = df
31
48
  self.hover_text_columns = hover_text_columns
49
+ self.column_to_plot = column_to_plot
50
+ self.legend_column = legend_column
51
+ self.area_column = area_column
52
+ self.title = title
53
+ self.subtitle = subtitle
54
+ self.enable_zoom = enable_zoom
55
+ self.download_chart_button_id = download_chart_button_id
56
+ self.download_data_button_id = download_data_button_id
32
57
  self.color_scale_is_discrete = color_scale_is_discrete
58
+ self.show_tile_layer = show_tile_layer
33
59
  self._add_data_to_geojson()
34
60
 
35
61
  def get_leaflet_choropleth_map(self):
@@ -38,9 +64,17 @@ class LeafletChoroplethMap:
38
64
  Returns:
39
65
  dl.Map: A dash leaflet map chart.
40
66
  """
41
- return dl.Map(
67
+ disabled_zoom_controls = {
68
+ "scrollWheelZoom": False,
69
+ "dragging": False,
70
+ "zoomControl": False,
71
+ "doubleClickZoom": False,
72
+ "touchZoom": False,
73
+ }
74
+ zoom_controls = {} if self.enable_zoom else disabled_zoom_controls
75
+ choropleth_map = dl.Map(
42
76
  children=[
43
- dl.TileLayer(),
77
+ dl.TileLayer() if self.show_tile_layer else None,
44
78
  self._get_colorbar(),
45
79
  self._get_colorbar_title(),
46
80
  self._get_dl_geojson(),
@@ -48,22 +82,25 @@ class LeafletChoroplethMap:
48
82
  center=[54.5, -2.5], # Centered on the UK
49
83
  zoom=6.5,
50
84
  minZoom=6.5,
51
- maxZoom=6.5,
85
+ maxZoom=10 if self.enable_zoom else 6.5,
52
86
  maxBounds=[[49.8, -10], [55.9, 1.8]],
53
- scrollWheelZoom=False, # Disable zooming via mouse scroll
54
- dragging=False, # Optional: prevent dragging too if you want
55
- zoomControl=False, # Hide the zoom buttons (+/-)
56
- doubleClickZoom=False, # Prevent double click zoom
57
- touchZoom=False, # Prevent pinch zoom
87
+ **zoom_controls,
58
88
  attributionControl=False,
59
89
  style={"width": "100%", "height": "800px", "background": "white"},
60
90
  )
91
+ return display_chart_or_table_with_header(
92
+ choropleth_map,
93
+ self.title,
94
+ self.subtitle,
95
+ self.download_chart_button_id,
96
+ self.download_data_button_id,
97
+ )
61
98
 
62
99
  def _add_data_to_geojson(self):
63
100
  info_map = {
64
101
  row["Area_Code"]: {
65
- "value": row["Value"],
66
- "region": row["Region"],
102
+ "value": row[self.column_to_plot],
103
+ "area": row[self.area_column],
67
104
  **{col: row[col] for col in self.hover_text_columns},
68
105
  }
69
106
  for row in self.df.iter_rows(named=True)
@@ -75,9 +112,9 @@ class LeafletChoroplethMap:
75
112
  if info:
76
113
 
77
114
  feature["properties"]["density"] = info["value"]
78
- feature["properties"]["region"] = info["region"]
115
+ feature["properties"]["area"] = info["area"]
79
116
 
80
- tooltip_parts = [f"<b>{info['region']}</b>"]
117
+ tooltip_parts = [f"<b>{info['area']}</b>"]
81
118
  if info["value"] is None:
82
119
  tooltip_parts.append("<br>No data available")
83
120
  else:
@@ -87,13 +124,18 @@ class LeafletChoroplethMap:
87
124
  feature["properties"]["tooltip"] = "".join(tooltip_parts)
88
125
  else:
89
126
  feature["properties"]["density"] = None
90
- feature["properties"]["region"] = "Unknown"
127
+ feature["properties"]["area"] = "Unknown"
91
128
  feature["properties"]["tooltip"] = "No data available"
92
129
 
93
130
  def _get_dl_geojson(self):
94
131
  style_handle = self._get_style_handle()
95
132
  colorscale = self._get_colorscale()
96
- style = {"weight": 2, "opacity": 1, "color": "white", "fillOpacity": 1}
133
+ style = {
134
+ "weight": 2,
135
+ "opacity": 1,
136
+ "color": "white",
137
+ "fillOpacity": 0.7 if self.show_tile_layer else 1,
138
+ }
97
139
  hover_style = arrow_function({"weight": 5, "color": "#666", "dashArray": ""})
98
140
  return dl.GeoJSON(
99
141
  data=self.geojson_data,
@@ -106,26 +148,53 @@ class LeafletChoroplethMap:
106
148
  "colorscale": colorscale, # Use hex strings
107
149
  "style": style,
108
150
  "colorProp": "density",
109
- "min": self.df["Value"].min(),
110
- "max": self.df["Value"].max(),
151
+ "min": self.df[self.column_to_plot].min(),
152
+ "max": self.df[self.column_to_plot].max(),
111
153
  },
112
154
  )
113
155
 
114
156
  def _get_style_handle(self):
115
157
  ns = Namespace("myNamespace", "mapColorScaleFunctions")
116
158
  if self.color_scale_is_discrete:
117
- return ""
159
+ return ns("discreteColorScale")
118
160
  return ns("continuousColorScale")
119
161
 
120
162
  def _get_colorscale(self):
121
163
  if self.color_scale_is_discrete:
122
- return ""
164
+ discrete_colours = ["#217847", "#23BBBE", "#8CCE69", "#FFEA80"]
165
+ if len(self.df[self.column_to_plot].unique()) == 3:
166
+ discrete_colours.pop(1)
167
+ return discrete_colours
123
168
  return ["#B0F2BC", "#257D98"]
124
169
 
170
+ def _get_color_bar_categories(self):
171
+ return (
172
+ self.df.select([self.legend_column, self.column_to_plot])
173
+ .unique()
174
+ .sort(self.column_to_plot, descending=True)
175
+ .select(self.legend_column)
176
+ .to_series()
177
+ .to_list()
178
+ )
179
+
125
180
  def _get_colorbar(self):
126
- min_value = self.df.select(pl.min("Value")).item()
181
+ if self.color_scale_is_discrete:
182
+ self._get_color_bar_categories()
183
+ return dlx.categorical_colorbar(
184
+ categories=self._get_color_bar_categories(), # reversed order
185
+ colorscale=self._get_colorscale()[::-1],
186
+ width=30,
187
+ height=300,
188
+ position="topleft",
189
+ style={
190
+ "padding": "6px",
191
+ "backgroundColor": "white",
192
+ "borderRadius": "4px",
193
+ },
194
+ )
195
+ min_value = self.df.select(pl.min(self.column_to_plot)).item()
127
196
  colorbar_min = min(min_value, 0)
128
- max_value = self.df.select(pl.max("Value")).item()
197
+ max_value = self.df.select(pl.max(self.column_to_plot)).item()
129
198
  mid_value = (colorbar_min + max_value) / 2
130
199
  quarter_value = (colorbar_min + max_value) / 4
131
200
  three_quarter_value = 3 * (colorbar_min + max_value) / 4
@@ -158,6 +227,8 @@ class LeafletChoroplethMap:
158
227
  )
159
228
 
160
229
  def _get_colorbar_title(self):
230
+ if self.color_scale_is_discrete:
231
+ return None
161
232
  return html.Div(
162
233
  self.hover_text_columns[0],
163
234
  style={
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gov_uk_dashboards
3
- Version: 17.1.0
3
+ Version: 18.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
@@ -10,7 +10,7 @@ setup(
10
10
  author="Department for Levelling Up, Housing and Communities",
11
11
  description="Provides access to functionality common to creating a data dashboard.",
12
12
  name="gov_uk_dashboards",
13
- version="17.1.0",
13
+ version="18.0.0",
14
14
  long_description=long_description,
15
15
  long_description_content_type="text/markdown",
16
16
  packages=find_packages(),