ANSI-Heatmap
view release on metacpan or search on metacpan
=head2 inc ( X, Y )
Increase the intensity at the given co-ordinate by 1.
=head2 to_string
Return a string containing the ANSI heatmap. If C<half> is set,
this string contains wide characters, so you may need to:
binmode STDOUT, ':utf8';
or
use open OUT => ':utf8';
before printing anything (in this case) to STDOUT.
=head2 data
Returns the heatmap data, cropped, scaled and normalised with
intensity values between 0 and 1.
Expressed as an arrayref of arrayrefs indexed by Y and then
X co-ordinate.
examples/boxes.pl view on Meta::CPAN
use strict;
use warnings;
use ANSI::Heatmap;
binmode STDOUT, ':utf8';
for my $half (0,1) {
for my $box ([2,2], [3, 5], [9,9], [10,10], [11,11], [21,19]) {
my ($x, $y) = @$box;
my $map = ANSI::Heatmap->new(
half => $half,
min_x => 1,
min_y => 1,
max_x => $x,
max_y => $y,
examples/git.pl view on Meta::CPAN
my @order = sort { $commit_count{$b} <=> $commit_count{$a} } keys %commit_count;
@order = splice @order, 0, $LIMIT;
my %header = map { $_ => "$_ (" . $commit_count{$_} . ")" } @order;
my @hdrlens = map { length $_ } values %header;
my $hdrwidth = max(@hdrlens);
my $colwidth = max($hdrwidth, 24) + 2;
my $pad = ' ' x ($colwidth - 24);
binmode STDOUT, ':utf8';
while ( my @row = splice @order, 0, $PER_ROW ) {
my $fmt = (('%-' . $colwidth . 's') x @row) . "\n";
printf $fmt, map { $header{$_} } @row;
my @maps = @map{@row};
my @split = map { [ split /\n/, $_ ] } @maps;
for my $line (0..$#{$split[0]}) {
print join '', map { $split[$_][$line] . $pad } 0..$#split;
print "\n";
}
examples/gray.pl view on Meta::CPAN
use strict;
use warnings;
use ANSI::Heatmap;
binmode STDOUT, ':utf8';
# Advanced usage
my $map = ANSI::Heatmap->new(
half => 1,
min_x => 1,
min_y => 1,
max_x => 10,
max_y => 10,
swatch => 'grayscale',
);
examples/interp.pl view on Meta::CPAN
use strict;
use warnings;
use ANSI::Heatmap;
binmode STDOUT, ':utf8';
my $map = ANSI::Heatmap->new(
half => 1,
swatch => 'grayscale',
);
for my $x (0..5) {
for my $y (0..5) {
$map->set($x, $y, ($x % 2 == $y % 2));
}
}
examples/random.pl view on Meta::CPAN
#!/usr/bin/perl
use strict;
use warnings;
use ANSI::Heatmap;
my $map = ANSI::Heatmap->new;
binmode STDOUT, ':utf8';
# Randomness
for (1..2000) {
my $x = int(rand(50));
my $y = int(rand(21));
$map->inc($x, $y);
}
print $map;
$map->half(1);
examples/smallinterp.pl view on Meta::CPAN
use strict;
use warnings;
use ANSI::Heatmap;
binmode STDOUT, ':utf8';
my $map = ANSI::Heatmap->new(
half => 1,
swatch => 'grayscale',
);
for my $x (0..19) {
for my $y (0..19) {
my $sc = 1 + ($x >= 10) + ($y >= 10) * 2;
my $z = (($x/$sc) % 2 == ($y/$sc) % 2);
$map->set($x, $y, $z);
lib/ANSI/Heatmap.pm view on Meta::CPAN
=head2 inc ( X, Y )
Increase the intensity at the given co-ordinate by 1.
=head2 to_string
Return a string containing the ANSI heatmap. If C<half> is set,
this string contains wide characters, so you may need to:
binmode STDOUT, ':utf8';
or
use open OUT => ':utf8';
before printing anything (in this case) to STDOUT.
=head2 data
Returns the heatmap data, cropped, scaled and normalised with
intensity values between 0 and 1.
Expressed as an arrayref of arrayrefs indexed by Y and then
X co-ordinate.
( run in 1.023 second using v1.01-cache-2.11-cpan-49f99fa48dc )