Skip to content

Commit

Permalink
Add the way to make background transparent (#631)
Browse files Browse the repository at this point in the history
  • Loading branch information
Watson1978 authored Mar 13, 2024
1 parent e64d87d commit 401eb8e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
18 changes: 16 additions & 2 deletions lib/gruff/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,14 @@ def replace_colors(color_list = [])
@colors = color_list
end

# Set whether to make background transparent.
#
# @param value [Boolean] Specify whether to make background transparent.
#
def transparent_background=(value)
@renderer.transparent_background(@columns, @rows) if value
end

# You can set a theme manually. Assign a hash to this method before you
# send your data.
#
Expand All @@ -378,7 +386,13 @@ def replace_colors(color_list = [])
# background_direction: :top_bottom
# }
#
# +background_image: 'squirrel.png'+ is also possible.
# +background_colors+
# - Array<String> format value - background has gradation. (ex. +background_colors: ['black', 'grey']+)
# - String value - background has solid color. (ex. +background_colors: 'orange'+)
# - nil - background has transparent. (ex. +background_colors: nil+)
#
# +background_image+:
# - Specify the path to image file when it draw the image as background.
#
# +background_direction+ accepts one of following parameters.
# - +:top_bottom+
Expand All @@ -400,7 +414,7 @@ def theme=(options)
marker_color: 'white',
marker_shadow_color: nil,
font_color: 'black',
background_colors: nil,
background_colors: 'gray',
background_image: nil
}
@theme_options = defaults.merge options
Expand Down
4 changes: 3 additions & 1 deletion lib/gruff/renderer/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ def finish
end

def background(columns, rows, scale, theme_options)
return image_background(scale, *theme_options[:background_image]) if theme_options[:background_image]

case theme_options[:background_colors]
when Array
gradated_background(columns, rows, *theme_options[:background_colors][0..1], theme_options[:background_direction])
when String
solid_background(columns, rows, theme_options[:background_colors])
else
image_background(scale, *theme_options[:background_image])
transparent_background(columns, rows)
end
end

Expand Down
4 changes: 0 additions & 4 deletions lib/gruff/spider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ def initialize(max_value, target_width = 800)
@max_value = max_value
end

def transparent_background=(value)
renderer.transparent_background(@columns, @rows) if value
end

def hide_text=(value)
@hide_title = @hide_text = value
end
Expand Down

0 comments on commit 401eb8e

Please sign in to comment.