Skip to content

Instantly share code, notes, and snippets.

@ceekz
Created Jan 10, 2013
Embed
What would you like to do?
use List::Util;
sub add_cloud_font_size {
my ($font_size_min, $font_size_max, $val_col, @lists) = @_;
if (scalar(@lists) == 0) {
return;
}
my $val_min = log(List::Util::min(map { $_->{$val_col} } @lists) + 1);
my $val_max = log(List::Util::max(map { $_->{$val_col} } @lists) + 1);
my $factor = ($val_max - $val_min) ? ($font_size_max - $font_size_min) / ($val_max - $val_min) : 1;
foreach (@lists) {
$_->{'cloud_font_size'} = sprintf("%.1f", (log($_->{$val_col} + 1) - $val_min) * $factor + $font_size_min);
}
return @lists;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment