govuk_publishing_components 45.6.1 → 45.7.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b7e677ebcf4bc8ae065476415230279eacde3aff30b4f673a682e9e340a90f4
4
- data.tar.gz: e8edaf344a5ebd5dd6e88c5edfdd0f013785daeb54dd031da6c41e9a97d8ffbd
3
+ metadata.gz: 1f666e85d9ff44b241dd92ecedaac2816dffcfd44c50b85f206bc5a0c209529b
4
+ data.tar.gz: c87b274a6e3bb1170ab2144ad3cfe21f22602381406edad542f03fbde9caa00c
5
5
  SHA512:
6
- metadata.gz: 3efebe93517bb33fbe07f055c063108ce045db6de8d808706a4e474041d4b5bf0774d620aa804a31af2897751f76f8fdfb8e7f6033f2a904e1aed7fda4383615
7
- data.tar.gz: f395017aded3b8d3e224aaa5c1442b58cec4c357e632f2d157ec305cd5605a734e988770f6849667d1a9569e11831fc5bb767428447dc3de78e864b5c07ecfc2
6
+ metadata.gz: 7062f9f8179dabef8ce3d70b4aca757f257c62e69a19486d095ae8fcfcddd8cce3b3405fddc663bce7e368d2272b89b80a921fa777c9adca32e3624c4d989953
7
+ data.tar.gz: ec90e23e9b1c953bc687b1abd5b5850336053a86c5f03a251eef0d05aab6747a280888f4c65672eddb965355e22a73402590e78844d6b0d0e3ce71b5cfe59d3b
@@ -5,28 +5,23 @@
5
5
  add_gem_component_stylesheet("heading")
6
6
  add_gem_component_stylesheet("skip-link")
7
7
 
8
- chart_heading ||= nil
9
8
  chart_heading_level ||= 2
10
9
  table_direction ||= "horizontal"
11
- h_axis_title ||= nil
12
- v_axis_title ||= nil
13
10
  rows ||= []
14
11
  keys ||= []
15
12
  chart_overview ||= nil
13
+ chart_type ||= "line"
16
14
  minimal ||= false
17
15
  hide_heading ||= minimal
18
- hide_legend ||= minimal
19
16
  link ||= false
20
- height ||= 400
21
17
  padding ||= false
22
- point_size ||= 10
23
- y_axis_auto_adjust ||= false
24
18
 
25
19
  chart_id = "chart-id-#{SecureRandom.hex(4)}"
26
20
  table_id = "table-id-#{SecureRandom.hex(4)}"
27
21
  @external_script ||= OpenStruct.new(loaded: 0)
28
22
  @external_script[:loaded] += 1
29
23
 
24
+ chart_helper = GovukPublishingComponents::Presenters::ChartHelper.new(local_assigns)
30
25
  shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
31
26
  component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns)
32
27
  component_helper.add_class("gem-c-chart")
@@ -36,58 +31,10 @@
36
31
 
37
32
  require "chartkick"
38
33
  Chartkick.options[:html] = '<div id="%{id}"><noscript><p class="govuk-body">Our charts are built using JavaScript but all the data is also available in the table below.</p></noscript></div>'
39
- # config options are here: https://developers.google.com/chart/interactive/docs/gallery/linechart
40
- font_16 = { color: '#000', fontName: 'GDS Transport', fontSize: '16', italic: false }
41
- font_19 = { color: '#000', fontName: 'GDS Transport', fontSize: '19', italic: false }
42
- legend = 'none'
43
- legend = { position: 'top', textStyle: font_16 } unless hide_legend
44
- point_size = 0 if minimal
45
- enableInteractivity = true
46
- enableInteractivity = false if minimal
47
- textPosition = nil
48
- textPosition = 'none' if minimal
49
- y_axis_view_window_min = 0
50
- y_axis_view_window_min = "auto" if y_axis_auto_adjust
51
34
 
52
35
  if !minimal && !chart_heading
53
36
  raise ArgumentError, "A chart heading must be provided for accessibility purposes."
54
37
  end
55
-
56
- chart_library_options = {
57
- chartArea: { width: '80%', height: '60%' },
58
- crosshair: { orientation: 'vertical', trigger: 'both', color: '#ccc' },
59
- curveType: 'none',
60
- enableInteractivity: enableInteractivity,
61
- legend: legend,
62
- pointSize: point_size,
63
- height: height,
64
- tooltip: { isHtml: true },
65
- hAxis: {
66
- textStyle: font_16,
67
- title: h_axis_title,
68
- titleTextStyle: font_19,
69
- textPosition: textPosition,
70
- },
71
- vAxis: {
72
- textStyle: font_16,
73
- title: v_axis_title,
74
- titleTextStyle: font_19,
75
- textPosition: textPosition,
76
- viewWindow: {
77
- min: y_axis_view_window_min
78
- }
79
- },
80
- }
81
-
82
- if rows.length > 0 && keys.length > 0
83
- chart_format_data = rows.map do |row|
84
- {
85
- name: row[:label],
86
- linewidth: 10,
87
- data: keys.zip(row[:values])
88
- }
89
- end
90
- end
91
38
  %>
92
39
  <% if rows.length > 0 && keys.length > 0 %>
93
40
  <%= javascript_include_tag "https://www.gstatic.com/charts/loader.js" if @external_script[:loaded] == 1 %>
@@ -117,7 +64,13 @@
117
64
  </span>
118
65
  <% end %>
119
66
 
120
- <%= line_chart(chart_format_data, library: chart_library_options) %>
67
+ <% if chart_type == "column" %>
68
+ <%= column_chart(chart_helper.chart_format_data, library: chart_helper.chart_options) %>
69
+ <% elsif chart_type == "bar" %>
70
+ <%= bar_chart(chart_helper.chart_format_data, library: chart_helper.chart_options) %>
71
+ <% else %>
72
+ <%= line_chart(chart_helper.chart_format_data, library: chart_helper.chart_options) %>
73
+ <% end %>
121
74
  <% end %>
122
75
 
123
76
  <% unless minimal %>
@@ -22,7 +22,6 @@ examples:
22
22
  h_axis_title: Day
23
23
  v_axis_title: Views
24
24
  chart_overview: This chart shows page views for January 2015.
25
- hide_legend: true
26
25
  keys:
27
26
  - "2015-01-01"
28
27
  - "2015-01-02"
@@ -102,6 +101,136 @@ examples:
102
101
  - 27
103
102
  - 18
104
103
  - 34
104
+ hide_legend:
105
+ data:
106
+ chart_heading: Page views chart
107
+ h_axis_title: Day
108
+ v_axis_title: Views
109
+ chart_overview: This chart shows page views for January 2015.
110
+ hide_legend: true
111
+ keys:
112
+ - "2015-01-01"
113
+ - "2015-01-02"
114
+ - "2015-01-03"
115
+ - "2015-01-04"
116
+ - "2015-01-05"
117
+ - "2015-01-06"
118
+ - "2015-01-07"
119
+ - "2015-01-08"
120
+ - "2015-01-09"
121
+ - "2015-01-10"
122
+ rows:
123
+ - label: January 2015
124
+ values:
125
+ - 500
126
+ - 1190
127
+ - 740
128
+ - 820
129
+ - 270
130
+ - 450
131
+ - 110
132
+ - 210
133
+ - 670
134
+ - 430
135
+ with_line_colours_and_styles:
136
+ description: Note that line styles and colours currently only work on line charts.
137
+ data:
138
+ chart_heading: Page views chart
139
+ h_axis_title: Day
140
+ v_axis_title: Views
141
+ chart_overview: This chart shows page views for January in different years.
142
+ line_colours:
143
+ - orange
144
+ - blue
145
+ - "#88AA11"
146
+ line_styles:
147
+ - solid
148
+ - dotted
149
+ - solid
150
+ keys:
151
+ - 1st
152
+ - 2nd
153
+ - 3rd
154
+ rows:
155
+ - label: January 2015
156
+ values:
157
+ - 110
158
+ - 119
159
+ - 105
160
+ - label: January 2016
161
+ values:
162
+ - 71
163
+ - 68
164
+ - 75
165
+ - label: January 2017
166
+ values:
167
+ - 21
168
+ - 42
169
+ - 18
170
+ bar_chart:
171
+ data:
172
+ chart_heading: Hats owned
173
+ h_axis_title: Day
174
+ v_axis_title: Views
175
+ chart_overview: This chart shows page views for January 2015.
176
+ chart_type: "bar"
177
+ hide_legend: true
178
+ keys:
179
+ - Jon
180
+ - Ash
181
+ - James
182
+ - Phil
183
+ rows:
184
+ - label: Hats owned
185
+ values:
186
+ - 3
187
+ - 1
188
+ - 1
189
+ - 2
190
+ column_chart:
191
+ data:
192
+ chart_heading: Hats owned
193
+ h_axis_title: Day
194
+ v_axis_title: Views
195
+ chart_overview: This chart shows page views for January 2015.
196
+ chart_type: "column"
197
+ hide_legend: true
198
+ keys:
199
+ - Jon
200
+ - Ash
201
+ - James
202
+ - Phil
203
+ rows:
204
+ - label: Hats owned
205
+ values:
206
+ - 3
207
+ - 1
208
+ - 1
209
+ - 2
210
+ format_axis_labels:
211
+ description: Sometimes if there are a lot of labels on the axes the chart can do strange truncation on the labels. If they are meant to be dates, the `h_axis_format` and `v_axis_format` will force a familiar date format to get around this problem.
212
+ data:
213
+ chart_heading: Page views chart
214
+ h_axis_title: Day
215
+ v_axis_title: Views
216
+ chart_overview: This chart shows page views for January.
217
+ h_axis_format: date
218
+ keys:
219
+ - 2024 Jan 1
220
+ - 2024 Jan 2
221
+ - 2024 Jan 3
222
+ - 2024 Jan 4
223
+ - 2024 Jan 5
224
+ - 2024 Jan 6
225
+ rows:
226
+ - label: January 2015
227
+ values:
228
+ - 110
229
+ - 119
230
+ - 105
231
+ - 109
232
+ - 130
233
+ - 131
105
234
  vertical table:
106
235
  description: Reorient the table to better suit the output of some data sets.
107
236
  data:
@@ -4,11 +4,12 @@ body: |
4
4
  This is a complex component that calls other components. For more accurate
5
5
  preview with real data, see the [contextual navigation preview][preview].
6
6
 
7
- There are 3 main variants of the component:
7
+ There are 4 main variants of the component:
8
8
 
9
9
  - Step by step, which uses the [step by step header][header]
10
10
  - Parent breadcrumb, which uses the `parent` link of the page with the [breadcrumbs component][breadcrumbs]
11
11
  - Taxon breadcrumb, which uses the `taxons` link of the page with the [breadcrumbs component][breadcrumbs]
12
+ - Organisation breadcrumb, which uses the `organisations` link of the page with the [breadcrumbs component][breadcrumbs]
12
13
 
13
14
  It must always used [together with the contextual sidebar][sidebar] and [footer].
14
15
 
@@ -33,7 +33,7 @@ en:
33
33
  characters: characters
34
34
  words: words
35
35
  chart:
36
- table_dropdown: Data table
36
+ table_dropdown: View data as a table
37
37
  accessibility_html: This chart is a visual representation of the data available in the table.
38
38
  accessibility_link: Skip to "%{chart_heading}" data table
39
39
  accessibility_heading: Data table for "%{chart_heading}"
@@ -55,6 +55,11 @@ module GovukPublishingComponents
55
55
  step_by_step: false,
56
56
  breadcrumbs: navigation.breadcrumbs,
57
57
  }
58
+ elsif navigation.use_organisation_breadcrumbs?
59
+ {
60
+ step_by_step: false,
61
+ breadcrumbs: navigation.organisation_breadcrumbs,
62
+ }
58
63
  elsif navigation.use_taxon_breadcrumbs?
59
64
  {
60
65
  step_by_step: false,
@@ -0,0 +1,106 @@
1
+ module GovukPublishingComponents
2
+ module Presenters
3
+ class ChartHelper
4
+ def initialize(options)
5
+ @rows = options[:rows]
6
+ @keys = options[:keys]
7
+ @minimal = options[:minimal]
8
+ @enable_interactivity = false
9
+ @enable_interactivity = true unless @minimal
10
+ @hide_legend = options[:hide_legend]
11
+ @hide_legend = true if @minimal
12
+ @point_size = options[:point_size] ||= 10
13
+ @point_size = 0 if @minimal
14
+ @height = options[:height] || 400
15
+ @h_axis_title = options[:h_axis_title]
16
+ @v_axis_title = options[:v_axis_title]
17
+ @text_position = "none" if @minimal
18
+ @y_axis_view_window_min = 0
19
+ @y_axis_view_window_min = "auto" if options[:y_axis_auto_adjust]
20
+ @line_colours = options[:line_colours]
21
+ @line_styles = options[:line_styles]
22
+ @h_axis_format = "YYYY-MM-dd" if options[:h_axis_format] == "date"
23
+ @v_axis_format = "YYYY-MM-dd" if options[:v_axis_format] == "date"
24
+ end
25
+
26
+ # config options are here: https://developers.google.com/chart/interactive/docs/gallery/linechart
27
+ def chart_options
28
+ {
29
+ chartArea: { width: "80%", height: "60%" },
30
+ crosshair: { orientation: "vertical", trigger: "both", color: "#ccc" },
31
+ curveType: "none",
32
+ enableInteractivity: @enable_interactivity,
33
+ legend: legend_options,
34
+ pointSize: @point_size,
35
+ height: @height,
36
+ tooltip: { isHtml: true },
37
+ series: series_options,
38
+ hAxis: {
39
+ textStyle: set_font_16,
40
+ title: @h_axis_title,
41
+ titleTextStyle: set_font_19,
42
+ textPosition: @text_position,
43
+ format: @h_axis_format,
44
+ },
45
+ vAxis: {
46
+ textStyle: set_font_16,
47
+ title: @v_axis_title,
48
+ titleTextStyle: set_font_19,
49
+ textPosition: @text_position,
50
+ format: @v_axis_format,
51
+ viewWindow: {
52
+ min: @y_axis_view_window_min,
53
+ },
54
+ },
55
+ }
56
+ end
57
+
58
+ def chart_format_data
59
+ if !@rows.empty? && !@keys.empty?
60
+ @rows.map do |row|
61
+ {
62
+ name: row[:label],
63
+ data: @keys.zip(row[:values]),
64
+ }
65
+ end
66
+ end
67
+ end
68
+
69
+ private
70
+
71
+ def legend_options
72
+ return { position: "top", textStyle: set_font_16 } unless @hide_legend
73
+
74
+ "none"
75
+ end
76
+
77
+ def set_font_16
78
+ { color: "#000", fontName: "GDS Transport", fontSize: "16", italic: false }
79
+ end
80
+
81
+ def set_font_19
82
+ { color: "#000", fontName: "GDS Transport", fontSize: "19", italic: false }
83
+ end
84
+
85
+ def series_options
86
+ series = {}
87
+ if @line_colours
88
+ @line_colours.each_with_index do |item, index|
89
+ series[index] = {} unless series[index]
90
+ series[index][:color] = item
91
+ end
92
+ end
93
+
94
+ if @line_styles
95
+ @line_styles.each_with_index do |item, index|
96
+ style = [2, 2] if item == "dotted"
97
+ series[index] = {} unless series[index]
98
+ series[index][:lineDashStyle] = style
99
+ end
100
+ end
101
+
102
+ series
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,36 @@
1
+ module GovukPublishingComponents
2
+ module Presenters
3
+ # @private
4
+ class ContentBreadcrumbsBasedOnOrganisations
5
+ def self.call(content_item)
6
+ new(content_item).breadcrumbs
7
+ end
8
+
9
+ def initialize(content_item)
10
+ @content_item = ContentItem.new(content_item)
11
+ end
12
+
13
+ def breadcrumbs
14
+ [
15
+ { title: "Home", url: "/" },
16
+ { title: "Organisations", url: "/government/organisations" },
17
+ *organisation_breadcrumbs_items,
18
+ ]
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :content_item
24
+
25
+ def organisation_breadcrumbs_items
26
+ first_related_organisation = ContentItem.new(content_item.related_organisations.first)
27
+ return [] unless first_related_organisation.present?
28
+
29
+ [{
30
+ title: first_related_organisation.title,
31
+ url: first_related_organisation.base_path,
32
+ }]
33
+ end
34
+ end
35
+ end
36
+ end
@@ -33,6 +33,10 @@ module GovukPublishingComponents
33
33
  @taxon_breadcrumbs ||= ContentBreadcrumbsBasedOnTaxons.call(content_item)
34
34
  end
35
35
 
36
+ def organisation_breadcrumbs
37
+ @organisation_breadcrumbs ||= ContentBreadcrumbsBasedOnOrganisations.call(content_item)
38
+ end
39
+
36
40
  def breadcrumbs
37
41
  breadcrumbs_based_on_ancestors
38
42
  end
@@ -56,6 +60,10 @@ module GovukPublishingComponents
56
60
  content_is_tagged_to_a_live_taxon? && !content_is_a_specialist_document?
57
61
  end
58
62
 
63
+ def use_organisation_breadcrumbs?
64
+ content_is_a_corporate_information_page? && content_has_related_organisations?
65
+ end
66
+
59
67
  def content_tagged_to_a_finder?
60
68
  content_item.dig("links", "finder").present?
61
69
  end
@@ -72,6 +80,10 @@ module GovukPublishingComponents
72
80
  content_item.dig("links", "ordered_related_items").present? && content_item.dig("links", "parent").present?
73
81
  end
74
82
 
83
+ def content_has_related_organisations?
84
+ ContentItem.new(content_item).related_organisations.present?
85
+ end
86
+
75
87
  def content_is_tagged_to_a_live_taxon?
76
88
  content_item.dig("links", "taxons").to_a.any? { |taxon| taxon["phase"] == "live" }
77
89
  end
@@ -80,6 +92,10 @@ module GovukPublishingComponents
80
92
  content_item["schema_name"] == "specialist_document"
81
93
  end
82
94
 
95
+ def content_is_a_corporate_information_page?
96
+ content_item["schema_name"] == "corporate_information_page"
97
+ end
98
+
83
99
  def content_is_a_html_publication?
84
100
  content_item["document_type"] == "html_publication"
85
101
  end
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "45.6.1".freeze
2
+ VERSION = "45.7.0".freeze
3
3
  end
@@ -15,6 +15,7 @@ require "govuk_publishing_components/presenters/big_number_helper"
15
15
  require "govuk_publishing_components/presenters/breadcrumbs_helper"
16
16
  require "govuk_publishing_components/presenters/breadcrumb_selector"
17
17
  require "govuk_publishing_components/presenters/button_helper"
18
+ require "govuk_publishing_components/presenters/chart_helper"
18
19
  require "govuk_publishing_components/presenters/contextual_navigation"
19
20
  require "govuk_publishing_components/presenters/devolved_nations_helper"
20
21
  require "govuk_publishing_components/presenters/emergency_banner_helper"
@@ -24,6 +25,7 @@ require "govuk_publishing_components/presenters/step_by_step_nav_helper"
24
25
  require "govuk_publishing_components/presenters/page_with_step_by_step_navigation"
25
26
  require "govuk_publishing_components/presenters/public_layout_helper"
26
27
  require "govuk_publishing_components/presenters/content_breadcrumbs_based_on_ancestors"
28
+ require "govuk_publishing_components/presenters/content_breadcrumbs_based_on_organisations"
27
29
  require "govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons"
28
30
  require "govuk_publishing_components/presenters/checkboxes_helper"
29
31
  require "govuk_publishing_components/presenters/select_helper"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_publishing_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 45.6.1
4
+ version: 45.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-21 00:00:00.000000000 Z
11
+ date: 2024-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chartkick
@@ -939,9 +939,11 @@ files:
939
939
  - lib/govuk_publishing_components/presenters/breadcrumb_selector.rb
940
940
  - lib/govuk_publishing_components/presenters/breadcrumbs_helper.rb
941
941
  - lib/govuk_publishing_components/presenters/button_helper.rb
942
+ - lib/govuk_publishing_components/presenters/chart_helper.rb
942
943
  - lib/govuk_publishing_components/presenters/checkboxes_helper.rb
943
944
  - lib/govuk_publishing_components/presenters/component_wrapper_helper.rb
944
945
  - lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_ancestors.rb
946
+ - lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_organisations.rb
945
947
  - lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons.rb
946
948
  - lib/govuk_publishing_components/presenters/content_item.rb
947
949
  - lib/govuk_publishing_components/presenters/contents_list_helper.rb