Class: GovukPublishingComponents::Presenters::ChartHelper
- Inherits:
-
Object
- Object
- GovukPublishingComponents::Presenters::ChartHelper
- Defined in:
- lib/govuk_publishing_components/presenters/chart_helper.rb
Instance Method Summary collapse
- #chart_format_data ⇒ Object
-
#chart_options ⇒ Object
config options are here: 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 29 30 |
# File 'lib/govuk_publishing_components/presenters/chart_helper.rb', line 4 def initialize() @rows = [:rows] @keys = [:keys] @minimal = [:minimal] @enable_interactivity = false @enable_interactivity = true unless @minimal @hide_legend = [:hide_legend] @hide_legend = true if @minimal @point_size = [:point_size] ||= 10 @point_size = 0 if @minimal @height = [:height] || 400 @h_axis_title = [:h_axis_title] @v_axis_title = [:v_axis_title] @text_position = "none" if @minimal @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
#chart_format_data ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/govuk_publishing_components/presenters/chart_helper.rb', line 64 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: developers.google.com/chart/interactive/docs/gallery/linechart
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 59 60 61 62 |
# File 'lib/govuk_publishing_components/presenters/chart_helper.rb', line 33 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, textPosition: @text_position, format: @h_axis_format, }, vAxis: { textStyle: set_font_16, title: @v_axis_title, titleTextStyle: set_font_19, textPosition: @text_position, format: @v_axis_format, viewWindow: { min: @y_axis_view_window_min, }, }, } end |