I am looking for a simple library which can be given a set of items:value pair and which can generate a tag cloud as output.
Library can preferably be i开发者_如何学运维n python
Define font-sizes in your css-file. Use classes from
size-0{
font-size: 11px;
}
size-1{
font-size: 12px;
}
etc. up to the font-size you need.
And then simply use this snippet:
CSS_SIZES = range(1, 7) # 1,2...6 for use in your css-file size-1, size-2, etc.
TAGS = {
'python' : 28059,
'html' : 19160,
'tag-cloud' : 40,
}
MAX = max(TAGS.values()) # Needed to calculate the steps for the font-size
STEP = MAX / len(CSS_SIZES)
for tag, count in TAGS.items():
css = count / STEP
print '<a href="%s" class="size-%s">%s</a>' % (tag, css, tag),
That's all. No need for a library ;-)
精彩评论