Class: TextChart::SizeCalculator
- Inherits:
-
Object
- Object
- TextChart::SizeCalculator
- Defined in:
- lib/text_chart/size_calculator.rb
Instance Method Summary collapse
-
#calculate_bar_height(bar) ⇒ Object
The number of rows that we should render [Integer].
- #calculate_number_of_columns ⇒ Integer
- #calculate_number_of_rows ⇒ Integer
- #calculate_reference_width ⇒ Integer
- #calculate_x_axis_size ⇒ Integer
- #calculate_y_axis_size ⇒ Integer
-
#initialize(text_chart) ⇒ SizeCalculator
constructor
A new instance of SizeCalculator.
Constructor Details
#initialize(text_chart) ⇒ SizeCalculator
Returns a new instance of SizeCalculator.
5 6 7 |
# File 'lib/text_chart/size_calculator.rb', line 5 def initialize(text_chart) @text_chart = text_chart end |
Instance Method Details
#calculate_bar_height(bar) ⇒ Object
Returns the number of rows that we should render [Integer].
63 64 65 66 67 68 |
# File 'lib/text_chart/size_calculator.rb', line 63 def () return 0 if .zero? = 1 (calculate_increase_percentile(@text_chart.data.min, ) / ).round + end |
#calculate_number_of_columns ⇒ Integer
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/text_chart/size_calculator.rb', line 10 def calculate_number_of_columns @number_of_columns ||= begin result = 0 result += calculate_reference_width y_axis_width = @text_chart.size_config(:y_axis_width) result += y_axis_width left_margin = @text_chart.size_config(:bar_margin) right_margin = @text_chart.size_config(:bar_margin) result += left_margin + right_margin = @text_chart.size_config(:bar_width) result += @text_chart.data.size * = @text_chart.size_config(:bar_margin) # -1 to avoid adding spacing after the last bar. result += (@text_chart.data.size - 1) * result end end |
#calculate_number_of_rows ⇒ Integer
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/text_chart/size_calculator.rb', line 45 def calculate_number_of_rows @number_of_rows ||= begin result = 0 x_axis_row = @text_chart.size_config(:x_axis_height) result += x_axis_row (@text_chart.data.max).times do result += @text_chart.size_config(:bar_row_height) end result end end |
#calculate_reference_width ⇒ Integer
36 37 38 39 40 41 42 |
# File 'lib/text_chart/size_calculator.rb', line 36 def calculate_reference_width @reference_width ||= begin biggest_number_size = @text_chart.data.map(&:to_s).map(&:size).max biggest_number_size end end |
#calculate_x_axis_size ⇒ Integer
71 72 73 |
# File 'lib/text_chart/size_calculator.rb', line 71 def calculate_x_axis_size @x_axis_size ||= calculate_number_of_columns - calculate_reference_width end |
#calculate_y_axis_size ⇒ Integer
76 77 78 79 80 81 82 |
# File 'lib/text_chart/size_calculator.rb', line 76 def calculate_y_axis_size @y_axis_size ||= begin x_axis_row = @text_chart.size_config(:x_axis_height) calculate_number_of_rows - x_axis_row end end |