Sha256: ae322d2bcfad23da114ed31bdf622047361d87bd2ceffa1e219f112c4a56a4e0

Contents?: true

Size: 757 Bytes

Versions: 6

Compression:

Stored size: 757 Bytes

Contents

class RailsDataExplorer
  module Utils
    class ColorScale

      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

      def compute(input)
        @gradient.at(input).html
      end

      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

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rails-data-explorer-0.2.3 lib/rails-data-explorer/utils/color_scale.rb
rails-data-explorer-0.2.2 lib/rails-data-explorer/utils/color_scale.rb
rails-data-explorer-0.2.1 lib/rails-data-explorer/utils/color_scale.rb
rails-data-explorer-0.2.0 lib/rails-data-explorer/utils/color_scale.rb
rails-data-explorer-0.1.0 lib/rails-data-explorer/utils/color_scale.rb
rails-data-explorer-0.0.1 lib/rails-data-explorer/utils/color_scale.rb