Class: Cosmos::LinegraphDataObject

Inherits:
DataObject show all
Defined in:
lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb

Overview

Represents a data object on a line graph Designed for use as a base class for custom data objects

Direct Known Subclasses

HousekeepingDataObject

Constant Summary collapse

Y_AXIS_CHOICES =

Possible Y-Axis Selections

[:LEFT, :RIGHT]

Constants inherited from DataObject

DataObject::COLOR_LIST, DataObject::DEFAULT_ARRAY_SIZE, DataObject::PRUNE_HYSTERISIS_PERCENTAGE

Instance Attribute Summary collapse

Attributes inherited from DataObject

#assigned_color, #color, #data_object_type, #error, #first_x_value, #max_points_saved, #name, #plot

Instance Method Summary collapse

Methods inherited from DataObject

#edit_safe?, #handle_process_exception, #invalid_value?, #popup_modifier, #process_dart, #process_packet, #process_values, #processed_items, #processed_packets

Constructor Details

#initializeLinegraphDataObject

Create a new LineGraphDataObject



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb', line 49

def initialize
  super()
  @horizontal_lines = []
  @y_offset = 0.0
  @y_axis = :LEFT
  @x_values = LowFragmentationArray.new(DEFAULT_ARRAY_SIZE)
  @y_values = LowFragmentationArray.new(DEFAULT_ARRAY_SIZE)
  @formatted_x_values = LowFragmentationArray.new(DEFAULT_ARRAY_SIZE)
  @x_states = nil
  @y_states = nil
end

Instance Attribute Details

#formatted_x_valuesObject

Array of formatted x_values to graph on the line graph



40
41
42
# File 'lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb', line 40

def formatted_x_values
  @formatted_x_values
end

#horizontal_linesObject

Horizontal lines associated with this data object Typically used to display limits on the line graph Array of arrays of the form [y_value, color]



25
26
27
# File 'lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb', line 25

def horizontal_lines
  @horizontal_lines
end

#x_statesObject

Hash of x states



43
44
45
# File 'lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb', line 43

def x_states
  @x_states
end

#x_valuesObject

Array of x_values to graph on the line graph



34
35
36
# File 'lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb', line 34

def x_values
  @x_values
end

#y_axisObject

Y axis used for this data object - :LEFT or :RIGHT



31
32
33
# File 'lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb', line 31

def y_axis
  @y_axis
end

#y_offsetObject

Y offset applied to each of the data object’s values (float)



28
29
30
# File 'lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb', line 28

def y_offset
  @y_offset
end

#y_statesObject

Hash of y states



46
47
48
# File 'lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb', line 46

def y_states
  @y_states
end

#y_valuesObject

Array of y values to graph on the line graph



37
38
39
# File 'lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb', line 37

def y_values
  @y_values
end

Instance Method Details

#configuration_stringObject

Returns the configuration lines used to create this data object



62
63
64
65
66
67
68
69
70
# File 'lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb', line 62

def configuration_string
  string = super()
  string << "      Y_OFFSET #{@y_offset}\n" if @y_offset != 0.0
  string << "      Y_AXIS #{@y_axis}\n"
  @horizontal_lines.each do |y_value, color|
    string << "      HORIZONTAL_LINE #{y_value} #{color}\n"
  end
  string
end

#copyObject

Creates a copy of the data object with settings but without data



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb', line 123

def copy
  data_object = super()
  horizontal_lines = []
  @horizontal_lines.each do |y_value, color|
    horizontal_lines << [y_value, color.clone]
  end
  data_object.horizontal_lines = horizontal_lines
  data_object.y_offset = @y_offset
  data_object.y_axis = @y_axis

  # States should not be changing, so they will not be deep cloned.
  data_object.x_states = @x_states.clone if @x_states
  data_object.y_states = @y_states.clone if @y_states

  data_object
end

#edit(edited_data_object) ⇒ Object

Edits the data object



141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb', line 141

def edit(edited_data_object)
  super(edited_data_object)
  @horizontal_lines = edited_data_object.horizontal_lines
  if @y_offset != edited_data_object.y_offset
    old_y_offset = @y_offset
    new_y_offset = edited_data_object.y_offset
    @y_values.length.times {|index| @y_values[index] += (new_y_offset - old_y_offset)}
  end
  @y_offset = edited_data_object.y_offset
  @y_axis = edited_data_object.y_axis
  @x_states = edited_data_object.x_states
  @y_states = edited_data_object.y_states
end

#exportObject

Exports the data objects data



114
115
116
117
118
119
120
# File 'lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb', line 114

def export
  if @formatted_x_values.empty?
    [[name().clone, 'X'].concat(@x_values), [name().clone, 'Y'].concat(@y_values)]
  else
    [[name().clone, 'Formatted X'].concat(@formatted_x_values), [name().clone, 'X'].concat(@x_values), [name().clone, 'Y'].concat(@y_values)]
  end
end

#handle_keyword(parser, keyword, parameters) ⇒ Object

Handles data object specific keywords



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb', line 73

def handle_keyword(parser, keyword, parameters)
  case keyword
  when 'HORIZONTAL_LINE'
    # Expect 2 parameters
    parser.verify_num_parameters(2, 2, "HORIZONTAL_LINE <Y Value> <Color>")
    y_value = parameters[0].to_f
    color = parameters[1]
    @horizontal_lines << [y_value, color]

  when 'Y_OFFSET'
    # Expect 1 parameter
    parser.verify_num_parameters(1, 1, "Y_OFFSET <Offset Value>")
    @y_offset = parameters[0].to_f

  when 'Y_AXIS'
    # Expect 1 parameter
    parser.verify_num_parameters(1, 1, "Y_AXIS <LEFT or RIGHT>")
    axis = parameters[0].upcase.intern
    if Y_AXIS_CHOICES.include?(axis)
      @y_axis = axis
    else
      raise ArgumentError, "Unknown Y_AXIS value: #{axis}"
    end

  else
    # Unknown keywords are passed to parent data object
    super(parser, keyword, parameters)

  end # case keyword

end

#resetObject

Resets the line graph data object



106
107
108
109
110
111
# File 'lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb', line 106

def reset
  super()
  @x_values = LowFragmentationArray.new(DEFAULT_ARRAY_SIZE)
  @y_values = LowFragmentationArray.new(DEFAULT_ARRAY_SIZE)
  @formatted_x_values = LowFragmentationArray.new(DEFAULT_ARRAY_SIZE)
end