Class: GovukPublishingComponents::Presenters::ChartHelper
- Inherits:
-
Object
- Object
- GovukPublishingComponents::Presenters::ChartHelper
- Defined in:
- lib/govuk_publishing_components/presenters/chart_helper.rb
Instance Method Summary collapse
- #brand_colours ⇒ Object
- #chart_format_data ⇒ Object
-
#chart_options ⇒ Object
config options are here: https://developers.google.com/chart/interactive/docs/gallery/linechart.
-
#initialize(options) ⇒ ChartHelper
constructor
A new instance of ChartHelper.
Constructor Details
#initialize(options) ⇒ ChartHelper
Returns a new instance of ChartHelper.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/govuk_publishing_components/presenters/chart_helper.rb', line 4 def initialize() @rows = [:rows] @keys = [:keys] @enable_interactivity = true @hide_legend = [:hide_legend] if @rows && (@rows.length > 1) @hide_legend = false end @point_size = 8 @height = [:height] || 400 @h_axis_title = [:h_axis_title] @v_axis_title = [:v_axis_title] @y_axis_view_window_min = 0 @y_axis_view_window_min = "auto" if [:y_axis_auto_adjust] @line_colours = [:line_colours] @line_styles = [:line_styles] @h_axis_format = "YYYY-MM-dd" if [:h_axis_format] == "date" @h_axis_format = "£#" if [:h_axis_format] == "currency" @h_axis_format = "#'\%'" if [:h_axis_format] == "percent" @v_axis_format = "YYYY-MM-dd" if [:v_axis_format] == "date" @v_axis_format = "£#" if [:v_axis_format] == "currency" @v_axis_format = "#'\%'" if [:v_axis_format] == "percent" end |
Instance Method Details
#brand_colours ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/govuk_publishing_components/presenters/chart_helper.rb', line 60 def brand_colours # The following accessible colour palette has been developed to meet the colour contrast requirements for adjacent colours (as set out in WCAG 2.1) # For charts, the palette should be used instead of the GOV.UK colour palette - https://design-system.service.gov.uk/styles/colour/ # https://gss.civilservice.gov.uk/policy-store/data-visualisation-colours-in-charts/#section-5 gss_colour_dark_blue = "#12436d" gss_colour_turquoise = "#1bbbaf" gss_colour_dark_pink = "#801650" gss_colour_orange = "#f46a25" gss_colour_dark_grey = "#3d3d3d" gss_colour_plum = "#a285d1" [gss_colour_dark_blue, gss_colour_turquoise, gss_colour_dark_pink, gss_colour_orange, gss_colour_dark_grey, gss_colour_plum] end |
#chart_format_data ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/govuk_publishing_components/presenters/chart_helper.rb', line 75 def chart_format_data if !@rows.empty? && !@keys.empty? @rows.map do |row| { name: row[:label], data: @keys.zip(row[:values]), } end end end |
#chart_options ⇒ Object
config options are here: https://developers.google.com/chart/interactive/docs/gallery/linechart
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/govuk_publishing_components/presenters/chart_helper.rb', line 31 def { chartArea: { width: "80%", height: "60%" }, crosshair: { orientation: "vertical", trigger: "both", color: "#ccc" }, curveType: "none", enableInteractivity: @enable_interactivity, legend: , pointSize: @point_size, height: @height, tooltip: { isHtml: true }, series: , hAxis: { textStyle: set_font_16, title: @h_axis_title, titleTextStyle: set_font_19, format: @h_axis_format, }, vAxis: { textStyle: set_font_16, title: @v_axis_title, titleTextStyle: set_font_19, format: @v_axis_format, viewWindow: { min: @y_axis_view_window_min, }, }, } end |