Class: Graphina::Panel
- Inherits:
-
Object
- Object
- Graphina::Panel
- Defined in:
- lib/graphina/panel.rb
Overview
A class that represents a panel configuration for graph visualization
The Panel class encapsulates the settings and behavior for a graph display panel, including title, update interval, data source command, color configuration, and formatting options. It provides methods for initializing from configuration data or command-line options, and for generating the appropriate data value provider proc based on the configured command or default random data generation.
Defined Under Namespace
Modules: Chooser
Instance Attribute Summary collapse
-
#background_color ⇒ Object
The background_color accessor method provides read and write access to the background_color attribute.
-
#color ⇒ Object
The color accessor method provides read and write access to the color attribute.
-
#color_secondary ⇒ Object
The color_secondary accessor method provides read and write access to the color_secondary attribute.
-
#command ⇒ Object
The command accessor method provides read and write access to the command attribute.
-
#foreground_color ⇒ Object
The foreground_color accessor method provides read and write access to the foreground_color attribute.
-
#format_value ⇒ Object
The format_value accessor method provides read and write access to the format_value attribute.
-
#interval ⇒ Numeric
The interval reader method provides access to the interval attribute that was set during object initialization.
-
#resolution ⇒ Object
The resolution accessor method provides read and write access to the resolution attribute.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
-
.from_opts(opts) ⇒ Graphina::Panel
The from_opts method creates a new Panel instance configured from command-line options.
Instance Method Summary collapse
-
#configure(config) ⇒ Graphina::Panel
The configure method sets panel attributes based on a configuration hash.
-
#configure_from_opts(opts) ⇒ Graphina::Panel
The configure_from_opts method configures the panel settings based on command-line options.
-
#initialize(config = {}) ⇒ Graphina::Panel
constructor
The initialize method sets up a Panel instance with default configuration values.
-
#value ⇒ Proc
The value method returns a proc that generates data values for graph display.
Constructor Details
#initialize(config = {}) ⇒ Graphina::Panel
The initialize method sets up a Panel instance with default configuration values
This method configures a new panel object with predefined default settings for title, update interval, resolution mode, color scheme, and formatting options before applying any custom configuration provided in the config hash
63 64 65 66 67 68 69 70 71 |
# File 'lib/graphina/panel.rb', line 63 def initialize(config = {}) self.title = 'Data' self.interval = 10.0 self.resolution = :double self.foreground_color = :white self.background_color = :black self.format_value = :as_default configure(config) end |
Instance Attribute Details
#background_color ⇒ Object
The background_color accessor method provides read and write access to the background_color attribute
This method creates a public getter and setter for the background_color instance variable which stores the background color value used for graph visualization
168 169 170 |
# File 'lib/graphina/panel.rb', line 168 def background_color @background_color end |
#color ⇒ Object
The color accessor method provides read and write access to the color attribute
This method creates a public getter and setter for the color instance variable which stores the primary color value used for graph visualization
134 135 136 |
# File 'lib/graphina/panel.rb', line 134 def color @color end |
#color_secondary ⇒ Object
The color_secondary accessor method provides read and write access to the color_secondary attribute
This method creates a public getter and setter for the color_secondary instance variable which stores the secondary color value used for enhanced visual effects in graph visualization
146 147 148 |
# File 'lib/graphina/panel.rb', line 146 def color_secondary @color_secondary end |
#command ⇒ Object
The command accessor method provides read and write access to the command attribute
This method creates a public getter and setter for the command instance variable which stores the external command string used to generate data values for visualization
125 126 127 |
# File 'lib/graphina/panel.rb', line 125 def command @command end |
#foreground_color ⇒ Object
The foreground_color accessor method provides read and write access to the foreground_color attribute
This method creates a public getter and setter for the foreground_color instance variable which stores the text color value used for graph visualization
157 158 159 |
# File 'lib/graphina/panel.rb', line 157 def foreground_color @foreground_color end |
#format_value ⇒ Object
The format_value accessor method provides read and write access to the format_value attribute
This method creates a public getter and setter for the format_value instance variable which stores the formatting strategy used for displaying data values
190 191 192 |
# File 'lib/graphina/panel.rb', line 190 def format_value @format_value end |
#interval ⇒ Numeric
The interval reader method provides access to the interval attribute that was set during object initialization.
This method returns the value of the interval instance variable, which typically represents the update interval in seconds for the graph visualization.
101 102 103 |
# File 'lib/graphina/panel.rb', line 101 def interval @interval end |
#resolution ⇒ Object
The resolution accessor method provides read and write access to the resolution attribute
This method creates a public getter and setter for the resolution instance variable which stores the display resolution mode for the graph visualization
179 180 181 |
# File 'lib/graphina/panel.rb', line 179 def resolution @resolution end |
#title ⇒ Object
Returns the value of attribute title.
91 92 93 |
# File 'lib/graphina/panel.rb', line 91 def title @title end |
Class Method Details
.from_opts(opts) ⇒ Graphina::Panel
The from_opts method creates a new Panel instance configured from command-line options
This method serves as a factory constructor for Panel objects, taking a hash of command-line options and using them to initialize and configure a new panel instance with appropriate settings
21 22 23 |
# File 'lib/graphina/panel.rb', line 21 def self.from_opts(opts) new.configure_from_opts(opts) end |
Instance Method Details
#configure(config) ⇒ Graphina::Panel
The configure method sets panel attributes based on a configuration hash
This method iterates over a configuration hash and dynamically assigns values to panel attributes by calling corresponding setter methods
83 84 85 86 87 88 89 |
# File 'lib/graphina/panel.rb', line 83 def configure(config) config.to_h.each do |name, value| value.nil? and next respond_to?("#{name}=") or raise ArgumentError, "invalid attribute #{name.inspect}" send("#{name}=", value) end end |
#configure_from_opts(opts) ⇒ Graphina::Panel
The configure_from_opts method configures the panel settings based on command-line options
This method takes a hash of command-line options and uses them to set up the panel’s configuration values including title, update interval, data source command, color settings, and formatting options
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/graphina/panel.rb', line 37 def configure_from_opts(opts) configure( title: opts[?t], interval: opts[?n], command: opts[?e], color: opts[?c], color_secondary: opts[?C], foreground_color: opts[?f], background_color: opts[?b], resolution: opts[?r], format_value: opts[?F] ) end |
#value ⇒ Proc
The value method returns a proc that generates data values for graph display
This method creates and returns a proc object that serves as the data source for the graph visualization. When the graph needs a new data point, it invokes this proc with an index parameter. The proc either executes a configured external command and converts its output to a float, or generates a random float value between 0 and 100 if no command is specified
203 204 205 206 207 208 209 |
# File 'lib/graphina/panel.rb', line 203 def value if @command -> i { `#@command`.to_f } else -> i { rand(100).to_f } end end |