X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=rt%2Fhtml%2FSearch%2FChart;h=26249a734c2a7d5abf425aa9e7a9c478d25f719f;hp=ea52bb1f976f50e9f1e05e8d35a64a4ca063def0;hb=24548f7cf666bac02335d0bc74f81251c7b4ab50;hpb=ef20b2b6b1feb47ad02b5ff7525f1a0fd11d0fa4 diff --git a/rt/html/Search/Chart b/rt/html/Search/Chart index ea52bb1f9..26249a734 100644 --- a/rt/html/Search/Chart +++ b/rt/html/Search/Chart @@ -2,7 +2,7 @@ %# %# COPYRIGHT: %# -%# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC +%# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC %# %# %# (Except where explicitly superseded by other copyright notices) @@ -24,7 +24,7 @@ %# along with this program; if not, write to the Free Software %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA %# 02110-1301 or visit their web page on the internet at -%# http://www.gnu.org/copyleft/gpl.html. +%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. %# %# %# CONTRIBUTION SUBMISSION POLICY: @@ -74,14 +74,45 @@ $tix->GroupBy( FIELD => $PrimaryGroupBy ); my $value_name = $tix->Column( FIELD => $PrimaryGroupBy ); my $chart = $chart_class->new( 600 => 400 ); + +my $font = $RT::ChartFont || ['verdana', 'arial', gdMediumBoldFont]; +$chart->set_title_font( $font, 12 ) if $chart->can('set_title_font'); +$chart->set_legend_font( $font, 12 ) if $chart->can('set_legend_font'); +$chart->set_x_label_font( $font, 10 ) if $chart->can('set_x_label_font'); +$chart->set_y_label_font( $font, 10 ) if $chart->can('set_y_label_font'); +$chart->set_label_font( $font, 10 ) if $chart->can('set_label_font'); +$chart->set_x_axis_font( $font, 9 ) if $chart->can('set_x_axis_font'); +$chart->set_y_axis_font( $font, 9 ) if $chart->can('set_y_axis_font'); +$chart->set_values_font( $font, 9 ) if $chart->can('set_values_font'); +$chart->set_value_font( $font, 9 ) if $chart->can('set_value_font'); + +# Pie charts don't like having no input, so we show a special image +# that indicates an error message. Because this is used in an +# context, it can't be a simple error message. Without this check, +# the chart will just be a non-loading image. +if ($tix->Count == 0) { + my $plot = GD::Image->new(600 => 400); + $plot->colorAllocate(255, 255, 255); # background + my $black = $plot->colorAllocate(0, 0, 0); + + require GD::Text::Wrap; + my $error = GD::Text::Wrap->new($plot, + color => $black, + text => loc("No tickets found."), + ); + $error->set_font( $font, 12 ); + $error->draw(0, 0); + + $m->comp( 'SELF:Plot', plot => $plot, %ARGS ); +} + if ($chart_class eq "GD::Graph::bars") { $chart->set( x_label => $tix->Label( $PrimaryGroupBy ), x_labels_vertical => 1, - y_label => 'Tickets', + y_label => loc('Tickets'), show_values => 1 ); - $chart->set_legend_font( ['verdana', 'arial', gdMediumBoldFont], 12); } my %class = ( @@ -132,17 +163,26 @@ my @sorted_values = map { $data{$_}} @sorted_keys; my $plot = $chart->plot( [ [@sorted_keys], [@sorted_values] ] ) or die $chart->error; +$m->comp( 'SELF:Plot', plot => $plot, %ARGS ); + -if ( $plot->can('png') ) { - $r->content_type('image/png'); - $m->out( $plot->png ); -} -elsif ( $plot->can('gif') ) { - $r->content_type('image/gif'); - $m->out( $plot->gif ); -} -else { - die "Your GD library appears to support neither PNG nor GIF"; +<%METHOD Plot> +<%ARGS> +$plot => undef + +<%INIT> +my @types = ('png', 'gif'); + +for my $type (@types) { + $plot->can($type) + or next; + + $r->content_type("image/$type"); + $m->out( $plot->$type ); + $m->abort(); } -$m->abort(); - + +die "Your GD library appears to support none of the following image types: " . join(', ', @types); + + +