lib/gchart.rb in matta-googlecharts-1.3.0 vs lib/gchart.rb in matta-googlecharts-1.3.1
- old
+ new
@@ -13,11 +13,11 @@
@@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
+ :title_color, :title_size, :custom, :axis_with_labels, :axis_labels, :bar_width_and_spacing
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
@@ -172,10 +172,32 @@
def set_bar_colors
@bar_colors = @bar_colors.join(',') if @bar_colors.is_a?(Array)
"chco=#{@bar_colors}"
end
+ # set bar spacing
+ # chbh=
+ # <bar width in pixels>,
+ # <optional space between bars in a group>,
+ # <optional space between groups>
+ def set_bar_width_and_spacing
+ width_and_spacing_values = case @bar_width_and_spacing
+ when String
+ @bar_width_and_spacing
+ when Array
+ @bar_width_and_spacing.join(',')
+ when Hash
+ width = @bar_width_and_spacing[:width] || 23
+ spacing = @bar_width_and_spacing[:spacing] || 4
+ group_spacing = @bar_width_and_spacing[:group_spacing] || 8
+ [width,spacing,group_spacing].join(',')
+ else
+ @bar_width_and_spacing.to_s
+ end
+ "chbh=#{width_and_spacing_values}"
+ end
+
def fill_for(type=nil, color='', angle=nil)
unless type.nil?
case type
when 'lg'
angle ||= 0
@@ -351,9 +373,11 @@
set_colors if @bg_color.nil?
when '@data'
set_data unless @data == []
when '@bar_colors'
set_bar_colors
+ when '@bar_width_and_spacing'
+ set_bar_width_and_spacing
when '@axis_with_labels'
set_axis_with_labels
when '@axis_labels'
set_axis_labels
when '@custom'
\ No newline at end of file