ANSI-Heatmap
view release on metacpan or search on metacpan
b) cause the whole of any work that you distribute or publish, that
in whole or in part contains the Program or any part thereof, either
with or without modifications, to be licensed at no charge to all
third parties under the terms of this General Public License (except
that you may choose to grant warranty protection to some or all
third parties, at your option).
c) If the modified program normally reads commands interactively when
run, you must cause it, when started running for such interactive use
in the simplest and most usual way, to print or display an
announcement including an appropriate copyright notice and a notice
that there is no warranty (or else, saying that you provide a
warranty) and that users may redistribute the program under these
conditions, and telling the user how to view a copy of this General
Public License.
d) You may charge a fee for the physical act of transferring a
copy, and you may at your option offer warranty protection in
exchange for a fee.
min_y => 0, max_y => 49,
swatch => 'blue-red',
);
for (1..2000) {
my $x = int(rand(50));
my $y = int(rand(50));
$map->inc($x, $y);
}
print $map;
$map->interpolate(1);
$map->width(25);
$map->height(25);
$map->swatch('grayscale');
print $map;
my $data = $map->data;
# Mess with the data...
print $map->render($data);
# Custom swatch
$map->swatch([0x10 .. 0x15]);
=head1 DESCRIPTION
Produce cutting-edge ANSI heatmaps using 256 colours and weird Unicode
characters! Perfect for 3D (2D + intensity) data.
=head1 METHODS
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.
=head2 render ( DATA )
examples/boxes.pl view on Meta::CPAN
swatch => 'grayscale',
);
my @white = (
(map { [1,$_], [$x,$_] } (1..$y)),
(map { [$_, 1], [$_, $y] } (1..$x)),
);
for my $c (@white) {
$map->set(@$c, 100);
}
print "$x x $y\n";
print $map, "\n";
}
}
examples/empty.t view on Meta::CPAN
use strict;
use warnings;
use ANSI::Heatmap;
my $map = ANSI::Heatmap->new( max_x => 10, max_y => 5 );
print $map;
examples/git.pl view on Meta::CPAN
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
min_y => 1,
max_x => 10,
max_y => 10,
swatch => 'grayscale',
);
for my $x (1..10) {
for my $y (1..10) {
$map->set($x, $y, $x * $y);
}
}
print $map->to_string; # explicit
examples/interp.pl view on Meta::CPAN
for my $y (0..5) {
$map->set($x, $y, ($x % 2 == $y % 2));
}
}
for my $wh ([3,3], [3,5], [5,5], [6,6], [12,12], [15,16], [10,20]) {
my ($w, $h) = @$wh;
$map->width($w);
$map->height($h);
$map->interpolate(0);
print "${w}x${h}\n";
print $map;
$map->interpolate(1);
print "${w}x${h}, interpolated\n";
print $map;
}
examples/random.pl view on Meta::CPAN
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);
print "\n";
print $map;
examples/smallinterp.pl view on Meta::CPAN
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);
}
}
print "$map\n";
$map->width(15);
$map->height(15);
print "$map\n";
$map->interpolate(1);
print "$map\n";
lib/ANSI/Heatmap.pm view on Meta::CPAN
for my $x (0..$#{$matrix->[$y]}) {
my $top = $matrix->[$y][$x] || 0;
my $bottom = $half ? ($y == $#{$matrix} ? undef : $matrix->[$y+1][$x] || 0)
: $top;
my ($top_color, $bottom_color) = map {
$self->_swatch_lookup($_)
} grep { defined } ($top, $bottom);
my $fg = sprintf "\e[38;5;%d%s", $top_color, 'm';
my $bg = defined $bottom ? sprintf "\e[48;5;%d%s", $bottom_color, 'm'
: '';
my $char = $half ? $fg . $bg . $TOPBLOCK : $bg . ' ';
push @s, $char . "\e[0m";
}
push @s, "\n";
}
return join '', @s;
}
lib/ANSI/Heatmap.pm view on Meta::CPAN
min_y => 0, max_y => 49,
swatch => 'blue-red',
);
for (1..2000) {
my $x = int(rand(50));
my $y = int(rand(50));
$map->inc($x, $y);
}
print $map;
$map->interpolate(1);
$map->width(25);
$map->height(25);
$map->swatch('grayscale');
print $map;
my $data = $map->data;
# Mess with the data...
print $map->render($data);
# Custom swatch
$map->swatch([0x10 .. 0x15]);
=head1 DESCRIPTION
Produce cutting-edge ANSI heatmaps using 256 colours and weird Unicode
characters! Perfect for 3D (2D + intensity) data.
=head1 METHODS
lib/ANSI/Heatmap.pm view on Meta::CPAN
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.
=head2 render ( DATA )
( run in 1.156 second using v1.01-cache-2.11-cpan-de7293f3b23 )