Skip to content
Browse files

* Changed background gradient direction to use separate theme option:…

… background_direction
  • Loading branch information...
1 parent 0b85fe4 commit 1170186daf778dd2c19156ff7b30083fab73aa12 @donv donv committed
View
168 lib/gruff/base.rb
@@ -304,7 +304,7 @@ def replace_colors(color_list=[])
# graph.theme = {
# :colors => %w(orange purple green white red),
# :marker_color => 'blue',
- # :background_colors => %w(black grey,:top_bottom)
+ # :background_colors => ['black', 'grey', :top_bottom]
# }
#
# :background_image => 'squirrel.png' is also possible.
@@ -315,12 +315,12 @@ def theme=(options)
reset_themes()
defaults = {
- :colors => ['black', 'white'],
- :additional_line_colors => [],
- :marker_color => 'white',
- :font_color => 'black',
- :background_colors => nil,
- :background_image => nil
+ :colors => ['black', 'white'],
+ :additional_line_colors => [],
+ :marker_color => 'white',
+ :font_color => 'black',
+ :background_colors => nil,
+ :background_image => nil
}
@theme_options = defaults.merge options
@@ -373,7 +373,7 @@ def theme_greyscale
def data(name, data_points=[], color=nil)
data_points = Array(data_points) # make sure it's an array
@data << [name, data_points, (color || increment_color)]
- # Set column count if this is larger than previous counts
+ # Set column count if this is larger than previous counts
@column_count = (data_points.length > @column_count) ? data_points.length : @column_count
# Pre-normalize
@@ -413,7 +413,6 @@ def to_blob(fileformat='PNG')
end
-
protected
# Overridden by subclasses to do the actual plotting of the graph.
@@ -425,10 +424,10 @@ def draw
debug {
# Outer margin
- @d.rectangle( @left_margin, @top_margin,
- @raw_columns - @right_margin, @raw_rows - @bottom_margin)
+ @d.rectangle(@left_margin, @top_margin,
+ @raw_columns - @right_margin, @raw_rows - @bottom_margin)
# Graph area box
- @d.rectangle( @graph_left, @graph_top, @graph_right, @graph_bottom)
+ @d.rectangle(@graph_left, @graph_top, @graph_right, @graph_bottom)
}
end
@@ -468,7 +467,7 @@ def normalize(force=false)
if data_point.nil?
norm_data_points << nil
else
- norm_data_points << ((data_point.to_f - @minimum_value.to_f ) / @spread)
+ norm_data_points << ((data_point.to_f - @minimum_value.to_f) / @spread)
end
end
@norm_data << [data_row[DATA_LABEL_INDEX], norm_data_points, data_row[DATA_COLOR_INDEX]]
@@ -486,21 +485,21 @@ def calculate_spread # :nodoc:
def setup_graph_measurements
@marker_caps_height = @hide_line_markers ? 0 :
- calculate_caps_height(@marker_font_size)
+ calculate_caps_height(@marker_font_size)
@title_caps_height = @hide_title ? 0 :
- calculate_caps_height(@title_font_size)
+ calculate_caps_height(@title_font_size)
@legend_caps_height = @hide_legend ? 0 :
- calculate_caps_height(@legend_font_size)
+ calculate_caps_height(@legend_font_size)
if @hide_line_markers
(@graph_left,
- @graph_right_margin,
- @graph_bottom_margin) = [@left_margin, @right_margin, @bottom_margin]
+ @graph_right_margin,
+ @graph_bottom_margin) = [@left_margin, @right_margin, @bottom_margin]
else
longest_left_label_width = 0
if @has_left_labels
- longest_left_label_width = calculate_width(@marker_font_size,
- labels.values.inject('') { |value, memo| (value.to_s.length > memo.to_s.length) ? value : memo }) * 1.25
+ longest_left_label_width = calculate_width(@marker_font_size,
+ labels.values.inject('') { |value, memo| (value.to_s.length > memo.to_s.length) ? value : memo }) * 1.25
else
longest_left_label_width = calculate_width(@marker_font_size,
label(@maximum_value.to_f))
@@ -508,23 +507,23 @@ def setup_graph_measurements
# Shift graph if left line numbers are hidden
line_number_width = @hide_line_numbers && !@has_left_labels ?
- 0.0 :
- (longest_left_label_width + LABEL_MARGIN * 2)
+ 0.0 :
+ (longest_left_label_width + LABEL_MARGIN * 2)
@graph_left = @left_margin +
- line_number_width +
- (@y_axis_label.nil? ? 0.0 : @marker_caps_height + LABEL_MARGIN * 2)
+ line_number_width +
+ (@y_axis_label.nil? ? 0.0 : @marker_caps_height + LABEL_MARGIN * 2)
# Make space for half the width of the rightmost column label.
# Might be greater than the number of columns if between-style bar markers are used.
last_label = @labels.keys.sort.last.to_i
extra_room_for_long_label = (last_label >= (@column_count-1) && @center_labels_over_point) ?
- calculate_width(@marker_font_size, @labels[last_label]) / 2.0 :
- 0
+ calculate_width(@marker_font_size, @labels[last_label]) / 2.0 :
+ 0
@graph_right_margin = @right_margin + extra_room_for_long_label
@graph_bottom_margin = @bottom_margin +
- @marker_caps_height + LABEL_MARGIN
+ @marker_caps_height + LABEL_MARGIN
end
@graph_right = @raw_columns - @graph_right_margin
@@ -533,11 +532,11 @@ def setup_graph_measurements
# When @hide title, leave a title_margin space for aesthetics.
# Same with @hide_legend
@graph_top = @top_margin +
- (@hide_title ? title_margin : @title_caps_height + title_margin ) +
- (@hide_legend ? legend_margin : @legend_caps_height + legend_margin)
+ (@hide_title ? title_margin : @title_caps_height + title_margin) +
+ (@hide_legend ? legend_margin : @legend_caps_height + legend_margin)
x_axis_label_height = @x_axis_label.nil? ? 0.0 :
- @marker_caps_height + LABEL_MARGIN
+ @marker_caps_height + LABEL_MARGIN
# FIXME: Consider chart types other than bar
@graph_bottom = @raw_rows - @graph_bottom_margin - x_axis_label_height - @label_stagger_height
@graph_height = @graph_bottom - @graph_top
@@ -557,10 +556,10 @@ def draw_axis_labels
@d.stroke('transparent')
@d.pointsize = scale_fontsize(@marker_font_size)
@d.gravity = NorthGravity
- @d = @d.annotate_scaled( @base_image,
- @raw_columns, 1.0,
- 0.0, x_axis_label_y_coordinate,
- @x_axis_label, @scale)
+ @d = @d.annotate_scaled(@base_image,
+ @raw_columns, 1.0,
+ 0.0, x_axis_label_y_coordinate,
+ @x_axis_label, @scale)
debug { @d.line 0.0, x_axis_label_y_coordinate, @raw_columns, x_axis_label_y_coordinate }
end
@@ -568,10 +567,10 @@ def draw_axis_labels
# Y Axis, rotated vertically
@d.rotation = -90.0
@d.gravity = CenterGravity
- @d = @d.annotate_scaled( @base_image,
- 1.0, @raw_rows,
- @left_margin + @marker_caps_height / 2.0, 0.0,
- @y_axis_label, @scale)
+ @d = @d.annotate_scaled(@base_image,
+ 1.0, @raw_rows,
+ @left_margin + @marker_caps_height / 2.0, 0.0,
+ @y_axis_label, @scale)
@d.rotation = 90.0
end
end
@@ -616,7 +615,7 @@ def draw_line_markers
@d = @d.line(@graph_left, y, @graph_right, y)
marker_label = BigDecimal(index.to_s) * BigDecimal(@increment.to_s) +
- BigDecimal(@minimum_value.to_s)
+ BigDecimal(@minimum_value.to_s)
unless @hide_line_numbers
@d.fill = @font_color
@@ -626,10 +625,10 @@ def draw_line_markers
@d.gravity = EastGravity
# Vertically center with 1.0 for the height
- @d = @d.annotate_scaled( @base_image,
- @graph_left - LABEL_MARGIN, 1.0,
- 0.0, y,
- label(marker_label), @scale)
+ @d = @d.annotate_scaled(@base_image,
+ @graph_left - LABEL_MARGIN, 1.0,
+ 0.0, y,
+ label(marker_label), @scale)
end
end
@@ -682,7 +681,7 @@ def center(size)
def draw_legend
return if @hide_legend
- @legend_labels = @data.collect {|item| item[DATA_LABEL_INDEX] }
+ @legend_labels = @data.collect { |item| item[DATA_LABEL_INDEX] }
legend_square_width = @legend_box_size # small square with color of this item
@@ -702,9 +701,9 @@ def draw_legend
end
current_x_offset = center(sum(label_widths.first))
- current_y_offset = @hide_title ?
- @top_margin + title_margin :
- @top_margin + title_margin + @title_caps_height
+ current_y_offset = @hide_title ?
+ @top_margin + title_margin :
+ @top_margin + title_margin + @title_caps_height
@legend_labels.each_with_index do |legend_label, index|
@@ -715,10 +714,10 @@ def draw_legend
@d.stroke('transparent')
@d.font_weight = NormalWeight
@d.gravity = WestGravity
- @d = @d.annotate_scaled( @base_image,
- @raw_columns, 1.0,
- current_x_offset + (legend_square_width * 1.7), current_y_offset,
- legend_label.to_s, @scale)
+ @d = @d.annotate_scaled(@base_image,
+ @raw_columns, 1.0,
+ current_x_offset + (legend_square_width * 1.7), current_y_offset,
+ legend_label.to_s, @scale)
# Now draw box with color of this dataset
@d = @d.stroke('transparent')
@@ -763,10 +762,10 @@ def draw_title
@d.pointsize = scale_fontsize(@title_font_size)
@d.font_weight = BoldWeight
@d.gravity = NorthGravity
- @d = @d.annotate_scaled( @base_image,
- @raw_columns, 1.0,
- 0, @top_margin,
- @title, @scale)
+ @d = @d.annotate_scaled(@base_image,
+ @raw_columns, 1.0,
+ 0, @top_margin,
+ @title, @scale)
end
# Draws column labels below graph, centered over x_offset
@@ -807,9 +806,9 @@ def draw_label(x_offset, index)
@d.pointsize = scale_fontsize(@marker_font_size)
@d.gravity = NorthGravity
@d = @d.annotate_scaled(@base_image,
- 1.0, 1.0,
- x_offset, y_offset,
- label_text, @scale)
+ 1.0, 1.0,
+ x_offset, y_offset,
+ label_text, @scale)
@labels_seen[index] = 1
debug { @d.line 0.0, y_offset, @raw_columns, y_offset }
end
@@ -823,10 +822,10 @@ def draw_no_data
@d.font_weight = NormalWeight
@d.pointsize = scale_fontsize(80)
@d.gravity = CenterGravity
- @d = @d.annotate_scaled( @base_image,
- @raw_columns, @raw_rows/2.0,
- 0, 10,
- @no_data_message, @scale)
+ @d = @d.annotate_scaled(@base_image,
+ @raw_columns, @raw_rows/2.0,
+ 0, 10,
+ @no_data_message, @scale)
end
# Finds the best background to render based on the provided theme options.
@@ -835,7 +834,7 @@ def draw_no_data
def render_background
case @theme_options[:background_colors]
when Array
- @base_image = render_gradiated_background(*@theme_options[:background_colors])
+ @base_image = render_gradiated_background(*@theme_options[:background_colors], @theme_options[:background_direction])
when String
@base_image = render_solid_background(@theme_options[:background_colors])
else
@@ -851,18 +850,22 @@ def render_solid_background(color)
end
# Use with a theme definition method to draw a gradiated background.
- def render_gradiated_background(top_color, bottom_color,direct=:top_bottom)
+ def render_gradiated_background(top_color, bottom_color, direct = :top_bottom)
case direct
when :bottom_top
- gradient_fill = GradientFill.new(100, 0, 0, 0, top_color, bottom_color)
+ gradient_fill = GradientFill.new(0, 0, 100, 0, bottom_color, top_color)
when :left_right
gradient_fill = GradientFill.new(0, 0, 0, 100, top_color, bottom_color)
when :right_left
- gradient_fill = GradientFill.new(0,100,0,0,top_color,bottom_color)
+ gradient_fill = GradientFill.new(0, 0, 0, 100, bottom_color, top_color)
+ when :topleft_bottomright
+ gradient_fill = GradientFill.new(0, 100, 100, 0, top_color, bottom_color)
+ when :topright_bottomleft
+ gradient_fill = GradientFill.new(0, 0, 100, 100, bottom_color, top_color)
else
gradient_fill = GradientFill.new(0, 0, 100, 0, top_color, bottom_color)
end
- Image.new(@columns, @rows,gradient_fill)
+ Image.new(@columns, @rows, gradient_fill)
end
# Use with a theme to use an image (800x600 original) background.
@@ -951,12 +954,12 @@ def significant(i) # :nodoc:
# Sort with largest overall summed value at front of array so it shows up
# correctly in the drawn graph.
def sort_norm_data
- @norm_data.sort! { |a,b| sums(b[DATA_VALUES_INDEX]) <=> sums(a[DATA_VALUES_INDEX]) }
+ @norm_data.sort! { |a, b| sums(b[DATA_VALUES_INDEX]) <=> sums(a[DATA_VALUES_INDEX]) }
end
def sums(data_set) # :nodoc:
total_sum = 0
- data_set.collect {|num| total_sum += num.to_f }
+ data_set.collect { |num| total_sum += num.to_f }
total_sum
end
@@ -1014,14 +1017,14 @@ def increment_color
# printed as a label.
def label(value)
label = if (@spread.to_f % (@marker_count.to_f==0 ? 1 : @marker_count.to_f) == 0) || !@y_axis_increment.nil?
- value.to_i.to_s
- elsif @spread > 10.0
- sprintf("%0i", value)
- elsif @spread >= 3.0
- sprintf("%0.2f", value)
- else
- value.to_s
- end
+ value.to_i.to_s
+ elsif @spread > 10.0
+ sprintf("%0i", value)
+ elsif @spread >= 3.0
+ sprintf("%0.2f", value)
+ else
+ value.to_s
+ end
parts = label.split('.')
parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{THOUSAND_SEPARATOR}")
@@ -1052,7 +1055,8 @@ def calculate_width(font_size, text)
end # Gruff::Base
- class IncorrectNumberOfDatasetsException < StandardError; end
+ class IncorrectNumberOfDatasetsException < StandardError;
+ end
end # Gruff
@@ -1065,10 +1069,10 @@ def annotate_scaled(img, width, height, x, y, text, scale)
scaled_width = (width * scale) >= 1 ? (width * scale) : 1
scaled_height = (height * scale) >= 1 ? (height * scale) : 1
- self.annotate( img,
- scaled_width, scaled_height,
- x * scale, y * scale,
- text)
+ self.annotate(img,
+ scaled_width, scaled_height,
+ x * scale, y * scale,
+ text)
end
end
View
BIN test/output/bar_background_gradient_bottom_top.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN test/output/bar_background_gradient_left_right.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN test/output/bar_background_gradient_right_left.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN test/output/bar_background_gradient_top_bottom.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN test/output/bar_background_gradient_topleft_bottomright.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN test/output/bar_background_gradient_topright_bottomleft.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
225 test/test_bar.rb
@@ -9,13 +9,13 @@ class TestGruffBar < GruffTestCase
def setup
super
@datasets = [
- [:Jimmy, [25, 36, 86, 39]],
- [:Charles, [80, 54, 67, 54]],
- [:Julie, [22, 29, 35, 38]],
- #[:Jane, [95, 95, 95, 90, 85, 80, 88, 100]],
- #[:Philip, [90, 34, 23, 12, 78, 89, 98, 88]],
- #["Arthur", [5, 10, 13, 11, 6, 16, 22, 32]],
- ]
+ [:Jimmy, [25, 36, 86, 39]],
+ [:Charles, [80, 54, 67, 54]],
+ [:Julie, [22, 29, 35, 38]],
+ #[:Jane, [95, 95, 95, 90, 85, 80, 88, 100]],
+ #[:Philip, [90, 34, 23, 12, 78, 89, 98, 88]],
+ #["Arthur", [5, 10, 13, 11, 6, 16, 22, 32]],
+ ]
end
def test_bar_graph
@@ -23,18 +23,18 @@ def test_bar_graph
g.title = "Bar Graph Test"
g.title_margin = 100
g.write("test/output/bar_keynote.png")
-
+
g = setup_basic_graph
g.title = "Visual Multi-Line Bar Graph Test"
g.theme = Gruff::Themes::RAILS_KEYNOTE
g.write("test/output/bar_rails_keynote.png")
-
+
g = setup_basic_graph
g.title = "Visual Multi-Line Bar Graph Test"
g.theme = Gruff::Themes::ODEO
g.write("test/output/bar_odeo.png")
end
-
+
def test_thousand_separators
g = Gruff::Bar.new(600)
g.title = "Formatted numbers"
@@ -48,17 +48,17 @@ def test_bar_graph_set_colors
g.title = "Bar Graph With Manual Colors"
g.legend_margin = 50
g.labels = {
- 0 => '5/6',
- 1 => '5/15',
- 2 => '5/24',
- 3 => '5/30',
+ 0 => '5/6',
+ 1 => '5/15',
+ 2 => '5/24',
+ 3 => '5/30',
}
g.data(:Art, [0, 5, 8, 15], '#990000')
g.data(:Philosophy, [10, 3, 2, 8], '#009900')
g.data(:Science, [2, 15, 8, 11], '#990099')
g.minimum_value = 0
-
+
g.write("test/output/bar_manual_colors.png")
end
@@ -66,10 +66,10 @@ def test_bar_graph_small
g = Gruff::Bar.new(400)
g.title = "Visual Multi-Line Bar Graph Test"
g.labels = {
- 0 => '5/6',
- 1 => '5/15',
- 2 => '5/24',
- 3 => '5/30',
+ 0 => '5/6',
+ 1 => '5/15',
+ 2 => '5/24',
+ 3 => '5/30',
}
@datasets.each do |data|
g.data(data[0], data[1])
@@ -91,29 +91,29 @@ def test_no_line_markers
g = setup_basic_graph(400)
g.title = "No Line Markers"
g.hide_line_markers = true
- g.write("test/output/bar_no_line_markers.png")
+ g.write("test/output/bar_no_line_markers.png")
end
def test_no_legend
g = setup_basic_graph(400)
g.title = "No Legend"
g.hide_legend = true
- g.write("test/output/bar_no_legend.png")
+ g.write("test/output/bar_no_legend.png")
end
def test_no_title
g = setup_basic_graph(400)
g.title = "No Title"
g.hide_title = true
- g.write("test/output/bar_no_title.png")
+ g.write("test/output/bar_no_title.png")
end
-
+
def test_no_title_or_legend
g = setup_basic_graph(400)
g.title = "No Title or Legend"
g.hide_legend = true
g.hide_title = true
- g.write("test/output/bar_no_title_or_legend.png")
+ g.write("test/output/bar_no_title_or_legend.png")
end
def test_set_marker_count
@@ -128,7 +128,7 @@ def test_set_legend_box_size
g.title = "Set Small Legend Box Size"
g.legend_box_size = 10.0
g.write("test/output/bar_set_legend_box_size_sm.png")
-
+
g = setup_basic_graph(400)
g.title = "Set Large Legend Box Size"
g.legend_box_size = 50.0
@@ -140,13 +140,13 @@ def test_x_y_labels
g.title = "X Y Labels"
g.x_axis_label = 'Score (%)'
g.y_axis_label = "Students"
- g.write("test/output/bar_x_y_labels.png")
+ g.write("test/output/bar_x_y_labels.png")
end
def test_wide_graph
g = setup_basic_graph('800x400')
g.title = "Wide Graph"
- g.write("test/output/bar_wide_graph.png")
+ g.write("test/output/bar_wide_graph.png")
g = setup_basic_graph('400x200')
g.title = "Wide Graph Small"
@@ -169,10 +169,10 @@ def test_one_value
g = Gruff::Bar.new
g.title = "One Value Graph Test"
g.labels = {
- 0 => '1',
- 1 => '2'
+ 0 => '1',
+ 1 => '2'
}
- g.data('one', [1,1])
+ g.data('one', [1, 1])
g.write("test/output/bar_one_value.png")
end
@@ -182,10 +182,10 @@ def test_negative
g = Gruff::Bar.new
g.title = "Pos/Neg Bar Graph Test"
g.labels = {
- 0 => '5/6',
- 1 => '5/15',
- 2 => '5/24',
- 3 => '5/30',
+ 0 => '5/6',
+ 1 => '5/15',
+ 2 => '5/24',
+ 3 => '5/30',
}
g.data(:apples, [-1, 0, 4, -4])
g.data(:peaches, [10, 8, 6, 3])
@@ -198,10 +198,10 @@ def test_nearly_zero
g = Gruff::Bar.new
g.title = "Nearly Zero Graph"
g.labels = {
- 0 => '5/6',
- 1 => '5/15',
- 2 => '5/24',
- 3 => '5/30',
+ 0 => '5/6',
+ 1 => '5/15',
+ 2 => '5/24',
+ 3 => '5/30',
}
g.data(:apples, [1, 2, 3, 4])
g.data(:peaches, [4, 3, 2, 1])
@@ -221,10 +221,10 @@ def generate_with_y_axis_increment(increment)
g = Gruff::Bar.new
g.title = "Y Axis Set to #{increment}"
g.labels = {
- 0 => '5/6',
- 1 => '5/15',
- 2 => '5/24',
- 3 => '5/30',
+ 0 => '5/6',
+ 1 => '5/15',
+ 2 => '5/24',
+ 3 => '5/30',
}
g.y_axis_increment = increment
g.data(:apples, [1, 0.2, 0.5, 0.7])
@@ -237,10 +237,10 @@ def test_custom_spacing
g.spacing_factor = 0
g.title = "Zero spacing graff"
g.labels = {
- 0 => '5/6',
- 1 => '5/15',
- 2 => '5/24',
- 3 => '5/30',
+ 0 => '5/6',
+ 1 => '5/15',
+ 2 => '5/24',
+ 3 => '5/30',
}
g.data(:apples, [1, 5, 8, 4])
@@ -270,16 +270,16 @@ def test_custom_theme
g.legend_font_size = 32
g.marker_font_size = 32
g.theme = {
- :colors => %w(#efd250 #666699 #e5573f #9595e2),
- :marker_color => 'white',
- :font_color => 'blue',
- :background_image => "assets/pc306715.jpg"
+ :colors => %w(#efd250 #666699 #e5573f #9595e2),
+ :marker_color => 'white',
+ :font_color => 'blue',
+ :background_image => "assets/pc306715.jpg"
}
g.labels = {
- 0 => '5/6',
- 1 => '5/15',
- 2 => '5/24',
- 3 => '5/30',
+ 0 => '5/6',
+ 1 => '5/15',
+ 2 => '5/24',
+ 3 => '5/30',
}
g.data(:vancouver, [1, 2, 3, 4])
g.data(:seattle, [2, 4, 6, 8])
@@ -288,7 +288,98 @@ def test_custom_theme
g.minimum_value = 0
g.write("test/output/bar_themed.png")
end
-
+
+ def test_background_gradient_top_bottom
+ g = Gruff::Bar.new
+ g.title = "Background gradient top to bottom"
+ g.theme = {
+ :background_colors => ['#ff0000', '#00ff00'],
+ :background_direction => :top_bottom,
+ }
+ g.labels = @labels
+ @datasets.each do |name, values|
+ g.data(name, values)
+ end
+ g.minimum_value = 0
+ write_test_file(g, 'bar_background_gradient_top_bottom.png')
+ end
+
+ def test_background_gradient_bottom_top
+ g = Gruff::Bar.new
+ g.title = "Background gradient top to bottom"
+ g.theme = {
+ :background_colors => ['#ff0000', '#00ff00'],
+ :background_direction => :bottom_top,
+ }
+ g.labels = @labels
+ @datasets.each do |name, values|
+ g.data(name, values)
+ end
+ g.minimum_value = 0
+ write_test_file(g, 'bar_background_gradient_bottom_top.png')
+ end
+
+ def test_background_gradient_left_right
+ g = Gruff::Bar.new
+ g.title = "Background gradient left to right"
+ g.theme = {
+ :background_colors => ['#ff0000', '#00ff00'],
+ :background_direction => :left_right,
+ }
+ g.labels = @labels
+ @datasets.each do |name, values|
+ g.data(name, values)
+ end
+ g.minimum_value = 0
+ write_test_file(g, 'bar_background_gradient_left_right.png')
+ end
+
+ def test_background_gradient_right_left
+ g = Gruff::Bar.new
+ g.title = "Background gradient right to left"
+ g.theme = {
+ :background_colors => ['#ff0000', '#00ff00'],
+ :background_direction => :right_left,
+ }
+ g.labels = @labels
+ @datasets.each do |name, values|
+ g.data(name, values)
+ end
+ g.minimum_value = 0
+ write_test_file(g, 'bar_background_gradient_right_left.png')
+ end
+
+ def test_background_gradient_topleft_bottomright
+ g = Gruff::Bar.new
+ g.title = "Background gradient top left to bottom right"
+ g.theme = {
+ :background_colors => ['#ff0000', '#00ff00'],
+ :background_direction => :topleft_bottomright,
+ }
+ g.labels = @labels
+ @datasets.each do |name, values|
+ g.data(name, values)
+ end
+ g.minimum_value = 0
+ write_test_file(g, 'bar_background_gradient_topleft_bottomright.png')
+ end
+
+ def test_background_gradient_topright_bottomleft
+ g = Gruff::Bar.new
+ g.title = "Background gradient top right to bottom left"
+ g.title_font_size = 30
+ g.theme = {
+ :background_colors => ['#ff0000', '#00ff00'],
+ :background_direction => :topright_bottomleft,
+ }
+ g.labels = @labels
+ @datasets.each do |name, values|
+ g.data(name, values)
+ end
+ g.minimum_value = 0
+ write_test_file(g, 'bar_background_gradient_topright_bottomleft.png')
+ end
+
def test_legend_should_not_overlap
g = Gruff::Bar.new(400)
g.theme_37signals()
@@ -305,7 +396,7 @@ def test_july_enhancements
g = Gruff::Bar.new(600)
g.hide_legend = true
g.title = "Full speed ahead"
- g.labels = (0..10).inject({}) { |memo, i| memo.merge({ i => (i*10).to_s}) }
+ g.labels = (0..10).inject({}) { |memo, i| memo.merge({i => (i*10).to_s}) }
g.data(:apples, (0..9).map { rand(20)/10.0 })
g.y_axis_increment = 1.0
g.x_axis_label = 'Score (%)'
@@ -344,7 +435,7 @@ def test_set_label_max_size_and_label_truncation_style
g.label_max_size = 13
g.label_truncation_style = :absolute
g.write("test/output/bar_set_absolute_trunc.png")
-
+
# Trailing Dots trunc
g = setup_long_labelled_graph
g.title = "Trailing dots truncation (6 chars inc dots)"
@@ -353,32 +444,32 @@ def test_set_label_max_size_and_label_truncation_style
g.write("test/output/bar_set_trailing_dots_trunc.png")
end
-protected
+ protected
def setup_basic_graph(size=800)
g = Gruff::Bar.new(size)
g.title = "My Bar Graph"
g.labels = {
- 0 => '5/6',
- 1 => '5/15',
- 2 => '5/24',
- 3 => '5/30',
+ 0 => '5/6',
+ 1 => '5/15',
+ 2 => '5/24',
+ 3 => '5/30',
}
@datasets.each do |data|
g.data(data[0], data[1])
end
g
end
-
+
def setup_long_labelled_graph(size=500)
g = Gruff::Bar.new(size)
g.title = 'A Graph for All Seasons'
g.labels = {
- 0 => 'January was a cold one',
- 1 => 'February is little better',
- 2 => 'March will bring me hares',
- 3 => 'April and I\'m a fool'
+ 0 => 'January was a cold one',
+ 1 => 'February is little better',
+ 2 => 'March will bring me hares',
+ 3 => 'April and I\'m a fool'
}
@datasets.each do |data|

0 comments on commit 1170186

Please sign in to comment.
Something went wrong with that request. Please try again.