Class: Cosmos::LinegraphDataObject
- Inherits:
-
DataObject
- Object
- DataObject
- Cosmos::LinegraphDataObject
- 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
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
-
#formatted_x_values ⇒ Object
Array of formatted x_values to graph on the line graph.
-
#horizontal_lines ⇒ Object
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].
-
#x_states ⇒ Object
Hash of x states.
-
#x_values ⇒ Object
Array of x_values to graph on the line graph.
-
#y_axis ⇒ Object
Y axis used for this data object - :LEFT or :RIGHT.
-
#y_offset ⇒ Object
Y offset applied to each of the data object’s values (float).
-
#y_states ⇒ Object
Hash of y states.
-
#y_values ⇒ Object
Array of y values to graph on the line graph.
Attributes inherited from DataObject
#assigned_color, #color, #data_object_type, #error, #first_x_value, #max_points_saved, #name, #plot
Instance Method Summary collapse
-
#configuration_string ⇒ Object
Returns the configuration lines used to create this data object.
-
#copy ⇒ Object
Creates a copy of the data object with settings but without data.
-
#edit(editted_data_object) ⇒ Object
Edits the data object.
-
#export ⇒ Object
Exports the data objects data.
-
#handle_keyword(parser, keyword, parameters) ⇒ Object
Handles data object specific keywords.
-
#initialize ⇒ LinegraphDataObject
constructor
Create a new LineGraphDataObject.
-
#reset ⇒ Object
Resets the line graph data object.
Methods inherited from DataObject
#edit_safe?, #handle_process_exception, #popup_modifier, #process_packet, #processed_packets
Constructor Details
#initialize ⇒ LinegraphDataObject
Create a new LineGraphDataObject
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb', line 50 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_values ⇒ Object
Array of formatted x_values to graph on the line graph
41 42 43 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb', line 41 def formatted_x_values @formatted_x_values end |
#horizontal_lines ⇒ Object
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]
26 27 28 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb', line 26 def horizontal_lines @horizontal_lines end |
#x_states ⇒ Object
Hash of x states
44 45 46 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb', line 44 def x_states @x_states end |
#x_values ⇒ Object
Array of x_values to graph on the line graph
35 36 37 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb', line 35 def x_values @x_values end |
#y_axis ⇒ Object
Y axis used for this data object - :LEFT or :RIGHT
32 33 34 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb', line 32 def y_axis @y_axis end |
#y_offset ⇒ Object
Y offset applied to each of the data object’s values (float)
29 30 31 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb', line 29 def y_offset @y_offset end |
#y_states ⇒ Object
Hash of y states
47 48 49 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb', line 47 def y_states @y_states end |
#y_values ⇒ Object
Array of y values to graph on the line graph
38 39 40 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb', line 38 def y_values @y_values end |
Instance Method Details
#configuration_string ⇒ Object
Returns the configuration lines used to create this data object
63 64 65 66 67 68 69 70 71 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb', line 63 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 |
#copy ⇒ Object
Creates a copy of the data object with settings but without data
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb', line 124 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(editted_data_object) ⇒ Object
Edits the data object
142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb', line 142 def edit(editted_data_object) super(editted_data_object) @horizontal_lines = editted_data_object.horizontal_lines if @y_offset != editted_data_object.y_offset old_y_offset = @y_offset new_y_offset = editted_data_object.y_offset @y_values.length.times {|index| @y_values[index] += (new_y_offset - old_y_offset)} end @y_offset = editted_data_object.y_offset @y_axis = editted_data_object.y_axis @x_states = editted_data_object.x_states @y_states = editted_data_object.y_states end |
#export ⇒ Object
Exports the data objects data
115 116 117 118 119 120 121 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb', line 115 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
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 104 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb', line 74 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 |
#reset ⇒ Object
Resets the line graph data object
107 108 109 110 111 112 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb', line 107 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 |