Skip to content

Instantly share code, notes, and snippets.

@Svel
Created October 16, 2010 15:41
Show Gist options
  • Save Svel/629920 to your computer and use it in GitHub Desktop.
Save Svel/629920 to your computer and use it in GitHub Desktop.
Logarithm Tag weights
<?php
/**
* Logarithm tag weights
*
* @see http://zhekanax.ru/2009/06/25/tag-cloud-logarithm/
* @see http://habrahabr.ru/blogs/webdev/30543/
*/
class Tag
{
/**
*
* @param array $options массив с максимальным (max), минимальным (min) значением
* и колчиеством градаций (levels)
* @return int [1,levels]
*/
public function getWeight(array $options)
{
if (!isset($this->nb_posts) || !isset($options['max']) || !isset($options['min']) || !isset($options['levels'])) {
return 1;
} else {
$options['min'] = log($options['min'] + 1);
$options['max'] = log($options['max'] + 1);
return round(
1
+ (log($this->nb_posts + 1) - $options['min'])
* ($options['levels'] - 1)
/ ($options['max'] - $options['min'] )
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment