From fbbc461c97713ea74cab9aa5fa955df97ee6166b Mon Sep 17 00:00:00 2001 From: Watson Date: Thu, 14 Mar 2024 05:25:48 +0900 Subject: [PATCH] Add the way to make background transparent --- lib/gruff/base.rb | 18 ++++++++++++++++-- lib/gruff/renderer/renderer.rb | 4 +++- lib/gruff/spider.rb | 4 ---- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/gruff/base.rb b/lib/gruff/base.rb index b71b0664..696b59bf 100644 --- a/lib/gruff/base.rb +++ b/lib/gruff/base.rb @@ -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. # @@ -378,7 +386,13 @@ def replace_colors(color_list = []) # background_direction: :top_bottom # } # - # +background_image: 'squirrel.png'+ is also possible. + # +background_colors+ + # - Array 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+ @@ -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 diff --git a/lib/gruff/renderer/renderer.rb b/lib/gruff/renderer/renderer.rb index 4a006a42..bc39173b 100644 --- a/lib/gruff/renderer/renderer.rb +++ b/lib/gruff/renderer/renderer.rb @@ -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 diff --git a/lib/gruff/spider.rb b/lib/gruff/spider.rb index 09da843d..ea97ddba 100644 --- a/lib/gruff/spider.rb +++ b/lib/gruff/spider.rb @@ -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