Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | use snippet to return tag cloud |
|---|---|
| Downloads: | Tarball | ZIP archive | SQL archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
5df11ad2cc14ce709cb35daea2a7266d |
| User & Date: | i5ivem@gmail.com 2010-03-16 15:27:22 |
| Original User & Date: | i5ivem@gmail.com 2010-03-16 15:27:23 |
Context
|
2010-03-16
| ||
| 15:27 | Progress bar and sleep interval added check-in: c532927408 user: i5ivem@gmail.com tags: trunk | |
| 15:27 | use snippet to return tag cloud check-in: 5df11ad2cc user: i5ivem@gmail.com tags: trunk | |
| 15:27 | First commit of App, still WIP check-in: 47fdc533c5 user: i5ivem@gmail.com tags: trunk | |
Changes
Added cloud.rb.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# Taken from http://snippets.dzone.com/posts/show/6027
# Tweaked to return values suitable for Shoes (lines 38-40, etc)
class TagCloud
def initialize(words)
@wordcount = count_words(words)
end
def count_words(words)
wordcount = {}
words.split(/\s/).each do |word|
word.downcase!
if word.strip.size > 0
unless wordcount.key?(word.strip)
wordcount[word.strip] = 0
else
wordcount[word.strip] = wordcount[word.strip] + 1
end
end
end
wordcount
end
def font_ratio(wordcount={})
min, max = 1000000, -1000000
wordcount.each_key do |word|
max = wordcount[word] if wordcount[word] > max
min = wordcount[word] if wordcount[word] < min
end
18.0 / (max - min)
end
def build
cloud = String.new
ratio = font_ratio(@wordcount)
color = ["steelblue", "deeppink"]
@wordcount.each_key do |word|
font_size = (10 + (@wordcount[word] * ratio)).round #must round for shoes since pixels
cloud << %Q{para "#{word}", :size => #{font_size}, :stroke => #{color[0]}; }
color.reverse! #alternate between colours
end
cloud
end
end
|
Changes to shoeset.rb.
1 2 3 4 5 6 7 8 9 10 11 12 13 | Shoes.setup do gem 'flickraw' end require 'flickraw' require 'yaml' Shoes.app do FlickRaw.api_key="" FlickRaw.shared_secret="" TOKENFILE = ENV['HOME']+"\\.shoeset.yml" | > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | Shoes.setup do gem 'flickraw' end require 'flickraw' require 'yaml' require 'cloud' Shoes.app do FlickRaw.api_key="" FlickRaw.shared_secret="" TOKENFILE = ENV['HOME']+"\\.shoeset.yml" |
| ︙ | ︙ | |||
48 49 50 51 52 53 54 55 56 |
:chose => @setlist[0] do |set|
para set.text
photosetinfo = @photosetlist.select {|s| s["title"] == set.text}
debug(photosetinfo)
debug photosetinfo[0]["id"].to_s #it's an array of a hash. Even though just one
photosetphotos = flickr.photosets.getPhotos(:photoset_id => photosetinfo[0]["id"] )
debug(photosetphotos["photo"])
photosetphotos["photo"].each do |photo|
debug flickr.tags.getListPhoto(:photo_id => photo["id"])
| > > > | < < | > | > | | | | > | > | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
:chose => @setlist[0] do |set|
para set.text
photosetinfo = @photosetlist.select {|s| s["title"] == set.text}
debug(photosetinfo)
debug photosetinfo[0]["id"].to_s #it's an array of a hash. Even though just one
photosetphotos = flickr.photosets.getPhotos(:photoset_id => photosetinfo[0]["id"] )
debug(photosetphotos["photo"])
array = []
photosetphotos["photo"].each do |photo|
debug flickr.tags.getListPhoto(:photo_id => photo["id"])
temp = flickr.tags.getListPhoto(:photo_id => photo["id"])
temp["tags"].each do |tags| #should be an array
array << tags["_content"]
end
debug array
# Caching - anyway? Could cache list of photos from set, but then what about if updated?
# Sleep interval between calls.
end
cloud = TagCloud.new(array.join(" "))
eval cloud.build
debug cloud.build
end
end
|