Class: PrawnCharts::RendererAssistant

Inherits:
Object
  • Object
show all
Defined in:
lib/prawn_charts/renderer_assistant.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ RendererAssistant

Returns a new instance of RendererAssistant.



5
6
7
# File 'lib/prawn_charts/renderer_assistant.rb', line 5

def initialize(input)
  @input = input
end

Instance Attribute Details

#inputObject (readonly)

Parses input data and responds with smart defaults or user specified data



4
5
6
# File 'lib/prawn_charts/renderer_assistant.rb', line 4

def input
  @input
end

Instance Method Details

#collectorObject



9
10
11
# File 'lib/prawn_charts/renderer_assistant.rb', line 9

def collector
  @collector ||= DataCollector.new(input.fetch(:graph))
end

#components_to_drawObject



13
14
15
16
17
# File 'lib/prawn_charts/renderer_assistant.rb', line 13

def components_to_draw
  available_components = [:rectangle_border, :rectangle_fill, :line, :dots, :x_labels, :y_labels, :horizontal_lines, :graph_title, :y_title, :x_title]
  specified_components = [:rectangle_border, :rectangle_fill, :line] + @input.keys
  @components_to_draw = available_components & specified_components
end

#dot_radiusObject

dots



20
21
22
23
# File 'lib/prawn_charts/renderer_assistant.rb', line 20

def dot_radius
  return default_dot_radius unless input.dig(:dots, :radius)
  input[:dots][:radius]
end

#graph_titleObject



30
31
32
33
# File 'lib/prawn_charts/renderer_assistant.rb', line 30

def graph_title
  raise "Graph must have title" unless input.dig(:graph_title, :title)
  input[:graph_title][:title]
end

#graph_title_optionsObject



35
36
37
38
# File 'lib/prawn_charts/renderer_assistant.rb', line 35

def graph_title_options
  return default_graph_title_options unless input.dig(:graph_title, :text_box_options)
  input[:graph_title][:text_box_options]
end

#graph_title_translateObject

graph_title



26
27
28
# File 'lib/prawn_charts/renderer_assistant.rb', line 26

def graph_title_translate
  [0, collector.height + offset(:graph_title, default_graph_title_offset)]
end

#x_labels_offsetObject

x_labels



71
72
73
# File 'lib/prawn_charts/renderer_assistant.rb', line 71

def x_labels_offset
  offset(:x_labels, default_x_labels_offset)
end

#x_labels_optionsObject



75
76
77
78
# File 'lib/prawn_charts/renderer_assistant.rb', line 75

def x_labels_options
  return default_x_labels_options unless input.dig(:x_labels, :text_box_options)
  input[:x_labels][:text_box_options]
end

#x_titleObject



45
46
47
48
# File 'lib/prawn_charts/renderer_assistant.rb', line 45

def x_title
  raise "Graph must have title" unless input.dig(:x_title, :title)
  input[:x_title][:title]
end

#x_title_optionsObject



50
51
52
53
# File 'lib/prawn_charts/renderer_assistant.rb', line 50

def x_title_options
  return default_x_title_options unless input.dig(:x_title, :text_box_options)
  input[:x_title][:text_box_options]
end

#x_title_translateObject

x_title



41
42
43
# File 'lib/prawn_charts/renderer_assistant.rb', line 41

def x_title_translate
  [0, offset(:x_title, default_x_title_offset)]
end

#y_labels_offsetObject

y_labels



81
82
83
# File 'lib/prawn_charts/renderer_assistant.rb', line 81

def y_labels_offset
  offset(:y_labels, default_y_labels_offset)
end

#y_labels_optionsObject



85
86
87
88
# File 'lib/prawn_charts/renderer_assistant.rb', line 85

def y_labels_options
  return default_y_labels_options unless input.dig(:y_labels, :text_box_options)
  default_y_labels_options.merge(input[:y_labels][:text_box_options])
end

#y_titleObject



60
61
62
63
# File 'lib/prawn_charts/renderer_assistant.rb', line 60

def y_title
  raise "Graph must have title" unless input.dig(:y_title, :title)
  input[:y_title][:title]
end

#y_title_optionsObject



65
66
67
68
# File 'lib/prawn_charts/renderer_assistant.rb', line 65

def y_title_options
  return default_y_title_options unless input.dig(:y_title, :text_box_options)
  input[:y_title][:text_box_options]
end

#y_title_translateObject

y_title



56
57
58
# File 'lib/prawn_charts/renderer_assistant.rb', line 56

def y_title_translate
  [offset(:y_title, default_y_title_offset), 0]
end