Class: Prawn::Graph::Theme

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

Constant Summary collapse

Default =
{series:['EBEDEF', 'D6DBDF', '85929E', '34495E', '1B2631' ], title:'17202A', background:'FFFFFF', grid:'F2F4F4', axes:'17202A', markers:'34495E', stroke_grid_lines:true, default:'333333', average:'34495E', max:'17202A', min:'17202A' }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg) ⇒ Theme

Returns a new instance of Theme.


13
14
15
16
17
# File 'lib/prawn/graph/theme.rb', line 13

def initialize(arg)
  @series_map = {}
  @current_series_color = 0
  @theme = OpenStruct.new(Prawn::Graph::Theme::Default.merge(arg))
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments) ⇒ Object


36
37
38
39
40
41
42
# File 'lib/prawn/graph/theme.rb', line 36

def method_missing(method_name, *arguments)
  if arguments.any?
    @theme.send(method_name, arguments)
  else
    @theme.send(method_name)
  end
end

Instance Attribute Details

#themeObject (readonly)

Returns the value of attribute theme.


5
6
7
# File 'lib/prawn/graph/theme.rb', line 5

def theme
  @theme
end

Class Method Details

.defaultObject

The default theme is special, only create one of them.


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

def self.default
  @@_default_theme ||= Prawn::Graph::Theme.new(Prawn::Graph::Theme::Default)
end

Instance Method Details

#==(other) ⇒ Object


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

def ==(other)
  theme == other.theme
end

#color_for(series) ⇒ Object


27
28
29
30
# File 'lib/prawn/graph/theme.rb', line 27

def color_for(series)
  @series_map[series.uuid] = cycle_color unless @series_map.has_key?(series.uuid)
  @series_map[series.uuid]
end

#font_sizesObject


32
33
34
# File 'lib/prawn/graph/theme.rb', line 32

def font_sizes
  @font_sizes ||= OpenStruct.new({default:      8, main_title:   10, axis_labels:  5, series_key:   8 })
end

#number_of_colorsObject


19
20
21
# File 'lib/prawn/graph/theme.rb', line 19

def number_of_colors
  theme.series.size
end