<?php /* function balancedTagCloud(array $values, array $priorities): array { $low = min($priorities) - 1; $high = max($priorities) - $low; return array_map( fn($v, $p) => sprintf( '<h%1$d>%2$s</h%1$d>', ceil(($p - $low) / $high * 6), $v ), $values, $priorities ); } */ $artist = ["the roots", "michael jackson", "billy idol", "more", "and more", "and_YET_MORE"]; /*$counts = [ 'original' => [5, 3, 9, 1, 1, 3], 'no_ones' => [5, 3, 9, 7, 7, 3], 'skewed' => [5, 3, 9, 7, 111, 3], 'all_same' => [5, 5, 5, 5, 5, 5], 'only_two' => [9, 20, 9, 20, 9, 20], ]; foreach ($counts as $count) { echo implode("\n", balancedTagCloud($artist, $count)); echo "\n---\n"; }*/ $count = [5, 3, 9, 1, 1, 3]; $steps = 6; $tags = []; $min = 1e9; $max = -1e9; foreach ($artist as $i => $name) { $c = log($count[$i]); $min = min($min, $c); $max = max($max, $c); $tags[] = (object) ['weight' => $count[$i], 'name' => $name, 'count' => $c]; } $range = max(.01, $max - $min) * 1.0001; foreach ($tags as $obj) { $obj->weight = 1 + floor($steps * ($obj->count - $min) / $range); } foreach ($tags as $tag) { echo "<h$tag->weight>$tag->name</h$tag->weight>\n"; }
You have javascript disabled. You will not be able to edit any code.