Class: Flightdeck::Metrics::LineChart

Inherits:
Chart
  • Object
show all
Defined in:
app/models/flightdeck/metrics/line_chart.rb

Overview

Average completion time: area under a line, with gaps where no jobs finished at all.

Constant Summary collapse

DOT_RADIUS =
3

Constants inherited from Chart

Chart::GRID_INTERVALS, Chart::HEIGHT, Chart::PAD_BOTTOM, Chart::PAD_LEFT, Chart::PAD_RIGHT, Chart::PAD_TOP, Chart::WIDTH

Instance Attribute Summary

Attributes inherited from Chart

#points, #window

Instance Method Summary collapse

Methods inherited from Chart

#axis_max, #empty?, #format_time, #full_time, #gridlines, #height, #initialize, #plot_bottom, #plot_height, #plot_left, #plot_right, #plot_top, #plot_width, #width, #x_ticks

Constructor Details

This class inherits a constructor from Flightdeck::Metrics::Chart

Instance Method Details

#any_data?Boolean

Returns:

  • (Boolean)


47
# File 'app/models/flightdeck/metrics/line_chart.rb', line 47

def any_data? = markers.any?

#area_path(segment) ⇒ Object



37
38
39
40
41
# File 'app/models/flightdeck/metrics/line_chart.rb', line 37

def area_path(segment)
  return "" if segment.empty?

  "#{line_path(segment)} L #{segment.last[:x]} #{plot_bottom} L #{segment.first[:x]} #{plot_bottom} Z"
end

#coordinatesObject



10
11
12
13
14
15
16
17
18
19
# File 'app/models/flightdeck/metrics/line_chart.rb', line 10

def coordinates
  @coordinates ||= points.each_with_index.map do |point, index|
    next nil if point.seconds.nil?

    { x: round(plot_left + (slot_width * index) + (slot_width / 2.0)),
      y: round(y_for(point.seconds)),
      seconds: point.seconds,
      title: point_title(point) }
  end
end

#last_markerObject



45
# File 'app/models/flightdeck/metrics/line_chart.rb', line 45

def last_marker = markers.last

#line_path(segment) ⇒ Object



31
32
33
34
35
# File 'app/models/flightdeck/metrics/line_chart.rb', line 31

def line_path(segment)
  return "" if segment.empty?

  segment.each_with_index.map { |c, i| "#{i.zero? ? "M" : "L"} #{c[:x]} #{c[:y]}" }.join(" ")
end

#markersObject



43
# File 'app/models/flightdeck/metrics/line_chart.rb', line 43

def markers = coordinates.compact

#segmentsObject

Contiguous runs of buckets that had data. Drawing them separately keeps a gap in the data looking like a gap, instead of a straight line across a period we know nothing about.



24
25
26
27
28
29
# File 'app/models/flightdeck/metrics/line_chart.rb', line 24

def segments
  coordinates.chunk_while { |a, b| !a.nil? && !b.nil? }.filter_map do |chunk|
    present = chunk.compact
    present.size.positive? ? present : nil
  end
end