Class: Termplot::Widgets::BaseWidget

Inherits:
Object
  • Object
show all
Includes:
Renderable
Defined in:
lib/termplot/widgets/base_widget.rb

Defined Under Namespace

Classes: BorderedWindow

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Renderable

#debug?, #render, #render_to_string

Constructor Details

#initialize(**opts) ⇒ BaseWidget

Returns a new instance of BaseWidget.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/termplot/widgets/base_widget.rb', line 22

def initialize(**opts)
  @cols = opts[:cols] >= min_cols ? opts[:cols] : min_cols
  @rows = opts[:rows] >= min_rows ? opts[:rows] : min_rows
  @window = Window.new(
    cols: @cols,
    rows: @rows
  )

  @bordered_window = BorderedWindow.new(window, default_border_size)
  @debug = opts[:debug]
  @errors = []

  @title = opts[:title]
  @decimals = 2

  @dataset = Dataset.new(max_count)

  post_initialize(opts)
end

Instance Attribute Details

#bordered_windowObject (readonly)

Returns the value of attribute bordered_window.



11
12
13
# File 'lib/termplot/widgets/base_widget.rb', line 11

def bordered_window
  @bordered_window
end

#colsObject (readonly)

Returns the value of attribute cols.



11
12
13
# File 'lib/termplot/widgets/base_widget.rb', line 11

def cols
  @cols
end

#datasetObject (readonly)

Returns the value of attribute dataset.



11
12
13
# File 'lib/termplot/widgets/base_widget.rb', line 11

def dataset
  @dataset
end

#decimalsObject (readonly)

Returns the value of attribute decimals.



11
12
13
# File 'lib/termplot/widgets/base_widget.rb', line 11

def decimals
  @decimals
end

#errorsObject (readonly)

Returns the value of attribute errors.



11
12
13
# File 'lib/termplot/widgets/base_widget.rb', line 11

def errors
  @errors
end

#rowsObject (readonly)

Returns the value of attribute rows.



11
12
13
# File 'lib/termplot/widgets/base_widget.rb', line 11

def rows
  @rows
end

#titleObject (readonly)

Returns the value of attribute title.



11
12
13
# File 'lib/termplot/widgets/base_widget.rb', line 11

def title
  @title
end

#windowObject (readonly)

Returns the value of attribute window.



11
12
13
# File 'lib/termplot/widgets/base_widget.rb', line 11

def window
  @window
end

Instance Method Details

#<<(point) ⇒ Object



46
47
48
49
# File 'lib/termplot/widgets/base_widget.rb', line 46

def <<(point)
  dataset << point
  dataset.set_capacity(max_count)
end

#post_initialize(opts) ⇒ Object



42
43
44
# File 'lib/termplot/widgets/base_widget.rb', line 42

def post_initialize(opts)
  # Implemented by subclasses
end

#render_to_windowObject



51
52
53
# File 'lib/termplot/widgets/base_widget.rb', line 51

def render_to_window
  raise "Must be implemented"
end