Class: RVGP::Plot::Gnuplot::Palette

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(opts = {}) ⇒ Palette

Returns a new instance of Palette.

Parameters:

  • opts (Hash) (defaults to: {})

    The options to configure this palette with

Options Hash (opts):

  • :base (Hash<Symbol, String>)

    The base colors for this plot. Currently, the following base colors are supported: :title_rgb, :background_rgb, :font_rgb, :grid_rgb, :axis_rgb, :key_text_rgb . This option expects keys to be one of the supported colors, and values to be in the ‘standard’ html color format, resembling “#rrggbb” (with rr, gg, and bb being a hexadecimal color code)

  • :series (Array<String>)

    An array of colors, in the ‘standard’ html color format. There is no limit to the size of this array.



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

Returns:

  • (String)

    An html color code, for the requested base color



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_hHash<Symbol, String>

Returns the base colors, currently supported, that were supplied in the #initialize base: option

Returns:

  • (Hash<Symbol, String>)

    An html color code, for the requested base color



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.

Returns:

  • (String)

    The html color code of the color, before we advanced the series



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