X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Fhtml%2FSearch%2FChart;h=82704fdc78d3e53d9ecf29b4b18eb2c1b5dd264b;hb=8103c1fc1b2c27a6855feadf26f91b980a54bc52;hp=ea52bb1f976f50e9f1e05e8d35a64a4ca063def0;hpb=9c68254528b6f2c7d8c1921b452fa56064783782;p=freeside.git diff --git a/rt/html/Search/Chart b/rt/html/Search/Chart index ea52bb1f9..82704fdc7 100644 --- a/rt/html/Search/Chart +++ b/rt/html/Search/Chart @@ -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); + + +