Tags cloud
There are several CPAN modules to generate tag clouds. To cite only 3 of them:
I just added tags cloud on this site (look the new home page!) with Data::CloudWeights. HTML::TagCloud generate ugly HTML and CSS that cannot be modified. HTML::TagClouder is marked as *WARNING* Alpha software! I mean it!
Not for me, thanks!
Data::CloudWeights is far the most flexible. It generates an arrayref of hashes from which you can pick size, occurences, colors and so on. I use the following subroutine to generate the cloud with a very simple and standard code:
use Data::CloudWeights;
sub tag_cloud {
my @tags = @_;
my $cloud = Data::CloudWeights->new;
for my $tag (@tags) {
# The followin line is a bit more complicated than shown here
# $tag is a DBIx::Class entry with more columns than displayed here
$cloud->add($tag->tag, scalar $tag->links, "/tag/" . $tag->tag);
}
my $cloud_html = "";
foreach my $tag (@{$cloud->formation}) {
$cloud_html .= '<a href="' . $tag->{'value'} .
'" style="font-size: ' . $tag->{'size'} . 'em">';
$cloud_html .= $tag->{'tag'};
$cloud_html .= '</a>';
}
return $cloud_html;
}Xavier Robin
Published Sunday, June 13, 2010 19:34 CEST
Permalink: /blog/2010/06/13/tags-cloud
Tags:
My website
Programming
Comments: 0
Comments
No comment
Search
Tags
Recent posts
Calendar
Syndication