HTML Tag Cloud in Python
Asked Answered
A

1

6

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 in python

Antipodes answered 5/7, 2010 at 15:51 Comment(1)
No need for the same question again: HTML Tag Cloud creation using Python?Managing
W
5

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 ;-)

Women answered 5/7, 2010 at 19:25 Comment(1)
Good concise answer. Not really necessary to use range() to define CSS_SIZES, though, since it's only used to get the length (which is 6).Sunshinesunspot

© 2022 - 2024 — McMap. All rights reserved.