Class: Termplot::Renderer
- Inherits:
-
Object
- Object
- Termplot::Renderer
- Defined in:
- lib/termplot/renderer.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#cols ⇒ Object
readonly
Returns the value of attribute cols.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Instance Method Summary collapse
-
#initialize(cols: 80, rows: 20, debug: false) ⇒ Renderer
constructor
A new instance of Renderer.
- #inner_width ⇒ Object
- #render(series) ⇒ Object
Constructor Details
#initialize(cols: 80, rows: 20, debug: false) ⇒ Renderer
Returns a new instance of Renderer.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/termplot/renderer.rb', line 11 def initialize(cols: 80, rows: 20, debug: false) # Default border size, right border allocation will change dynamically as # data comes in to account for the length of the numbers to be printed in # the axis ticks @border_size = default_border_size @cols = cols > min_cols ? cols : min_cols @rows = rows > min_rows ? rows : min_rows @window = Window.new(cols: @cols, rows: @rows) @decimals = 2 @tick_spacing = 3 @debug = debug @errors = [] end |
Instance Attribute Details
#cols ⇒ Object (readonly)
Returns the value of attribute cols.
9 10 11 |
# File 'lib/termplot/renderer.rb', line 9 def cols @cols end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
9 10 11 |
# File 'lib/termplot/renderer.rb', line 9 def rows @rows end |
Instance Method Details
#inner_width ⇒ Object
59 60 61 |
# File 'lib/termplot/renderer.rb', line 59 def inner_width cols - border_size.left - border_size.right end |
#render(series) ⇒ Object
25 26 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 |
# File 'lib/termplot/renderer.rb', line 25 def render(series) window.clear errors.clear # Calculate width of right hand axis calculate_axis_size(series) # Points points = build_points(series) render_points(series, points) window.cursor.reset_position # Title bar render_title(series) window.cursor.reset_position # Borders render_borders window.cursor.reset_position # Draw axis ticks = build_ticks(points) render_axis(ticks) # Flush window to screen debug? ? window.flush_debug : window.flush if errors.any? window.print_errors(errors) end end |