Class: DataAxis
- Inherits:
-
Object
- Object
- DataAxis
- Defined in:
- lib/output/data_axis.rb
Overview
Output class to create the data axis for the dataset and delta output in the x- and y-dimension
Instance Attribute Summary collapse
-
#max_y_indentation ⇒ Object
readonly
private
attribute to store the maximal needed indentation for the y scale.
Instance Method Summary collapse
-
#determine_maximal_domainvalue_length(domain) ⇒ Integer
private
method to determine the maximal string length of a MetaData::DataDomain value.
-
#determine_y_axis_init(domain, key) ⇒ String
private
method to determine if the coordinate of the current y value should be printed or the corresponding number blanks.
-
#extend_x_axis_output(index, domain) ⇒ Object
private
method to print the empty gap between two values of the x-axis and the following value.
-
#initialize ⇒ DataAxis
constructor
initialization.
-
#print_x_axis_init(domain_x) ⇒ Object
private
singleton method to print the initial string of the x axis description.
-
#print_x_axis_markings(domain_x) ⇒ Object
private
method to print axis markings to see which visualized point belongs to the coordinate of the axis values.
-
#print_x_axis_values(domain_x) ⇒ Object
method to print the legend for the x-axis.
-
#print_y_line_beginning(domain, key) ⇒ Object
method to print the legend of the y axis and the start of a line.
Constructor Details
#initialize ⇒ DataAxis
initialization
13 14 15 |
# File 'lib/output/data_axis.rb', line 13 def initialize @max_y_indentation = 0 end |
Instance Attribute Details
#max_y_indentation ⇒ Object (readonly, private)
attribute to store the maximal needed indentation for the y scale
44 45 46 |
# File 'lib/output/data_axis.rb', line 44 def max_y_indentation @max_y_indentation end |
Instance Method Details
#determine_maximal_domainvalue_length(domain) ⇒ Integer (private)
method to determine the maximal string length of a MetaData::DataDomain value
84 85 86 87 88 89 |
# File 'lib/output/data_axis.rb', line 84 def determine_maximal_domainvalue_length(domain) sizes = [ "#{(domain.lower + domain.step).round(3)}".length, "#{(domain.upper + domain.step).round(3)}".length, "#{domain.lower}".length, "#{domain.upper}".length] return sizes.sort.last end |
#determine_y_axis_init(domain, key) ⇒ String (private)
method to determine if the coordinate of the current y value should be printed or the corresponding number blanks
96 97 98 99 100 101 102 |
# File 'lib/output/data_axis.rb', line 96 def determine_y_axis_init(domain, key) if (key % 5 == 0 || key == domain.number_of_values) return "#{domain.get_coordinate_to_index(key).round(3)}" else return String.new() end end |
#extend_x_axis_output(index, domain) ⇒ Object (private)
method to print the empty gap between two values of the x-axis and the following value
74 75 76 77 78 |
# File 'lib/output/data_axis.rb', line 74 def extend_x_axis_output(index, domain) value = "#{domain.get_coordinate_to_index(index).round(3)}" (10 - value.length).times { print ' ' } print "%#{value.length}s" % "#{value}" end |
#print_x_axis_init(domain_x) ⇒ Object (private)
singleton method to print the initial string of the x axis description
63 64 65 66 67 |
# File 'lib/output/data_axis.rb', line 63 def print_x_axis_init(domain_x) (@max_y_indentation).times { print ' '} value = "#{domain_x.get_coordinate_to_index(0).round(3)}" print "%#{value.length}s" % "#{value}" end |
#print_x_axis_markings(domain_x) ⇒ Object (private)
method to print axis markings to see which visualized point belongs to the coordinate of the axis values
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/output/data_axis.rb', line 49 def print_x_axis_markings(domain_x) (@max_y_indentation).times { print ' '} index = 0 print '\\/' while (index < domain_x.number_of_values / 5) 8.times { print '-'} print '\\/' index += 1 end puts end |
#print_x_axis_values(domain_x) ⇒ Object
method to print the legend for the x-axis
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/output/data_axis.rb', line 19 def print_x_axis_values(domain_x) x_value_lenght = determine_maximal_domainvalue_length(domain_x) print_x_axis_markings(domain_x) print_x_axis_init(domain_x) index = 5 while ((x_value_lenght / 2 + index) <= domain_x.number_of_values) extend_x_axis_output(index, domain_x) index += 5 end end |
#print_y_line_beginning(domain, key) ⇒ Object
method to print the legend of the y axis and the start of a line
33 34 35 36 37 38 39 40 |
# File 'lib/output/data_axis.rb', line 33 def print_y_line_beginning(domain, key) max_length = determine_maximal_domainvalue_length(domain) + 1 output = determine_y_axis_init(domain, key) (max_length - output.length).times { output.concat(' ') } @max_y_indentation = output.length if (@max_y_indentation < output.length) print output end |