topfunky / gruff

Gruff graphing library for Ruby
http://gruff.rubyforge.org
MIT License
1.37k stars 239 forks source link

Add the way to make background transparent #631

Closed Watson1978 closed 8 months ago

Watson1978 commented 8 months ago

Fix https://github.com/topfunky/gruff/issues/630

This patch provides two ways to make the background transparent.

1. #transparent_background=

g = Gruff::Bar.new
g.transparent_background = true # use transparent
g.title = 'Hello world'
g.data :Art, [0, 5, 8, 15]
g.data :Philosophy, [10, 3, 2, 8]
g.data :Science, [2, 15, 8, 11]

g.write('bar.png')

2. Make background to transparent by theme

g = Gruff::Bar.new
g.theme = {
  colors: [
    '#FDD84E',
    '#6886B4',
    '#72AE6E',
    '#D1695E',
    '#8A6EAF',
    '#EFAA43',
    'white'
  ],
  marker_color: 'white',
  font_color: 'white',
  background_colors: nil # use transparent
}
g.title = 'Hello world'
g.data :Art, [0, 5, 8, 15]
g.data :Philosophy, [10, 3, 2, 8]
g.data :Science, [2, 15, 8, 11]

g.write('bar.png')