Class: RVGP::Plot::Gnuplot::Palette
- Inherits:
-
Object
- Object
- RVGP::Plot::Gnuplot::Palette
- Defined in:
- lib/rvgp/plot/gnuplot.rb
Overview
Palette(s) are loaded from a template, and contain logic related to coloring base elements (fonts/background/line-colors/etc), as well as relating to series/element colors in the plot.
Instance Method Summary collapse
-
#base_to_h ⇒ Hash<Symbol, String>
Returns the base colors, currently supported, that were supplied in the #initialize base: option.
-
#initialize(opts = {}) ⇒ Palette
constructor
A new instance of Palette.
-
#method_missing(name) ⇒ String
Unhandled methods, are assumed to be base_color requests.
-
#reverse_series_colors!(from_origin) ⇒ Object
This is used by some charts, due to gnuplot requiring us to inverse the order of series.
-
#series_next! ⇒ String
Return the current series color.
Constructor Details
#initialize(opts = {}) ⇒ Palette
Returns a new instance of Palette.
24 25 26 27 28 29 |
# File 'lib/rvgp/plot/gnuplot.rb', line 24 def initialize(opts = {}) @series_colors = opts[:series] @base_colors = opts[:base] @last_series_color = -1 @last_series_direction = 1 end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ String
Unhandled methods, are assumed to be base_color requests. And, commensurately, the :base option in the constructor is used to satisfy any such methods
49 50 51 |
# File 'lib/rvgp/plot/gnuplot.rb', line 49 def method_missing(name) @base_colors.key?(name) ? base_color(name) : super(name) end |
Instance Method Details
#base_to_h ⇒ Hash<Symbol, String>
Returns the base colors, currently supported, that were supplied in the #initialize base: option
55 56 57 58 59 |
# File 'lib/rvgp/plot/gnuplot.rb', line 55 def base_to_h # We'll probably want to expand this more at some point... { title_rgb: title, background_rgb: background, font_rgb: font, grid_rgb: grid, axis_rgb: axis, key_text_rgb: key_text } end |
#reverse_series_colors!(from_origin) ⇒ Object
This is used by some charts, due to gnuplot requiring us to inverse the order of series. The from_origin parameter, is the new origin, by which we’ll begin to assign colors, in reverse order
64 65 66 67 |
# File 'lib/rvgp/plot/gnuplot.rb', line 64 def reverse_series_colors!(from_origin) @last_series_color = from_origin @last_series_direction = -1 end |
#series_next! ⇒ String
Return the current series color. And, increments the ‘current’ color pointer, so that a subsequent call to this method returns ‘the next color’, and continues the cycle. Should there be no further series colors available, at the time of advance, the ‘current’ color moves back to the first element in the provided :series colors.
36 37 38 39 |
# File 'lib/rvgp/plot/gnuplot.rb', line 36 def series_next! @last_series_color += @last_series_direction @series_colors[@last_series_color % @series_colors.length] end |