Module: Utilities::Heatmap

Defined in:
lib/utilities/heatmap.rb

Class Method Summary collapse

Class Method Details

.color_from_hash(hash) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/utilities/heatmap.rb', line 11

def self.color_from_hash(hash)
  j = hash[0, 1]
  substr = j.hex

  hash << hash

  '#' + hash[substr..(substr + 5)]
end

.heatmap_color_for(value) ⇒ Object

0,1


4
5
6
7
8
9
# File 'lib/utilities/heatmap.rb', line 4

def self.heatmap_color_for(value)
  h = (1 - value) * 360
  s = 100
  l = value * 50
  "hsl(#{h.round(2)},#{s.round(2)}%,#{l.round(2)}%)"
end

.hex_color_from_string(text) ⇒ Object



35
36
37
# File 'lib/utilities/heatmap.rb', line 35

def self.hex_color_from_string(text)
  color_from_hash(text_to_hash(text))
end

.text_to_hash(text) ⇒ Object

llama-3-8b-instruct and function colorFromHash(hash) (internall)



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/utilities/heatmap.rb', line 22

def self.text_to_hash(text)
  hash = 0
  if text.empty?
    return hash.to_s(16)
  end

  text.each_char do |char|
    hash = ((hash << 5) - hash + char.ord).abs
  end

  hash.to_s(16)
end