Module: Chartify::WebChart::GoogleChart::GoogleChartModule

Included in:
AreaChart, BarChart, ColumnChart, LineChart, PieChart
Defined in:
lib/chartify/web_chart/google_chart/google_chart_module.rb

Instance Method Summary collapse

Instance Method Details

#array_data_tableObject



23
24
25
26
27
28
29
# File 'lib/chartify/web_chart/google_chart/google_chart_module.rb', line 23

def array_data_table
  array_data = label_column.present? ? [[label_column] + column_names] : [column_names]
  array_data + data.collect do |row|
    row_val = column_keys.collect { |col| row[col] }
    label_column.present? ? [row[label_column]] + row_val : row_val
  end
end

#chart_optionsObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/chartify/web_chart/google_chart/google_chart_module.rb', line 7

def chart_options
  {
      title: title,
      backgroundColor: bg_color,
      colors: web_colors,
      vAxis: {baselineColor: baseline_color,
              gridlines: {color: grid_color},
              textStyle: {color: text_color}},
      hAxis: {baselineColor: baseline_color,
              gridlines: {color: grid_color},
              textStyle: {color: text_color}},
      legend: {textStyle: {color: text_color}},
      lineWidth: config.web_config.line_width
  }
end

#include_jsObject



35
36
37
# File 'lib/chartify/web_chart/google_chart/google_chart_module.rb', line 35

def include_js
  %q{<script type="text/javascript" src="https://www.google.com/jsapi"></script>}
end

#timestampObject



31
32
33
# File 'lib/chartify/web_chart/google_chart/google_chart_module.rb', line 31

def timestamp
  @timestamp ||= Time.now.to_i
end

#wrap_in_function(code) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/chartify/web_chart/google_chart/google_chart_module.rb', line 39

def wrap_in_function(code)
  js = <<-JS
    google.load("visualization", "1", {packages:["corechart"], callback:drawChart#{timestamp}});
    function drawChart#{timestamp}() {
      #{code}
    }
  JS
  js.html_safe
end