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
Publié le dimanche 13 juin 2010 à 19:34 CEST
Lien permanent : /blog/2010/06/13/tags-cloud
Tags : Mon site web Programmation
Commentaires : 0

Commentaires

Aucun commentaire

Nouveau commentaire

* L'astérisque dénote un champ obligatoire.

En soumettant votre message, vous acceptez qu' il soit publié sous licence CC BY-SA 3.0.

Quelques balises HTML sont autorisées : a[href, hreflang, title], br, em, i, strong, b, tt, samp, kbd, var, abbr[title], acronym[title], code, q[cite], sub, sup.

Switch to English

Chercher

Tags

Bruit de fond Hobbys Humour Informatique Internet Livres Logiciels Moi Mon site web Mozilla Photo Politique Programmation Scolaire Ubuntu pROC

Billets récents

Calendrier

lun.mar.mer.jeu.ven.sam.dim.
123456
78910111213
14151617181920
21222324252627
282930

Syndication

Recommender