Tuesday 15 April 2008

New website

Well, my new website is up and running (www.birkbeck.org.uk) using a modified version of the Satellite v1.5 PHP scripts. As time goes on, I will be adding functionality - including feeds from this and other blogs of mine - and finally taking some time out to learn some PHP.

Most recently, I have been working to get a Flickr Tag Cloud working in a way I like. The original scaled the font according to the number of occurrences of each tag, but the distribution of occurrences was very wide - for instance, most images are tagged with England, Britain and UK. The order of magnitude difference between the most used tags and the majority of tags is very large and the way it had been coded meant that only those tags used in approx 70% or more of the photos in my stream were shown in anything other than the smallest font. The code below is a snippet I have added to calculate font sizes based on a normalised distribution of occurrences.


// Calc font size for a normalised distribution........
// First build array of total counts for each tag count
$i = 0;
foreach ($theCount as $count) { $tagCounter[$i] = $count; $i++; }
// sort array of counts
sort($tagCounter);
// Remove duplicates
$sortedTagCounts = array_unique($tagCounter);
// create an array of preset font sizes determine by tag count
$totalTags = count($sortedTagCounts);
$fontRange = $maxFontSize - $minFontSize;
$fontSizeMultiplier = (($fontRange-$minFontSize+1)/$totalTags);
$i=0;
foreach ($sortedTagCounts as $tagOccurrence) {
$tagOccurrencesMappedToFontSizes[$tagOccurrence] = $i*$fontSizeMultiplier)+$minFontSize;
$i++;
}


In essence, I create a sorted list of tag occurrence frequencies, e.g. one tag may occur 8 times, another may be used over 1000 times. In all, there may be 50 different occurrence numbers. If two different tags are used 10 times each, then this is one entry in the list. Then, I created an array based on each number of occurrences that holds the font size.

Later in the code (not shown here), when I loop through the tags I just use the occurrence frequency as an index into the array of font sizes. There may be easier ways to accomplish this, but I am reasonable happy with it, particularly given my lack of knowledge regarding PHP syntax and built-in functions.

I am working on a revised version of the code and plan to release the full source code, once I have added integral blog pages, but first need to write some PHP to feed that in via XML and RSS. In the meantime, if you want a copy of the code, drop me an email.

No comments: