Question

I'm looking to make a Tag Cloud in Objective-C, and I'm trying to find a good algorithm. I've tried several, which, at first, seemed to work quite well, but they all had one flaw: if the word with the lowest number of occurences appeared as often as the word with the highest frequency, the whole process was flawed.

Example (First algorithm in Google):

var multiplier = (maxPercent-minPercent)/(max-min);
var size = minPercent + ((max-(max-(count-min)))*multiplier);

Here, if min = 5, max = 5, maxPercent = 300, minPercent = 75, and count = 5, then you have:

var multiplier = (300-75)/(5-5) ----- division by 0, impossible
var size = 75 + ((5-(5-(5-5)))*multiplier);

So my question is, are there any Tag Cloud algorithms that take this into account, and are able to calculate each word's font size, even when the maximum frequency is equal to the minimum frequency?

Was it helpful?

Solution

Try the following:

var multiplier = (maxPercent-minPercent)/(max-min+1);
var size = minPercent + ((max-(max-(count-min)))*multiplier);

As far as I can see, it solves your problem just fine; at the same time, as long as frequencies are distinguishable, +1 doesn't change things much.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top