Class: DataAxis

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeDataAxis

initialization



13
14
15
# File 'lib/output/data_axis.rb', line 13

def initialize
  @max_y_indentation = 0
end

Instance Attribute Details

#max_y_indentationObject (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

Parameters:

  • domain (DataDomain)

    the considered domain

Returns:

  • (Integer)

    the maximal lenght of a string in this domain



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

Parameters:

  • domain (DataDomain)

    the data domain of the y-axis

  • key (Integer)

    the index of the current line

Returns:

  • (String)

    the current y coordinate or an empty string



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

Parameters:

  • index (Integer)

    the index of the data coordinate which should be printed

  • domain (DataDomain)

    the data domain of the x-axis



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

singleton method to print the initial string of the x axis description

Parameters:

  • domain_x (DataDomain)

    the data domain used for the x-axis values



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

method to print axis markings to see which visualized point belongs to the coordinate of the axis values

Parameters:

  • domain_x (DataDomain)

    the data domain used for the x-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

method to print the legend for the x-axis

Parameters:

  • domain_x (DataDomain)

    the data domain used for the x-axis values



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

method to print the legend of the y axis and the start of a line

Parameters:

  • domain (DataDomain)

    the data domain in y

  • key (Integer)

    the index of the dataset in y



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