Class: Kdep::Dashboard::Layout

Inherits:
Object
  • Object
show all
Defined in:
lib/kdep/dashboard/layout.rb

Constant Summary collapse

MIN_ROWS =
16
MIN_COLS =
60

Instance Method Summary collapse

Constructor Details

#initialize(rows:, cols:) ⇒ Layout

Returns a new instance of Layout.



9
10
11
12
# File 'lib/kdep/dashboard/layout.rb', line 9

def initialize(rows:, cols:)
  @rows = rows
  @cols = cols
end

Instance Method Details

#panelsObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/kdep/dashboard/layout.rb', line 14

def panels
  return nil if @rows < MIN_ROWS || @cols < MIN_COLS

  # Reserve row 0 for header, last row for status bar
  usable_top = 1
  usable_height = @rows - 2  # minus header and status bar
  usable_left = 0
  usable_width = @cols

  top_height = usable_height / 2
  bottom_height = usable_height - top_height

  left_width = (usable_width * 0.6).to_i
  right_width = usable_width - left_width

  bottom_top = usable_top + top_height

  {
    rollout:   Rect.new(usable_top, usable_left, top_height, left_width),
    resources: Rect.new(usable_top, usable_left + left_width, top_height, right_width),
    logs:      Rect.new(bottom_top, usable_left, bottom_height, left_width),
    health:    Rect.new(bottom_top, usable_left + left_width, bottom_height, right_width),
  }
end