Class: Hackmac::Graph
- Inherits:
-
Object
- Object
- Hackmac::Graph
- Includes:
- Formatters, Term::ANSIColor
- Defined in:
- lib/hackmac/graph.rb,
lib/hackmac/graph/display.rb
Overview
A class that provides graphical display functionality for terminal-based data visualization
The Graph class enables the creation of dynamic, real-time visualizations of data values within a terminal environment. It manages the rendering of graphical representations such as line charts or graphs, updating them continuously based on provided data sources. The class handles terminal control operations, including cursor positioning, color management, and screen clearing to ensure smooth visual updates. It also supports configuration of display parameters like title, formatting strategies for values, update intervals, and color schemes for different data series.
Defined Under Namespace
Modules: Formatters Classes: Display
Instance Method Summary collapse
-
#initialize(title:, value: -> i { 0 }, format_value: nil, sleep: nil, color: nil) ⇒ Graph
constructor
The initialize method sets up a Graph instance by configuring its display parameters and internal state.
-
#start ⇒ Object
The start method initiates the graphical display process by setting up signal handlers, performing an initial terminal reset, and entering the main update loop.
-
#stop ⇒ Object
The stop method terminates the graphical display process by performing a full reset and setting the continue flag to false.
Methods included from Formatters
#as_bytes, #as_celsius, #as_default, #as_hertz, #as_percent, #derive_color_from_string
Constructor Details
#initialize(title:, value: -> i { 0 }, format_value: nil, sleep: nil, color: nil) ⇒ Graph
The initialize method sets up a Graph instance by configuring its display parameters and internal state
This method configures the graph visualization with title, value provider, formatting options, update interval, and color settings. It initializes internal data structures for storing historical values and manages synchronization through a mutex for thread-safe operations.
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/hackmac/graph.rb', line 166 def initialize( title:, value: -> i { 0 }, format_value: nil, sleep: nil, color: nil ) sleep >= 0 or raise ArgumentError, 'sleep has to be >= 0' @title = title @value = value @format_value = format_value @sleep = sleep @continue = false @data = [] @color = color @mutex = Mutex.new end |
Instance Method Details
#start ⇒ Object
The start method initiates the graphical display process by setting up signal handlers, performing an initial terminal reset, and entering the main update loop
This method serves as the entry point for starting the graph visualization functionality. It configures the necessary signal handlers for graceful shutdown and terminal resizing, performs an initial full reset of the display state, and then begins the continuous loop that updates and renders graphical data.
193 194 195 196 197 |
# File 'lib/hackmac/graph.rb', line 193 def start install_handlers full_reset start_loop end |
#stop ⇒ Object
The stop method terminates the graphical display process by performing a full reset and setting the continue flag to false
This method serves as the shutdown mechanism for the graph visualization functionality. It ensures that all display resources are properly cleaned up and the terminal state is restored to its original condition before stopping the continuous update loop.
206 207 208 209 |
# File 'lib/hackmac/graph.rb', line 206 def stop full_reset @continue = false end |