Class: PrawnCharts::RendererAssistant
- Inherits:
-
Object
- Object
- PrawnCharts::RendererAssistant
- Defined in:
- lib/prawn_charts/renderer_assistant.rb
Instance Attribute Summary collapse
-
#input ⇒ Object
readonly
Parses input data and responds with smart defaults or user specified data.
Instance Method Summary collapse
- #collector ⇒ Object
- #components_to_draw ⇒ Object
-
#dot_radius ⇒ Object
dots.
- #graph_title ⇒ Object
- #graph_title_options ⇒ Object
-
#graph_title_translate ⇒ Object
graph_title.
-
#initialize(input) ⇒ RendererAssistant
constructor
A new instance of RendererAssistant.
-
#x_labels_offset ⇒ Object
x_labels.
- #x_labels_options ⇒ Object
- #x_title ⇒ Object
- #x_title_options ⇒ Object
-
#x_title_translate ⇒ Object
x_title.
-
#y_labels_offset ⇒ Object
y_labels.
- #y_labels_options ⇒ Object
- #y_title ⇒ Object
- #y_title_options ⇒ Object
-
#y_title_translate ⇒ Object
y_title.
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
#input ⇒ Object (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
#collector ⇒ Object
9 10 11 |
# File 'lib/prawn_charts/renderer_assistant.rb', line 9 def collector @collector ||= DataCollector.new(input.fetch(:graph)) end |
#components_to_draw ⇒ Object
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_radius ⇒ Object
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_title ⇒ Object
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_options ⇒ Object
35 36 37 38 |
# File 'lib/prawn_charts/renderer_assistant.rb', line 35 def return unless input.dig(:graph_title, :text_box_options) input[:graph_title][:text_box_options] end |
#graph_title_translate ⇒ Object
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_offset ⇒ Object
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_options ⇒ Object
75 76 77 78 |
# File 'lib/prawn_charts/renderer_assistant.rb', line 75 def return unless input.dig(:x_labels, :text_box_options) input[:x_labels][:text_box_options] end |
#x_title ⇒ Object
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_options ⇒ Object
50 51 52 53 |
# File 'lib/prawn_charts/renderer_assistant.rb', line 50 def return unless input.dig(:x_title, :text_box_options) input[:x_title][:text_box_options] end |
#x_title_translate ⇒ Object
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_offset ⇒ Object
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_options ⇒ Object
85 86 87 88 |
# File 'lib/prawn_charts/renderer_assistant.rb', line 85 def return unless input.dig(:y_labels, :text_box_options) .merge(input[:y_labels][:text_box_options]) end |
#y_title ⇒ Object
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_options ⇒ Object
65 66 67 68 |
# File 'lib/prawn_charts/renderer_assistant.rb', line 65 def return unless input.dig(:y_title, :text_box_options) input[:y_title][:text_box_options] end |
#y_title_translate ⇒ Object
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 |