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

New comment

* denotes a mandatory field.

By submitting your message, you accept to publish it under a CC BY-SA 3.0 license.

Some HTML tags are allowed: a[href, hreflang, title], br, em, i, strong, b, tt, samp, kbd, var, abbr[title], acronym[title], code, q[cite], sub, sup.

Passer en français

Search

Tags

Background noise Books Computers Fun Hobbies Internet Me Mozilla My website Photo Politics Programming School Software Ubuntu pROC

Recent posts

Calendar

MonTueWedThuFriSatSun
123456
78910111213
14151617181920
21222324252627
282930

Syndication

Recommend