Creating the blog tags for this website was a bit tricky because I wasn't sure how to make the tags have different sizes according to their significance. I started off with 5 spans and ordered the tags in terms of frequency and divided them equally into the spans. However tags are not evenly distributed, so instead I calculated the normalized weight of the tag according to the others, and made the font size a percentage of that.
In the model:
@staticmethod
def generateSpans():
counts = session.query(Tag,
func.count(Tag.id)).join(blog_tags).group_by(Tag).all()
smallest = min(count for (tag, count) in counts)
scale = max(count for (tag, count) in counts) - smallest
scaled = []
for tag, count in counts:
if scale != 0:
scaled.append((tag, (count - smallest)/float(scale)))
else:
scaled.append((tag, 1))
return scaled
In the view:
<p>
% for tag, weight in tags:
<span style="font-size: ${int(70 + (80 * weight))|h}%"><a href=
"${urls.build('tag.entries', dict(tag=tag.link))|h}">${tag.name|h}</a> </span>
% endfor
</p>
It looks pretty good when there are at least 3 different weightings as you can see to the right.
Safari play jquery confirmation bias papier mache SANS Post Secret stew fabrics AJAX gardening comedy train etiquette shoes Woodilee tags Istanbul Microsoft Word text thesis page breaks Art Attack Chilli handmade Ben Nevis canvas Michelin star Mendeley Number One captcha rabbit nutrition restaurant encryption Opera OCFA music Routine Activities Theory internet history criminology Christmas lectures foodies cake birthday rabbit vision sausages hacking iPod Touch risotto Edinburgh Fringe unicode draught excluder blood SECC ballistics Google Chrome News of the World Derren Brown Karanga camp naughty bunny