Sha256: 6f3c917e1b320e448f4f5afcb252577cfe9300c2d3ae1c77255e5ccdd06d7b4b

Contents?: true

Size: 1.21 KB

Versions: 20

Compression:

Stored size: 1.21 KB

Contents

# TagCloud.rb
# July 6, 2007
#

class TagCloud
  def calculate_max_min
       @max=nil
    @min=nil
       for key in @histogram.keys
      if @min==nil || @histogram[key]<@min
        @min=@histogram[key]
      end
      if @max==nil || @histogram[key]>@max
        @max=@histogram[key]
      end
    end
  end
  def initialize(tag_data)
   
    @histogram=tag_data.inject(Hash.new(0)){|hash,x| hash[x.tag_name]+=1;hash}
              
    @tag_data=tag_data.sort_by{|x|[@histogram[x.tag_name],x.tag_name]}
   calculate_max_min
    while @histogram.size>40
        @histogram.reject!{|key, value| value == @min }
        calculate_max_min
    end
    @normal_histogram={}
    if tag_data.length>0
      range=@max-@min
      for key in @histogram.keys
        if range==0
           @normal_histogram[key]=2
        else
           @normal_histogram[key]=((@histogram[key]-@min)*4)/range
        end
       
      end
      @tags=@histogram.keys
      @tags.sort!
    else 
      @tags=[]
    end
  end
  def tags
    return @tags
  end
  def get_count(tag_name)
    return @histogram[tag_name]
  end
   def get_magnitude(tag_name)
    return @normal_histogram[tag_name]
  end
end


Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
cloudwow-not_relational-0.1.0 lib/not_relational/tag_cloud.rb
cloudwow-not_relational-0.1.11 lib/not_relational/tag_cloud.rb
cloudwow-not_relational-0.1.2 lib/not_relational/tag_cloud.rb
cloudwow-not_relational-0.1.3 lib/not_relational/tag_cloud.rb
cloudwow-not_relational-0.1.5 lib/not_relational/tag_cloud.rb
cloudwow-not_relational-0.1.6 lib/not_relational/tag_cloud.rb
cloudwow-not_relational-0.1.7 lib/not_relational/tag_cloud.rb
cloudwow-not_relational-0.1.8 lib/not_relational/tag_cloud.rb
cloudwow-not_relational-0.1.9 lib/not_relational/tag_cloud.rb
sdb_dal-0.0.8 ./lib/sdb_dal/tag_cloud.rb
sdb_dal-0.0.11 ./lib/sdb_dal/tag_cloud.rb
sdb_dal-0.0.6 ./lib/sdb_dal/tag_cloud.rb
sdb_dal-0.0.3 ./lib/sdb_dal/tag_cloud.rb
sdb_dal-0.0.2 ./lib/sdb_dal/tag_cloud.rb
sdb_dal-0.0.4 ./lib/sdb_dal/tag_cloud.rb
sdb_dal-0.0.1 ./lib/sdb_dal/tag_cloud.rb
sdb_dal-0.0.12 ./lib/sdb_dal/tag_cloud.rb
sdb_dal-0.0.5 ./lib/sdb_dal/tag_cloud.rb
sdb_dal-0.0.7 ./lib/sdb_dal/tag_cloud.rb
sdb_dal-0.0.9 ./lib/sdb_dal/tag_cloud.rb