+ protected function formatTagsForCloud(array $tags): array
+ {
+ // We sort tags alphabetically, then choose a font size according to count.
+ // First, find max value.
+ $maxCount = count($tags) > 0 ? max($tags) : 0;
+ $logMaxCount = $maxCount > 1 ? log($maxCount, 30) : 1;
+ $tagList = [];
+ foreach ($tags as $key => $value) {
+ // Tag font size scaling:
+ // default 15 and 30 logarithm bases affect scaling,
+ // 2.2 and 0.8 are arbitrary font sizes in em.
+ $size = log($value, 15) / $logMaxCount * 2.2 + 0.8;
+ $tagList[$key] = [
+ 'count' => $value,
+ 'size' => number_format($size, 2, '.', ''),
+ ];
+ }
+
+ return $tagList;
+ }
+