You are here

private function TagadelicCloud::recalculate in Tagadelic 7.2

(Re)calculates the weights on the tags.

Parameters

$recalculate. Optional flag to enfore recalculation of the weights for the tags in this cloud.: defaults to FALSE, meaning the value will be calculated once per cloud. @return $this; for chaining

1 call to TagadelicCloud::recalculate()
TagadelicCloud::get_tags in ./TagadelicCloud.php
Getter for tags @returns Array list of tags

File

./TagadelicCloud.php, line 123

Class

TagadelicCloud
class TagadelicCloud TagadelicCloud, contains a list of tags and methods to manipulate this set of tags. It can operate on the list of tags.

Code

private function recalculate() {
  $tags = array();

  // Find minimum and maximum log-count.
  $min = 1000000000.0;
  $max = -1000000000.0;
  foreach ($this->tags as $id => $tag) {
    $min = min($min, $tag
      ->distributed());
    $max = max($max, $tag
      ->distributed());
    $tags[$id] = $tag;
  }

  // Note: we need to ensure the range is slightly too large to make sure even
  // the largest element is rounded down.
  $range = max(0.01, $max - $min) * 1.0001;
  foreach ($tags as $id => $tag) {
    $this->tags[$id]
      ->set_weight(1 + floor($this->steps * ($tag
      ->distributed() - $min) / $range));
  }
  return $this;
}