module ZTK::GoogleChart::Base::DataTable

Public Instance Methods

data_table(function, *args) click to toggle source
# 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
data_table_function(&block) click to toggle source
# 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
data_table_render() click to toggle source
# 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