Class: Cosmos::TimegraphWidget

Inherits:
LinegraphWidget show all
Defined in:
lib/cosmos/tools/tlm_viewer/widgets/timegraph_widget.rb

Overview

TimegraphWidget class

This class creates a graph of the supplied data value versus time.

Constant Summary

Constants inherited from LineGraph

LineGraph::DOUBLE_CLICK_SECONDS, LineGraph::FRAME_OFFSET, LineGraph::GRAPH_SPACER, LineGraph::LABEL_TICK_SIZE, LineGraph::LEFT_X_LABEL_WIDTH_ADJUST

Instance Attribute Summary

Attributes included from Widget

#item, #item_name, #limits_set, #limits_state, #packet, #packet_name, #polling_period, #screen, #settings, #target_name, #value, #value_type

Attributes inherited from LineGraph

#draw_cursor_line_callback, #horizontal_lines, #left_y_max, #left_y_min, #mouse_leave_callback, #mouse_left_button_press_callback, #post_error_callback, #pre_error_callback, #right_y_max, #right_y_min, #x_max, #x_max_label, #x_min, #x_min_label

Instance Method Summary collapse

Methods inherited from LinegraphWidget

takes_value?

Methods included from Widget

#context_menu, #get_tooltip_text, included, #process_settings, #set_setting, #set_subsetting, #shutdown, #update_widget

Methods inherited from LineGraph

#add_horizontal_line, #add_line, #add_popups_for_lines, #adjust_popup_positions, attr_accessor_with_redraw, #auto_scale_x, #auto_scale_y, #auto_scale_y_axis, #build_popups_from_x_value, #build_x_grid_lines, #build_y_grid_lines, #calculate_base, #calculate_scaling_factors, #calculate_x_grid_lines, #calculate_y_grid_lines, #calculate_y_labels, #clear_horizontal_lines, #clear_lines, #convert_x_value_to_text, #convert_y_value_to_text, #determine_graph_size, #draw_cursor_line_and_popups, #draw_cursor_line_and_popups_at_x, #draw_error_icon, #draw_frame, #draw_graph_background, #draw_graph_into_back_buffer, #draw_graph_to_screen, #draw_horizontal_lines, #draw_legend, #draw_legend_text, #draw_line, #draw_lines, #draw_origin_lines, #draw_popups, #draw_title, #draw_x_axis_grid_lines, #draw_x_axis_title, #draw_x_label, #draw_y_axis_grid_lines, #draw_y_axis_title, #draw_y_label, #get_legend_position, #graph, #leaveEvent, #manual_scale_x, #manual_scale_y, #mouseMoveEvent, #mousePressEvent, #mouseReleaseEvent, #paintEvent, #remote_draw_cursor_line_at_x, #resizeEvent, #scale_graph, #scale_graph_to_value_x, #scale_left_to_right_y, #scale_value_to_graph_x, #scale_value_to_graph_y, #update_graph_size

Constructor Details

#initialize(parent_layout, target_name, packet_name, item_name, num_samples = 100, width = 300, height = 200, point_size = 5, time_item_name = 'RECEIVED_TIMESECONDS', value_type = :CONVERTED) ⇒ TimegraphWidget

Returns a new instance of TimegraphWidget.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cosmos/tools/tlm_viewer/widgets/timegraph_widget.rb', line 22

def initialize(parent_layout, target_name, packet_name, item_name, num_samples = 100, width = 300, height = 200, point_size = 5, time_item_name = 'RECEIVED_TIMESECONDS', value_type = :CONVERTED)
  super(parent_layout, target_name, packet_name, item_name, num_samples, width, height, value_type)
  @time_item_name = time_item_name.to_s
  @time = []
  @first_value = true
  @initial_time = 0
  @vs_time = true
  @items = []
  @items << [@target_name, @packet_name, @item_name]
  @items << [@target_name, @packet_name, @time_item_name]
  self.show_y_grid_lines = true
  self.unix_epoch_x_values = true
  self.point_size = Integer(point_size)
end

Instance Method Details

#value=(data) ⇒ Object

Obtains the telemetry item data and it’s corresponding time stamp from the telemetry item name set during widget creation and then adds this data to the LineGraph object.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/cosmos/tools/tlm_viewer/widgets/timegraph_widget.rb', line 40

def value=(data)
  data  = nil
  t_sec = nil

  if @screen.mode == :REALTIME
    begin
      # Even though it has been provided, need to get data and timestamp here.
      # Otherwise, the time stamp may be from a different packet if packets
      # are received too fast
      tlm_items, _, _, _ = get_tlm_values(@items)
      data = tlm_items[0]
      t_sec = tlm_items[1]
      return if t_sec == 0.0 # Don't graph if we have no timestamp
    rescue DRb::DRbConnError
      # If the cts is not available, it must have just recently been lost
      # simply return without updating.
      return
    end
  else # in log mode
    # Note: in logmode value= usually isn't called with every data point so this is never
    # going to work very well.  Will work ok for logfile playback so we will
    # still support it.
    data = System.telemetry.value(@target_name, @packet_name, @item_name)
    t_sec = System.telemetry.value(@target_name, @packet_name, @time_item_name)
  end

  # Don't regraph old data
  return if @time[-1] == t_sec

  # create time array
  @time << t_sec

  # create data array and graph
  @data << data.to_f

  # truncate data if necessary
  if @data.length > @num_samples
    @data = @data[1..-1]
    @time = @time[1..-1]
  end

  self.clear_lines
  self.add_line('line', @data, @time)
  self.graph
end