First and foremost, Oliver was right, and I was wrong.

The data is in a power curve, or maybe logarithmic, or whatever curve
you want to call it, depending on which expert you consult...

But as I realized last night, the data is ALREADY in that "curve" and
by simply breaking down in even increments from MIN to MAX, the
"curve" works itself out correctly.

Or, in other words, I was trying to complicate things by designing
logarithmic graph paper, when all I really wanted was standard graph
paper, to graph the data as it is in Reality.

Of course, others might choose to "shape" their curve by a log (or
other function) but most probably won't need to.

Here's the code I am using for my Tag Cloud (aka tagcloud), and it
works fine:


  //fat screen editor, sorry...
  $query = "select tag, popular from (select tag, count(*) as popular
from entry_tag group by tag order by popular desc limit 100) as p
order by tag";
  $tagged = mysql_query($query, $connection);
  if (!$tagged){
    $messages[] = "Tagged Browsing offline for maintenance. Please try
again later or contact us.";
    error_log(mysql_error($connection));
    error_log($query);
  }
  $tagged_a = array();
  $max = 0;
  $min = 0xffffffff;
  while ($tagged && (list($tag, $popular) = mysql_fetch_row($tagged))){
    $tagged_a[$tag] = $popular;
    $max = max($max, $popular);
    $min = min($min, $popular);
  }
  $distribution = ($max - $min) / 5;

// function here which prints out masthead, body, etc
// including anything in $messages array, with suitable div tag
// for error messages

  echo "<p id=\"tagged\" style=\"text-align: center\" >";
  foreach($tagged_a as $tag => $popular){
    $tag_html = htmlentities($tag);
    $pop = round(($popular - $min) / $distribution);
    $pop = max(1, $pop); $pop = min(5, $pop);
    echo "<a href=\"tagged/$tag_html.htm\"><span
class=\"t$pop\">$tag_html</span></a> ";
  }
  echo "</p>\n";

The CSS looks like:

.tagCloud {
  margin: 20px 0px 20px 0px;
  width: 830px;
}

.tagCloud span {
  padding: 3px;
}

.t1 {
  color: #c3c2ba;
  font-size: .8em;
}

.t2 {
  color: #8F8D7A;
  font-size: .9em;
}

.t3 {
  color: #615f4e;
  font-size: 1em;
}

.t4 {
  color: #535142;
  font-size: 1.2em;
}

.t5 {
  color: #434237;
  font-size: 1.4em;
}


Of course, you are free to tweak the colors and sizes as you see fit :-)

Since there are only a hundred items, ever, I chose to iterate the
result set, putting the data into an array, and track min/max as I go.

It might be slightly faster to run a second query to get min/max, or
to rewind the result set instead of making an array, or whatever, but,
really, it's fine as it is for only 100 items.

Thanks to Tedd for answering the question I asked, I think, even
though I was asking the wrong question. :-)

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to