Skip to content

Commit

Permalink
Add the way to make background transparent
Browse files Browse the repository at this point in the history
  • Loading branch information
Watson1978 committed Mar 13, 2024
1 parent e64d87d commit 0a0e60c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
22 changes: 18 additions & 4 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 @@ -396,11 +410,11 @@ def theme=(options)
reset_themes

defaults = {
colors: %w[black white],
colors: %w[gray white],
marker_color: 'white',
marker_shadow_color: nil,
font_color: 'black',
background_colors: nil,
font_color: 'white',
background_colors: 'black',
background_image: nil
}
@theme_options = defaults.merge options
Expand Down
6 changes: 5 additions & 1 deletion lib/gruff/renderer/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ def background(columns, rows, scale, theme_options)
when String
solid_background(columns, rows, theme_options[:background_colors])
else
image_background(scale, *theme_options[:background_image])
if theme_options[:background_image]
image_background(scale, *theme_options[:background_image])
else
transparent_background(columns, rows)
end
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 0a0e60c

Please sign in to comment.