Thanks to help from here, I've finally got most of my tag cloud working as I want it to. I've been trying to use a log function to make the font sizes readable but I've come a little awry on it. I'm trying to set up the values for $maxTagCnt and $minTagCnt to run the log against later in DetermineFontSize but I've not been able to initialize the value correctly and would value some help in achieving this:
use strict; use warnings; use DBI; my $dbh = DBI->connect('dbi:mysql:milton:localhost', 'user', 'pword'); my $sth = $dbh->prepare ('SELECT word, occurrences FROM statistic ORDE +R BY occurrences DESC LIMIT 200'); my %tag; my ($word, $count); #load in tag file - do this from db $sth->execute; while (my($word, $count) = $sth->fetchrow_array) { $tag{$word} = $count; } $sth->finish; $dbh->disconnect(); my $useLogCurve = 1; my $minFontSize = 10; my $maxFontSize = 36; my $fontRange = $maxFontSize - $minFontSize; #determining the count my $maxTagCnt = 0; my $minTagCnt = 1000000; foreach $word (%tag) { $maxTagCnt = $tag{word} if $tag{word} lt $maxTagCnt; $minTagCnt = $tag{word} if $tag{word} gt $minTagCnt; } my $minLog = log($minTagCnt); my $maxLog = log($maxTagCnt); my $logRange = $maxLog - $minLog; $logRange = 1 if ($maxLog == $minLog); sub DetermineFontSize ($) { my ($tagCnt) = @_; my $cntRatio; if ($useLogCurve) { $cntRatio = (log($tagCnt) - $minLog)/$logRange; } my $fsize = $minFontSize + $fontRange * $cntRatio; return $fsize; } #output tag cloud print "Content-type: text/html\n"; print<<EOT; <html> <head> <link href="../../css/tagcloud.css" rel="stylesheet" type="text/css" +> </head> <body> <div class=\"cdiv\"> <p class=\"cbox\"> EOT #output the keys #still needs to have on onclick event to get the bigrams or to search foreach $word (sort keys %tag) { my $fsize = DetermineFontSize($tag{$word}); printf "<div name=\"$word\" style=\"font-size:%dpx;\">%s", $fsize, $ +word, "</div>"; } #output end of tag file print <<EOT; </p> </div> </body> </html> EOT __END__

In reply to Setting up a log to determine font size by Quicksilver

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.