Class: GoogleVisualr::ColorFormat

Inherits:
Formatter
  • Object
show all
Defined in:
lib/google_visualr/formatters.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Formatter

#columns, #options

Methods included from ParamHelpers

#js_parameters, #stringify_keys!, #typecast

Constructor Details

#initializeColorFormat

Returns a new instance of ColorFormat.



47
48
49
50
# File 'lib/google_visualr/formatters.rb', line 47

def initialize
  @ranges           = Array.new
  @gradient_ranges  = Array.new
end

Instance Attribute Details

#gradient_rangesObject

Returns the value of attribute gradient_ranges.



45
46
47
# File 'lib/google_visualr/formatters.rb', line 45

def gradient_ranges
  @gradient_ranges
end

#rangesObject

Returns the value of attribute ranges.



44
45
46
# File 'lib/google_visualr/formatters.rb', line 44

def ranges
  @ranges
end

Instance Method Details

#add_gradient_range(from, to, color, fromBgColor, toBgColor) ⇒ Object



56
57
58
# File 'lib/google_visualr/formatters.rb', line 56

def add_gradient_range(from, to, color, fromBgColor, toBgColor)
  @gradient_ranges <<  { :from => from, :to => to, :color => color, :fromBgColor => fromBgColor, :toBgColor => toBgColor }
end

#add_range(from, to, color, bgcolor) ⇒ Object



52
53
54
# File 'lib/google_visualr/formatters.rb', line 52

def add_range(from, to, color, bgcolor)
  @ranges << { :from => from, :to => to, :color => color, :bgcolor => bgcolor }
end

#to_jsObject



60
61
62
63
64
65
66
67
68
69
# File 'lib/google_visualr/formatters.rb', line 60

def to_js
  super do |js|
    @ranges.each do |r|
      js << "\nformatter.addRange(#{typecast(r[:from])}, #{typecast(r[:to])}, #{typecast(r[:color])}, #{typecast(r[:bgcolor])});"
    end
    @gradient_ranges.each do |r|
      js << "\nformatter.addGradientRange(#{typecast(r[:from])}, #{typecast(r[:to])}, #{typecast(r[:color])}, #{typecast(r[:fromBgColor])}, #{typecast(r[:toBgColor])});"
    end
  end
end