class RailsDataExplorer::Utils::ColorScale
Responsibilities:
* Map an input value between -1 and 1 to a color on a color scale.
Public Class Methods
new()
click to toggle source
# File lib/rails_data_explorer/utils/color_scale.rb, line 10 def initialize @points = { -1 => Color::RGB::Red, -0.1 => Color::RGB::Black, 0.1 => Color::RGB::Black, 1 => Color::RGB::Green, } @gradient = Interpolate::Points.new(@points) @gradient.blend_with {|color, other, balance| other.mix_with(color, balance * 100.0) } end
Public Instance Methods
compute(input)
click to toggle source
# File lib/rails_data_explorer/utils/color_scale.rb, line 23 def compute(input) @gradient.at(input).html end
demo()
click to toggle source
# File lib/rails_data_explorer/utils/color_scale.rb, line 27 def demo "<ul>".html_safe + (-1).step(1, 0.1).map { |e| color = compute(e) %(<li style="color: #{ color }">#{ e } (#{ color })</li>) }.join.html_safe + "</ul>".html_safe end