Benchmark-Harness-Graph
view release on metacpan or search on metacpan
### Return the <div> representing what gets displayed by hotspot click.
### Put this in a display:none element so it shows only via <script> control.
sub hotspotText {
my ($self, $axislist, $idx) = @_;
return <<EOT;
<div id=hs_$idx style='position:absolute;display:none;top:0;left:0;'>$axislist->[$idx]->{legend}</div>
EOT
}
### ################################################################################################
### Take GD::Graph's hotspot output and project it to the smallest array.
sub collapseArea {
my $self = shift;
my $answer = [];
my $thisSpot = undef;
for ( @_ ) {
if ( defined $thisSpot ) {
if ( defined($_) && ($thisSpot->[3] == $_->[1]) ) {
$thisSpot->[3] = $_->[3];
}
else {
push @$answer, $thisSpot;
$thisSpot = undef;
}
}
else {
if ( defined $_ ) {
$_->[2] -= 1;
$_->[4] += 1;
$thisSpot = $_;
}
}
}
push @$answer, $thisSpot if defined $thisSpot;
return $answer;
}
### ################################################################################################
### Return the entire <script> element to insert in the html <head>
sub htmlScript {
<<EOT;
<script language=javascript>
function ShowDetail (idx) {
var detail = document.getElementById("hs_"+idx);
if ( detail == null ) return;
var iframe = document.getElementById("detailview");
iframe.contentWindow.document.body.innerHTML = detail.innerHTML;
}
</script>
EOT
}
### ################################################################################################
### Return the entire <style> element to insert in the html <head>
sub htmlStyle {
<<EOT;
<style>
<!--
.x_legend {
font-weight: bold;
text-align: center;
}
.y1_legend {
font-weight: bold;
font-size: 12;
text-align: center;
vertical-align: middle;
text-color: green;
}
.y2_legend {
font-weight: bold;
font-size: 12;
text-align: center;
vertical-align: middle;
text-color: red;
}
-->
</style>
EOT
}
### ################################################################################################
### Return the entire <table> element, up to end of graph area, to insert in the html <body>
sub htmlGraph {
my $self = shift;
my ($href) = ($self->{graphFilename} =~ m{([^/]*)$});
my $x_legend = $self->{x_legend} || 'Time';
my $y1_legend = $self->{y1_legend} || 'Memory';
$y1_legend =~ s{(.)}{$1<br>}g;
my $y2_legend = $self->{y2_legend} || 'CPU';
$y2_legend =~ s{(.)}{$1<br>}g;
<<EOT;
<table width=700 align=center cellspacing=10>
<tr>
<td width=6% class=y1_legend><font color='$self->{y1_color}'>$y1_legend</font></td>
<td width=4%> </td>
<td align=center><img src="$href" USEMAP="#clientsidemap" border=0></td>
<td width=4%> </td>
<td width=6% class=y2_legend><font color='$self->{y2_color}'>$y2_legend</font></td>
</tr>
<tr><td colspan=3 class=x_legend>$x_legend</td></tr>
EOT
}
### ################################################################################################
### ################################################################################################
### ################################################################################################
package Benchmark::Harness::GraphLineData;
use strict;
### ################################################################################################
# new($legend, $color)
sub new {
return bless
{
'data' => $_[1]
,'legend' => $_[2]
,'color' => $_[3]
,'line_width' => defined($_[4])?$_[4]:1
}
}
### ################################################################################################
sub Max {
my ($data, $max) = ($_[0]->{data}, -999999999);
map { do {$max = ($max > $_)?$max:$_} if defined $_} @$data;
return $max;
( run in 1.096 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )