Skip to content

Commit

Permalink
Add bar/column chart option
Browse files Browse the repository at this point in the history
- can display a bar or column chart instead of a line chart
- also add explicit documentation for the hide_legend option, which seemed to be missing
- not sure if it's possible to write a test for this, as the option is passed to the component, which then calls the chart, so there's no measurable difference in outcome, other than visually within the elements created by the chart JS
  • Loading branch information
andysellick committed Nov 21, 2024
1 parent 789e028 commit 5bfce00
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
rows ||= []
keys ||= []
chart_overview ||= nil
chart_type ||= "line"
minimal ||= false
hide_heading ||= minimal
hide_legend ||= minimal
Expand Down Expand Up @@ -64,7 +65,13 @@
</span>
<% end %>

<%= line_chart(chart_helper.chart_format_data, library: chart_helper.chart_options) %>
<% if chart_type == "column" %>
<%= column_chart(chart_helper.chart_format_data, library: chart_helper.chart_options) %>
<% elsif chart_type == "bar" %>
<%= bar_chart(chart_helper.chart_format_data, library: chart_helper.chart_options) %>
<% else %>
<%= line_chart(chart_helper.chart_format_data, library: chart_helper.chart_options) %>
<% end %>
<% end %>

<% unless minimal %>
Expand Down
72 changes: 71 additions & 1 deletion app/views/govuk_publishing_components/components/docs/chart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ examples:
h_axis_title: Day
v_axis_title: Views
chart_overview: This chart shows page views for January 2015.
hide_legend: true
keys:
- "2015-01-01"
- "2015-01-02"
Expand Down Expand Up @@ -102,6 +101,77 @@ examples:
- 27
- 18
- 34
hide_legend:
data:
chart_heading: Page views chart
h_axis_title: Day
v_axis_title: Views
chart_overview: This chart shows page views for January 2015.
hide_legend: true
keys:
- "2015-01-01"
- "2015-01-02"
- "2015-01-03"
- "2015-01-04"
- "2015-01-05"
- "2015-01-06"
- "2015-01-07"
- "2015-01-08"
- "2015-01-09"
- "2015-01-10"
rows:
- label: January 2015
values:
- 500
- 1190
- 740
- 820
- 270
- 450
- 110
- 210
- 670
- 430
bar_chart:
data:
chart_heading: Hats owned
h_axis_title: Day
v_axis_title: Views
chart_overview: This chart shows page views for January 2015.
chart_type: "bar"
hide_legend: true
keys:
- Jon
- Ash
- James
- Phil
rows:
- label: Hats owned
values:
- 3
- 1
- 1
- 2
column_chart:
data:
chart_heading: Hats owned
h_axis_title: Day
v_axis_title: Views
chart_overview: This chart shows page views for January 2015.
chart_type: "column"
hide_legend: true
keys:
- Jon
- Ash
- James
- Phil
rows:
- label: Hats owned
values:
- 3
- 1
- 1
- 2
vertical table:
description: Reorient the table to better suit the output of some data sets.
data:
Expand Down

0 comments on commit 5bfce00

Please sign in to comment.