Class: Termplot::Widgets::TimeSeriesWidget

Inherits:
BaseWidget
  • Object
show all
Defined in:
lib/termplot/widgets/time_series_widget.rb

Defined Under Namespace

Classes: Point, Tick

Constant Summary collapse

DEFAULT_COLOR =
"yellow"
DEFAULT_LINE_STYLE =
"line"

Instance Attribute Summary collapse

Attributes inherited from BaseWidget

#bordered_window, #cols, #dataset, #decimals, #errors, #rows, #title, #window

Instance Method Summary collapse

Methods inherited from BaseWidget

#<<, #initialize

Methods included from Renderable

#debug?, #render, #render_to_string

Constructor Details

This class inherits a constructor from Termplot::Widgets::BaseWidget

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



15
16
17
# File 'lib/termplot/widgets/time_series_widget.rb', line 15

def color
  @color
end

#line_styleObject (readonly)

Returns the value of attribute line_style.



15
16
17
# File 'lib/termplot/widgets/time_series_widget.rb', line 15

def line_style
  @line_style
end

#tick_spacingObject (readonly)

Returns the value of attribute tick_spacing.



15
16
17
# File 'lib/termplot/widgets/time_series_widget.rb', line 15

def tick_spacing
  @tick_spacing
end

Instance Method Details

#post_initialize(opts) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/termplot/widgets/time_series_widget.rb', line 17

def post_initialize(opts)
  @color = Termplot::Colors.fetch(opts[:color], DEFAULT_COLOR)
  @line_style = Termplot::CharacterMap::LINE_STYLES.fetch(
    opts[:line_style],
    Termplot::CharacterMap::LINE_STYLES[DEFAULT_LINE_STYLE]
  )

  @tick_spacing = 3
end

#render_to_windowObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/termplot/widgets/time_series_widget.rb', line 27

def render_to_window
  errors.clear
  window.clear

  # Calculate width of right hand axis
  calculate_axis_size

  # Points
  points = build_points
  render_points(points)
  window.cursor.reset_position

  # Title bar
  Termplot::Renderers::TextRenderer.new(
    bordered_window: bordered_window,
    text: title_text,
    row: 0,
    errors: errors
  ).render
  window.cursor.reset_position

  # Borders
  Termplot::Renderers::BorderRenderer.new(
    bordered_window: bordered_window
  ).render

  window.cursor.reset_position

  # Draw axis
  ticks = build_ticks(points)
  render_axis(ticks)
end