Sha256: 9721f7d0cc336cf873266fbaa970e973640c13c84a7bbd718818b965dfb65048

Contents?: true

Size: 1.71 KB

Versions: 1

Compression:

Stored size: 1.71 KB

Contents

module Seer

  module Chart #:nodoc:

    attr_accessor :chart_element, :colors
    
    DEFAULT_COLORS = ['#324F69','#919E4B', '#A34D4D', '#BEC8BE']
    DEFAULT_LEGEND_LOCATION = 'bottom'
    DEFAULT_HEIGHT = 350
    DEFAULT_WIDTH = 550
    
    def in_element=(elem)
      @chart_element = elem
    end
    
    def colors=(colors_list)
      unless colors_list.include?('darker')
        raise ArgumentError, "Invalid color option: #{colors_list}" unless colors_list.is_a?(Array)
        colors_list.each do |color|
          raise ArgumentError, "Invalid color option: #{colors_list}" unless Seer.valid_hex_number?(color)
        end
      end
      @colors = colors_list
    end
    
    def formatted_colors
      if @colors.include?('darker')
        @colors
      else
        "[#{@colors.map{|color| "'#{color.gsub(/\#/,'')}'"} * ','}]"
      end
    end
    
    def data_columns
      _data_columns =  "            data.addRows(#{data_table.size});\r"
      _data_columns << "            data.addColumn('string', '#{label_method}');\r"
      _data_columns << "            data.addColumn('number', '#{data_method}');\r"
      _data_columns
    end
    
    def options
      _options = ""
      nonstring_options.each do |opt|
        if opt == :colors
          _options << "            options['#{opt.to_s.camelize(:lower)}'] = #{self.send(:formatted_colors)};\r" if self.send(opt)
        else
          _options << "            options['#{opt.to_s.camelize(:lower)}'] = #{self.send(opt)};\r" if self.send(opt)
        end
      end
      string_options.each do |opt|
        _options << "            options['#{opt.to_s.camelize(:lower)}'] = '#{self.send(opt)}';\r" if self.send(opt)
      end
      _options
    end
        
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
seer-0.4.0 lib/seer/chart.rb