lib/gchart.rb in mokolabs-googlecharts-1.3.3 vs lib/gchart.rb in mokolabs-googlecharts-1.3.4
- old
+ new
@@ -13,31 +13,28 @@
@@chars = @@simple_chars + ['-', '.']
@@ext_pairs = @@chars.map { |char_1| @@chars.map { |char_2| char_1 + char_2 } }.flatten
@@file_name = 'chart.png'
attr_accessor :title, :type, :width, :height, :horizontal, :grouped, :legend, :data, :encoding, :max_value, :bar_colors,
- :title_color, :title_size, :custom, :axis_with_labels, :axis_labels, :bar_width_and_spacing
+ :title_color, :title_size, :custom, :axis_with_labels, :axis_labels, :bar_width_and_spacing, :id, :alt, :class
- class << self
- # Support for Gchart.line(:title => 'my title', :size => '400x600')
- def method_missing(m, options={})
- # Extract the format and optional filename, then clean the hash
- format = options[:format] || 'url'
- @@file_name = options[:filename] unless options[:filename].nil?
- options.delete(:format)
- options.delete(:filename)
- # create the chart and return it in the format asked for
- if @@types.include?(m.to_s)
- chart = new(options.merge!({:type => m}))
- chart.send(format)
- elsif m.to_s == 'version'
- Gchart::VERSION::STRING
- else
- "#{m} is not a supported chart format, please use one of the following: #{supported_types}."
- end
- end
-
+ # Support for Gchart.line(:title => 'my title', :size => '400x600')
+ def self.method_missing(m, options={})
+ # Extract the format and optional filename, then clean the hash
+ format = options[:format] || 'url'
+ @@file_name = options[:filename] unless options[:filename].nil?
+ options.delete(:format)
+ options.delete(:filename)
+ # create the chart and return it in the format asked for
+ if @@types.include?(m.to_s)
+ chart = new(options.merge!({:type => m}))
+ chart.send(format)
+ elsif m.to_s == 'version'
+ Gchart::VERSION::STRING
+ else
+ "#{m} is not a supported chart format, please use one of the following: #{supported_types}."
+ end
end
def initialize(options={})
@type = :line
@data = []
@@ -45,12 +42,15 @@
@height = 200
@horizontal = false
@grouped = false
@encoding = 'simple'
@max_value = 'auto'
+ # Sets the alt tag when chart is exported as image tag
@alt = 'Google Chart'
+ # Sets the CSS id selector when chart is exported as image tag
@id = false
+ # Sets the CSS class selector when chart is exported as image tag
@class = false
# set the options value if definable
options.each do |attribute, value|
send("#{attribute.to_s}=", value) if self.respond_to?("#{attribute}=")
@@ -67,36 +67,9 @@
@width, @height = size.split("x").map { |dimension| dimension.to_i }
end
def size
"#{@width}x#{@height}"
- end
-
- # Sets the alt tag when chart is exported as image tag
- def alt=(alt='Google Chart')
- @alt = alt
- end
-
- def alt
- @alt
- end
-
- # Sets the CSS id selector when chart is exported as image tag
- def id=(id=false)
- @id = id
- end
-
- def id
- @id
- end
-
- # Sets the CSS class selector when chart is exported as image tag
- def class=(klass=false)
- @class = klass
- end
-
- def class
- @class
end
# Sets the orientation of a bar graph
def orientation=(orientation='h')
if orientation == 'h' || orientation == 'horizontal'
\ No newline at end of file