Module: NeqaHighCharts::ViewsHelper

Defined in:
lib/neqa_high_charts/views_helper.rb

Instance Method Summary collapse

Instance Method Details

#high_chart(div_id, object, div_html_options = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/neqa_high_charts/views_helper.rb', line 3

def high_chart(div_id, object, div_html_options = {})
  div_html_options = {width: "100%", height: "100%"}.merge(div_html_options)
  div_style = generate_div_style_from_hash div_html_options
  div_el ="    <div id=\"\#{div_id}\" style=\"\#{div_style}\"></div>\n  DIV\n  graph =<<-HCJS\n    <script type=\"text/javascript\">\n      $(function () {\n        $(\"#\#{div_id}\").highcharts({\n  \#{option_generate(object)}\n        });\n      });\n    </script>\n  HCJS\n\n  div_el + graph\nend\n"

#option_generate(object) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/neqa_high_charts/views_helper.rb', line 22

def option_generate(object)
  options = ''
  object.instance_variables.each do |v|
    v_name = v.to_s.delete("@")
    v_value = object.instance_variable_get(v)
    if v_value.is_a? Hash
      j_value = '{' + generate_json_from_hash(v_value) + '}'
    else
      j_value = '[' + generate_json_from_array(v_value) + ']'
    end
    option ="    \#{v_name}: \#{j_value},\n    OPTION\n    options += option\n  end\n  options\nend\n"