Class: Chart::Theme

Inherits:
Object
  • Object
show all
Defined in:
lib/gchart/theme.rb

Defined Under Namespace

Classes: ThemeNotFound

Constant Summary collapse

@@theme_files =
["#{File.dirname(__FILE__)}/../themes.yml"]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(theme_name) ⇒ Theme

Returns a new instance of Theme


27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/gchart/theme.rb', line 27

def initialize(theme_name)
  themes = {}
  @@theme_files.each {|f| themes.update YAML::load(File.open(f))}
  theme = themes[theme_name]
  if theme
    self.colors = theme[:colors]
    self.bar_colors = theme[:bar_colors]
    self.background = theme[:background]
    self.chart_background = theme[:chart_background]
    self
  else
    raise(ThemeNotFound, "Could not locate the #{theme_name} theme ...")
  end
end

Instance Attribute Details

#backgroundObject

Returns the value of attribute background


11
12
13
# File 'lib/gchart/theme.rb', line 11

def background
  @background
end

#bar_colorsObject

Returns the value of attribute bar_colors


10
11
12
# File 'lib/gchart/theme.rb', line 10

def bar_colors
  @bar_colors
end

#chart_backgroundObject

Returns the value of attribute chart_background


12
13
14
# File 'lib/gchart/theme.rb', line 12

def chart_background
  @chart_background
end

#colorsObject

Returns the value of attribute colors


9
10
11
# File 'lib/gchart/theme.rb', line 9

def colors
  @colors
end

Class Method Details

.add_theme_file(file) ⇒ Object

Allows you to specify paths for custom theme files in YAML format


23
24
25
# File 'lib/gchart/theme.rb', line 23

def self.add_theme_file(file)
  @@theme_files << file
end

.load(theme_name) ⇒ Object


14
15
16
# File 'lib/gchart/theme.rb', line 14

def self.load(theme_name)
  theme = new(theme_name)
end

.theme_filesObject


18
19
20
# File 'lib/gchart/theme.rb', line 18

def self.theme_files
  @@theme_files
end

Instance Method Details

#to_optionsObject


42
43
44
# File 'lib/gchart/theme.rb', line 42

def to_options
  {:background => background, :chart_background => chart_background, :bar_colors => bar_colors.join(',')}
end