Text::Quantize - render a list of numbers as a textual chart
version 0.05
use Text::Quantize; print quantize([26, 24, 51, 77, 21]); __END__ value ------------- Distribution ------------- count 8 | 0 16 |@@@@@@@@@@@@@@@@@@@@@@@@ 3 32 |@@@@@@@@ 1 64 |@@@@@@@@ 1 128 | 0
use Text::Quantize (); print Text::Quantize::quantize([map { chomp; $_ } <DATA>], { left_label => 'microseconds', middle_label => 'Calls per time bucket', right_label => 'syscalls', distribution_width => 80, distribution_character => '=', }); __END__ microseconds ---------------------------- Calls per time bucket ----------------------------- syscalls 256 | 0 512 |==== 5 1024 |===== 7 2048 |================== 23 4096 |============================ 36 8192 |======= 9 16384 |= 2 32768 | 1 262144 | 1 524288 | 1 1048576 | 1 2097152 |======= 9 4194304 |=== 4 8388608 | 1 16777216 | 0
quantize([integers], {options})
quantize takes an array reference of integers and an optional hash reference of options, and produces a textual histogram of the integers bucketed into powers-of-2 sets.
quantize
Options include:
left_label
value
Controls the text of the left-most label which represents the bucket's contents.
middle_label
Distribution
Controls the text of the middle label which can be used to title the histogram.
right_label
count
Controls the text of the right-most label which represents how many items are in that bucket.
distribution_width
40
Controls how many characters wide the textual histogram is. This does not include the legends.
distribution_character
@
Controls the character used to represent the data in the histogram.
add_endpoints
1
Controls whether the top and bottom lines (which are going to have values of 0) are added. They're included by default because it hints that the data set is complete.
bucketize([integers], {options})
bucketize takes an array reference of integers and an optional hash reference of options, and produces a hash reference of those integers bucketed into powers-of-2 sets.
bucketize
Controls whether extra buckets, smaller than the minimum value and larger than the maximum value, (which are going to have values of 0) are added. They're included by default because it hints that the data set is complete.
DTrace, which is where I first saw this kind of quantize() histogram.
DTrace
quantize()
dip, which ported quantize() to Perl first, and from which I took a few insights.
Shawn M Moore <code@sartak.org>
This software is copyright (c) 2012 by Infinity Interactive.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Text::Quantize, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Text::Quantize
CPAN shell
perl -MCPAN -e shell install Text::Quantize
For more information on module installation, please visit the detailed CPAN module installation guide.