Module: IRuby::Output::HTML::WordCloud
- Defined in:
- lib/iruby/output/html.rb
Overview
Class Method Summary collapse
- .element_heat(val, max) ⇒ Object
- .element_size(histogram, key) ⇒ Object
- .histogram_max(histogram) ⇒ Object
- .wordcloud(histogram = {}) ⇒ Object
Class Method Details
.element_heat(val, max) ⇒ Object
161 162 163 |
# File 'lib/iruby/output/html.rb', line 161 def self.element_heat(val, max) sprintf("%02x" % (200 - ((200.0 / max) * val))) end |
.element_size(histogram, key) ⇒ Object
157 158 159 |
# File 'lib/iruby/output/html.rb', line 157 def self.element_size(histogram, key) (((histogram[key] / histogram.map{|k,v| histogram[k]}.reduce(&:+).to_f) * 100) + 5).to_i end |
.histogram_max(histogram) ⇒ Object
153 154 155 |
# File 'lib/iruby/output/html.rb', line 153 def self.histogram_max(histogram) histogram.map{|k,v| histogram[k]}.max end |
.wordcloud(histogram = {}) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/iruby/output/html.rb', line 139 def self.wordcloud(histogram={}) html = %{<div class="wordcloud">} histogram.keys.sort{|a,b| histogram[a] <=> histogram[b]}.reverse.each do |k| next if histogram[k] < 1 _max = histogram_max(histogram) * 2 _size = element_size(histogram, k) _heat = element_heat(histogram[k], _max) html << %{ <span class="wordcloud_element" style="color: ##{_heat}#{_heat}#{_heat}; font-size: #{_size}px;">#{k}</span> } end html << %{<br style="clear: both;" /></div>} end |