Class: Cosmos::DataObject
- Defined in:
- lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb
Overview
Represents a data object in a tabbed plots definition Designed for use as a base class for custom data objects
Direct Known Subclasses
Constant Summary collapse
- COLOR_LIST =
List of colors to use
%w(blue red green darkorange gold purple hotpink lime cornflowerblue brown coral crimson indigo tan lightblue cyan peru)
- DEFAULT_ARRAY_SIZE =
Used to create large arrays to prevent memory thrashing with large objects
100000
- PRUNE_HYSTERISIS_PERCENTAGE =
Percent of max seconds saved to achieve hystersis on pruning to reduce memory thrashing
0.10
Instance Attribute Summary collapse
-
#assigned_color ⇒ Object
Assigned Color of the line (string or nil for auto color choice).
-
#color ⇒ Object
Color currently being used to draw the line (string).
-
#data_object_type ⇒ Object
Type of data object (string).
-
#error ⇒ Object
Error associated with this data_object (Exception).
-
#first_x_value ⇒ Object
This value is the first x value for this data object since reset() was called.
-
#max_points_saved ⇒ Object
Max number of data points saved (integer).
-
#name ⇒ Object
Returns the name of this data object.
-
#plot ⇒ Object
Plot holding this data object (subclass of 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 by updating its settings from another data object.
-
#edit_safe?(edited_data_object) ⇒ Boolean
Indicates if the changes made to the data object are safe to perform without reseting its data.
-
#export ⇒ Object
Exports the data object’s data as an array of arrays.
-
#handle_keyword(parser, keyword, parameters) ⇒ Object
Handles data object specific keywords.
-
#initialize ⇒ DataObject
constructor
A new instance of DataObject.
-
#popup_modifier(x_value) ⇒ Object
Supplies text that should be appended to the popup string on mousing over the specified x value.
-
#process_packet(packet, count) ⇒ Object
Processes a packet associated with this data object.
-
#processed_packets ⇒ Object
Returns the packets processed by this data object as an array of [target_name, packet_name] pairs.
-
#prune_to_max_points_saved(force_prune = false) ⇒ Object
Prunes data to max_points_saved.
-
#reset ⇒ Object
Resets the data object’s data (everything that is not configuration).
Constructor Details
#initialize ⇒ DataObject
Returns a new instance of DataObject.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 54 def initialize @plot = nil @max_points_saved = nil @prune_hysterisis = nil # Start this value at the max float so any x_value will be less than it @first_x_value = Float::MAX @error = nil @assigned_color = nil @color = COLOR_LIST[0] # Type is classname without DataObject @data_object_type = self.class.to_s[0..-11].upcase @data_object_type = @data_object_type.split("::")[-1] # remove Cosmos:: if necessary end |
Instance Attribute Details
#assigned_color ⇒ Object
Assigned Color of the line (string or nil for auto color choice)
48 49 50 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 48 def assigned_color @assigned_color end |
#color ⇒ Object
Color currently being used to draw the line (string)
45 46 47 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 45 def color @color end |
#data_object_type ⇒ Object
Type of data object (string)
39 40 41 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 39 def data_object_type @data_object_type end |
#error ⇒ Object
Error associated with this data_object (Exception)
42 43 44 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 42 def error @error end |
#first_x_value ⇒ Object
This value is the first x value for this data object since reset() was called. It is stored here so it can be retrieved even after x values have been pruned.
52 53 54 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 52 def first_x_value @first_x_value end |
#max_points_saved ⇒ Object
Max number of data points saved (integer)
36 37 38 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 36 def max_points_saved @max_points_saved end |
#name ⇒ Object
Returns the name of this data object
149 150 151 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 149 def name 'Unknown' end |
#plot ⇒ Object
Plot holding this data object (subclass of Plot)
30 31 32 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 30 def plot @plot end |
Instance Method Details
#configuration_string ⇒ Object
Returns the configuration lines used to create this data object
70 71 72 73 74 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 70 def configuration_string string = " DATA_OBJECT #{@data_object_type}\n" string << " COLOR #{@assigned_color}\n" if @assigned_color string end |
#copy ⇒ Object
Creates a copy of the data object with settings but without data
125 126 127 128 129 130 131 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 125 def copy data_object = self.class.new data_object.assigned_color = @assigned_color.clone if @assigned_color data_object.color = @color.clone data_object.max_points_saved = @max_points_saved data_object end |
#edit(editted_data_object) ⇒ Object
Edits the data object by updating its settings from another data object
134 135 136 137 138 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 134 def edit(editted_data_object) @assigned_color = editted_data_object.assigned_color @color = editted_data_object.color self.max_points_saved = editted_data_object.max_points_saved end |
#edit_safe?(edited_data_object) ⇒ Boolean
Indicates if the changes made to the data object are safe to perform without reseting its data
144 145 146 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 144 def edit_safe?(edited_data_object) true end |
#export ⇒ Object
Exports the data object’s data as an array of arrays. Each inner array is a column of the output.
120 121 122 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 120 def export raise "export must be defined by class #{self.class}" end |
#handle_keyword(parser, keyword, parameters) ⇒ Object
Handles data object specific keywords
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 77 def handle_keyword(parser, keyword, parameters) case keyword when 'COLOR' # Expect 1 parameter parser.verify_num_parameters(1, 1, "COLOR <Color Name>") @assigned_color = parameters[0].downcase @color = @assigned_color else raise ArgumentError, "Unknown keyword received by #{self.class}: #{keyword}" end end |
#popup_modifier(x_value) ⇒ Object
Supplies text that should be appended to the popup string on mousing over the specified x value
113 114 115 116 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 113 def popup_modifier(x_value) #The default class returns an empty value return "" end |
#process_packet(packet, count) ⇒ Object
Processes a packet associated with this data object
100 101 102 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 100 def process_packet(packet, count) raise "process_packet must be defined by class #{self.class}" end |
#processed_packets ⇒ Object
Returns the packets processed by this data object as an array of
- target_name, packet_name
-
pairs
91 92 93 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 91 def processed_packets raise "processed_packets must be defined by class #{self.class}" end |
#prune_to_max_points_saved(force_prune = false) ⇒ Object
Prunes data to max_points_saved
170 171 172 173 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 170 def prune_to_max_points_saved(force_prune = false) # Must be implemented by subclasses return nil end |
#reset ⇒ Object
Resets the data object’s data (everything that is not configuration)
105 106 107 108 109 |
# File 'lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb', line 105 def reset @error = nil #Reset this value at the max float so any x_value will be less than it @first_x_value = Float::MAX end |