1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
package CGI::Application::Plugin::DBIProfile::Graph::HTMLBarGraph;
use strict;
use HTML::Template;
use HTML::BarGraph;
# NOTE: HTML::BarGraph is a little broken on its pure HTML output.
# if you have issues, try changing the "bartype" to "pixel", and
# setup the pixel directory ("/dbiprofile_images") in your webroot.
# NOTE: HTML::BarGraph is also pure broken.. can't call graph more
# than once, cause your maxval scaling will stick!
sub build_graph
{
my $proto = shift;
my $class = ref($proto) || $proto;
my %opts = @_;
#my $self = { };
#bless $self, $class;
$opts{data} ||= [];
my $stmt_count = @{$opts{data}};
my $title = "Top $stmt_count statements"; # by total runtime
my $tag = 1;
my $tags = [ map { $tag++ } @{$opts{data}} ];
my %defs = (
direction => 'v',
graphminsize => 50,
bartype => 'html', # pixel or html
pixeldir => '/dbiprofile_images',
pixelfmt => 'PNG',
barlength => 150,
barwidth => 10,
#baraspect => 0.5,
colors => ["#7187C7"], # this is color per-dataset.
data => [ ],
tags => $tags,
setspacer => 0,
#highlighttag => undef,
#highlightpos => [],
addalt => 1,
showaxistags => 1,
showvalues => 1,
valuesuffix => '', # s
valueprefix => '',
bordertype => 'flat', # reised or flat
bordercolor => 'black',
borderwidth => '3',
bgcolor => 'white',
textcolor => 'black',
title => $title,
titlecolor => 'black',
titlealign => 'center',
fontface => 'Verdana,Arial,San-Serif',
xlabel => '',
ylabel => 'Seconds',
xlabelalign => 'center',
ylabelalign => 'middle',
labeltextcolor => 'black',
labelbgcolor => '#aaaaaa',
);
%defs = (%defs, %opts);
return HTML::BarGraph::graph(%defs);
}
1;
__END__
=head1 NAME
CGI::Application::Plugin::DBIProfile::Graph::HTMLBarGraph - If it weren't for HTML::BarGraph bugs, this would work.
=head1 DO NOT USE THIS
This is provided because I had it done, and it provides another example, but there are bugs in HTML::BarGraph.
If HTML::BarGraph ever gets fixed, this will start to work correctly. The problem is its use of globals to track things like $maxval, which throws off scaling of the graph for subsequent calls to graph().
=head1 BUGS
HTML::BarGraph is not mod_perl safe. It has globals that track, for instance, $maxval. That doesn't get reset accross calls to graph(), so whatever your largest value graphed is, that will set the scale of all graphs to come.
Actually, it's not even single process safe... you can't make more than one call to graph().
=head1 SEE ALSO
L<CGI::Application::Plugin::DBIProfile>
=head1 AUTHOR
Joshua I Miller, L<unrtst@cpan.org>
=head1 COPYRIGHT & LICENSE
Copyright 2007 Joshua Miller, all rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut
|