J
Josef Möllers
Hi,
I've hacked up a small script which takes lines of numbers (sar output)
and draws a histogram of the values found in one of the columns (I used
it to check for anomalies in the sar output).
I'd like to add some popup labels to the bars displayed, i.e. if I move
the mouse cursor over one of the bars, a small window should appear
telling me the value of the bar.
Any suggestion how this might be done?
The code is attached.
--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
#! /usr/bin/perl -w
use Getopt::Std;
use Tk;
my %opts;
getopts('c:s:', \%opts);
my $column = $opts{'c'} || 0;
my $separator = $opts{'s'} || '\s+';
my @data = ();
my $max = undef;
my $min = undef;
while (<STDIN>) {
print;
next if /^\s*#/;
chomp;
@values = split /$separator/;
$v = $values[$column];
next unless (defined($v) && $v =~ m/^\d+(\.\d*)?$/);
push @data, $v;
$max = $v if (!defined($max) || $v > $max);
$min = $v if (!defined($min) || $v < $min);
}
my $range = $max - $min;
$range = 1 unless $range;
my $sum = 0;
foreach (@data) {
$_ = (($_ - $min) * 100) / $range;
$sum += $_;
}
my $nsamples = scalar @data;
my $linewidth = int(1000 / $nsamples);
my $top = new MainWindow;
my $c = $top->Canvas(-width => $nsamples * $linewidth,
-height => 100,
-state => 'normal');
$c->pack(-side => 'top');
for (my $i = 0; $i < $nsamples; $i++) {
$c->createLine($i*$linewidth, 100, $i*$linewidth, 100-$data[$i], -width => $linewidth, -fill => 'black');
}
my $avg = $sum / $nsamples;
$c->createLine(0, 100-$avg, $nsamples*$linewidth-1, 100-$avg, -fill => 'red');
MainLoop;
I've hacked up a small script which takes lines of numbers (sar output)
and draws a histogram of the values found in one of the columns (I used
it to check for anomalies in the sar output).
I'd like to add some popup labels to the bars displayed, i.e. if I move
the mouse cursor over one of the bars, a small window should appear
telling me the value of the bar.
Any suggestion how this might be done?
The code is attached.
--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
#! /usr/bin/perl -w
use Getopt::Std;
use Tk;
my %opts;
getopts('c:s:', \%opts);
my $column = $opts{'c'} || 0;
my $separator = $opts{'s'} || '\s+';
my @data = ();
my $max = undef;
my $min = undef;
while (<STDIN>) {
print;
next if /^\s*#/;
chomp;
@values = split /$separator/;
$v = $values[$column];
next unless (defined($v) && $v =~ m/^\d+(\.\d*)?$/);
push @data, $v;
$max = $v if (!defined($max) || $v > $max);
$min = $v if (!defined($min) || $v < $min);
}
my $range = $max - $min;
$range = 1 unless $range;
my $sum = 0;
foreach (@data) {
$_ = (($_ - $min) * 100) / $range;
$sum += $_;
}
my $nsamples = scalar @data;
my $linewidth = int(1000 / $nsamples);
my $top = new MainWindow;
my $c = $top->Canvas(-width => $nsamples * $linewidth,
-height => 100,
-state => 'normal');
$c->pack(-side => 'top');
for (my $i = 0; $i < $nsamples; $i++) {
$c->createLine($i*$linewidth, 100, $i*$linewidth, 100-$data[$i], -width => $linewidth, -fill => 'black');
}
my $avg = $sum / $nsamples;
$c->createLine(0, 100-$avg, $nsamples*$linewidth-1, 100-$avg, -fill => 'red');
MainLoop;