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.
Internet Explorer Google Chrome Derren Brown Demand Five magic Webscavator Highland cow treats music law ACPO blood SECC lectures etiquette thesis PostgreSQL iPod touch Deterrence Theory Linkin Park bacon encryption jquery Mosaic new dinosaurs presents web history coasters snob Firebug doppelgangers section breaks foodies arts fair usability guidelines art history readability AJAX stand-up Number One Pentlands web browser forensics masters Mesh computers counting chew censorship sock puppets public lecture Skye SQLAlchemy Moroccan cuisine PNG thumbs.db chocolate Michelin star résumé visualisation