Module: LazyHighCharts::LayoutHelper

Defined in:
lib/lazy_high_charts/layout_helper.rb

Instance Method Summary collapse

Instance Method Details

#high_chart(placeholder, object, id = "nil", &block) ⇒ Object



5
6
7
8
9
# File 'lib/lazy_high_charts/layout_helper.rb', line 5

def high_chart(placeholder, object  ,id="nil", &block)
  object.html_options.merge!({:id=>placeholder})
  object.options[:chart][:renderTo] = placeholder
  high_graph(placeholder,object ,id, &block).concat(("div","", object.html_options))
end

#high_graph(placeholder, object, id, &block) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/lazy_high_charts/layout_helper.rb', line 17

def high_graph(placeholder, object, id, &block)
  graph =<<-EOJS
  <script type="text/javascript">
  var global_chart_#{id};
  
  
  jQuery(function() {
        // 1. Define JSON options
        var options = {
                      chart: #{object.options[:chart].to_json},
                              title: #{object.options[:title].to_json},
                              legend: #{object.options[:legend].to_json},
                              xAxis: #{object.options[:xAxis].to_json},
                              yAxis: #{object.options[:yAxis].to_json},
                              tooltip:  #{object.options[:tooltip].to_json},
                              credits: #{object.options[:credits].to_json},
                              plotOptions: #{object.options[:plotOptions].to_json},
                              series: #{object.data.to_json},
                              subtitle: #{object.options[:subtitle].to_json}
                      };

        // 2. Add callbacks (non-JSON compliant)
          #{capture(&block) if block_given?}
        // 3. Build the chart
        console.log(global_chart_#{id})
          global_chart_#{id} = new Highcharts.Chart(options);
    });
    </script>
  EOJS
  
  if defined?(raw)
    return raw(graph) 
  else
    return graph
  end
  
end

#high_graph_stock(placeholder, object, &block) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/lazy_high_charts/layout_helper.rb', line 55

def high_graph_stock(placeholder, object, &block)
  graph =<<-EOJS
  <script type="text/javascript">
  jQuery(function() {
        // 1. Define JSON options
        var options = {
                      chart: #{object.options[:chart].to_json},
                              title: #{object.options[:title].to_json},
                              legend: #{object.options[:legend].to_json},
                              xAxis: #{object.options[:xAxis].to_json},
                              yAxis: #{object.options[:yAxis].to_json},
                              tooltip:  #{object.options[:tooltip].to_json},
                              credits: #{object.options[:credits].to_json},
                              plotOptions: #{object.options[:plotOptions].to_json},
                              series: #{object.data.to_json},
                              subtitle: #{object.options[:subtitle].to_json}
                      };

        // 2. Add callbacks (non-JSON compliant)
          #{capture(&block) if block_given?}
        // 3. Build the chart
          var chart = new Highcharts.StockChart(options);
    });
    </script>
  EOJS
  
  if defined?(raw)
    return raw(graph) 
  else
    return graph
  end
  
end

#high_stock(placeholder, object, &block) ⇒ Object



11
12
13
14
15
# File 'lib/lazy_high_charts/layout_helper.rb', line 11

def high_stock(placeholder, object  , &block)
  object.html_options.merge!({:id=>placeholder})
  object.options[:chart][:renderTo] = placeholder
  high_graph_stock(placeholder,object , &block).concat(("div","", object.html_options))
end