From 9f5ed5bd20f6b72fb9507ba46562b537d0610f83 Mon Sep 17 00:00:00 2001 From: Andy Sellick Date: Fri, 18 Oct 2024 16:42:36 +0100 Subject: [PATCH] Add option for chart height - currently hard coded as the chart isn't responsive - quite difficult to write a test for this as it's applied as an inline style --- .../components/_chart.html.erb | 3 +- .../components/docs/chart.yml | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/app/views/govuk_publishing_components/components/_chart.html.erb b/app/views/govuk_publishing_components/components/_chart.html.erb index 05ecf38284..09101aa3d4 100644 --- a/app/views/govuk_publishing_components/components/_chart.html.erb +++ b/app/views/govuk_publishing_components/components/_chart.html.erb @@ -16,6 +16,7 @@ minimal_link ||= nil hide_legend ||= minimal link ||= false + height ||= 400 chart_id = "chart-id-#{SecureRandom.hex(4)}" table_id = "table-id-#{SecureRandom.hex(4)}" @@ -49,7 +50,7 @@ enableInteractivity: enableInteractivity, legend: legend, pointSize: pointSize, - height: 400, + height: height, tooltip: { isHtml: true }, hAxis: { textStyle: font_16, diff --git a/app/views/govuk_publishing_components/components/docs/chart.yml b/app/views/govuk_publishing_components/components/docs/chart.yml index 67176ec3aa..f34b4d601b 100644 --- a/app/views/govuk_publishing_components/components/docs/chart.yml +++ b/app/views/govuk_publishing_components/components/docs/chart.yml @@ -286,3 +286,43 @@ examples: - 118 - 85 - 80 + with_a_different_height: + description: | + Sets a height in pixels for the chart, defaulting to `400`. This is useful where the chart might appear in a narrow column and the default height would be too tall. + + The component is not currently responsive. + data: + chart_heading: Page views + h_axis_title: Day + v_axis_title: Views + minimal: true + minimal_link: "https://www.gov.uk" + chart_overview: This is a graph of views per day + height: 200 + keys: + - 1st + - 2nd + - 3rd + - 4th + - 5th + - 6th + - 7th + rows: + - label: January 2015 + values: + - 5 + - 119 + - 74 + - 117 + - 33 + - 89 + - 79 + - label: January 2016 + values: + - 3 + - 8 + - 37 + - 82 + - 118 + - 85 + - 80