Sha256: 37f08afef977474f306328f1a2c4a0a24eec57a981267f5215ab0969c8d09d08

Contents?: true

Size: 944 Bytes

Versions: 11

Compression:

Stored size: 944 Bytes

Contents

require 'ziya/maps/support/base'
require 'color'

module Ziya::Maps::Support
  class HeatRange < Base    
    has_attribute   :base_color, :min, :max, :step, :color_step, :color_method
    
    def flatten( xml )
      ranges = compute_ranges
      ranges.each_pair do |range, color|
        xml.state( :id => 'range' ) do
          xml.data( range )
          xml.color( color )
        end      
      end
    end
    
    # -------------------------------------------------------------------------
    private
    
      # Compute heat color ranges
      def compute_ranges
        ranges  = {}
        color   = Color::RGB.from_html( base_color )
        current = min
    
        while current < max do
          ranges["#{current} - #{current+step-1}" ] = color.html.gsub( /#/, '' )
          color    = color.send( color_method || :darken_by, color_step )
          current += step
        end    
        ranges
      end    
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
derailed-ziya-2.1.0 lib/ziya/maps/support/heat_range.rb
derailed-ziya-2.1.1 lib/ziya/maps/support/heat_range.rb
derailed-ziya-2.1.2 lib/ziya/maps/support/heat_range.rb
derailed-ziya-2.1.3 lib/ziya/maps/support/heat_range.rb
derailed-ziya-2.1.4 lib/ziya/maps/support/heat_range.rb
derailed-ziya-2.1.5 lib/ziya/maps/support/heat_range.rb
ziya-2.3.0 lib/ziya/maps/support/heat_range.rb
ziya-2.1.9 lib/ziya/maps/support/heat_range.rb
ziya-2.1.8 lib/ziya/maps/support/heat_range.rb
ziya-2.1.7 lib/ziya/maps/support/heat_range.rb
ziya-2.1.6 lib/ziya/maps/support/heat_range.rb