Skip to content

Instantly share code, notes, and snippets.

@JJ
Last active December 18, 2021 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JJ/1d08d02a1b57b38d1325fc6162b6fe9f to your computer and use it in GitHub Desktop.
Save JJ/1d08d02a1b57b38d1325fc6162b6fe9f to your computer and use it in GitHub Desktop.
Embedding Text::Chart code
unit module Text::Chart;
constant $default-char is export = "█";
sub vertical ( Int :$max = 10,
Str :$chart-chars = $default-char,
*@data ) is export {
my $space = " ";
my @chars = $chart-chars.comb;
my $chart;
for $max^...0 -> $i {
for 0..^@data.elems -> $j {
$chart ~= @data[$j] > $i ?? @chars[$j % @chars.elems] !!
$space;
}
$chart ~= "\n";
}
return $chart;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment