Module: ZTK::GoogleChart::Base::DataTable

Included in:
ZTK::GoogleChart::Base
Defined in:
lib/ztk/google_chart/base/data_table.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) data_table(function, *args)



7
8
9
10
11
12
# File 'lib/ztk/google_chart/base/data_table.rb', line 7

def data_table(function, *args)
  @chart_method = :data_table
  @chart_data_table ||= Array.new

  @chart_data_table << [function, *args]
end

- (Object) data_table_function(&block)



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ztk/google_chart/base/data_table.rb', line 14

def data_table_function(&block)
  <<-EOCHART
  function #{@chart_draw_tag}() {

    #{@chart_data_tag} = new google.visualization.DataTable();
#{block.call.chomp}

    var #{@chart_options_tag} = #{JSON.pretty_generate(@chart_options).__fix_date};

    #{@chart_name_tag} = new google.visualization.#{@chart_type_tag}(document.getElementById('#{@chart_div_tag}'));
    #{@chart_name_tag}.draw(#{@chart_data_tag}, #{@chart_options_tag});
  }
EOCHART
end

- (Object) data_table_render



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ztk/google_chart/base/data_table.rb', line 29

def data_table_render
  data_table_blob = Array.new
  @chart_data_table.each do |function, *args|
    args = args.collect do |arg|
      if arg.is_a?(Array)
        JSON.pretty_generate(arg).__fix_date
      else
        arg.to_json
      end
    end.join(', ')
    data_table_blob << %(    #{@chart_data_tag}.#{function}(#{args});)
  end

  body do
    data_table_function do
      data_table_blob.join("\n")
    end
  end
end