You are here

protected function TagadelicCloudBase::recalculate in Tagadelic 8.3

(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 TagadelicCloudBase::recalculate()
TagadelicCloudBase::getTags in src/TagadelicCloudBase.php
Return an array of Tagadelic Tags.

File

src/TagadelicCloudBase.php, line 87

Class

TagadelicCloudBase
Defines a base TagadelicCloud implementation.

Namespace

Drupal\tagadelic

Code

protected 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]
      ->setWeight(1 + floor($this->steps * ($tag
      ->distributed() - $min) / $range));
  }
  return $this;
}