summaryrefslogtreecommitdiff
path: root/rt/html/Search/Chart
diff options
context:
space:
mode:
Diffstat (limited to 'rt/html/Search/Chart')
-rw-r--r--rt/html/Search/Chart68
1 files changed, 54 insertions, 14 deletions
diff --git a/rt/html/Search/Chart b/rt/html/Search/Chart
index ea52bb1..82704fd 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 <img>
+# 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 );
+</%init>
-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
+</%ARGS>
+<%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();
-</%init>
+
+die "Your GD library appears to support none of the following image types: " . join(', ', @types);
+</%INIT>
+
+</%METHOD>