1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
6 %# <jesse@bestpractical.com>
8 %# (Except where explicitly superseded by other copyright notices)
13 %# This work is made available to you under the terms of Version 2 of
14 %# the GNU General Public License. A copy of that license should have
15 %# been provided with this software, but in any event can be snarfed
18 %# This work is distributed in the hope that it will be useful, but
19 %# WITHOUT ANY WARRANTY; without even the implied warranty of
20 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 %# General Public License for more details.
23 %# You should have received a copy of the GNU General Public License
24 %# along with this program; if not, write to the Free Software
25 %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 %# 02110-1301 or visit their web page on the internet at
27 %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
30 %# CONTRIBUTION SUBMISSION POLICY:
32 %# (The following paragraph is not intended to limit the rights granted
33 %# to you to modify and distribute this software under the terms of
34 %# the GNU General Public License and is only of importance to you if
35 %# you choose to contribute your changes and enhancements to the
36 %# community by submitting them to Best Practical Solutions, LLC.)
38 %# By intentionally submitting any modifications, corrections or
39 %# derivatives to this work, or any other work intended for use with
40 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 %# you are the copyright holder for those contributions and you grant
42 %# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 %# royalty-free, perpetual, license to use, copy, create derivative
44 %# works based on those contributions, and sublicense and distribute
45 %# those contributions and any derivatives thereof.
47 %# END BPS TAGGED BLOCK }}}
50 $PrimaryGroupBy => 'Queue'
51 $SecondaryGroupBy => undef
59 if ($ChartStyle eq 'pie') {
60 require GD::Graph::pie;
61 $chart_class = "GD::Graph::pie";
63 require GD::Graph::bars;
64 $chart_class = "GD::Graph::bars";
67 use RT::Report::Tickets;
68 my $tix = RT::Report::Tickets->new( $session{'CurrentUser'} );
69 my ($count_name, $value_name) = $tix->SetupGroupings(
70 Query => $Query, GroupBy => $PrimaryGroupBy,
73 my $chart = $chart_class->new( 600 => 400 );
75 my $font = RT->Config->Get('ChartFont') || ['verdana', 'arial', gdMediumBoldFont];
76 $chart->set_title_font( $font, 12 ) if $chart->can('set_title_font');
77 $chart->set_legend_font( $font, 12 ) if $chart->can('set_legend_font');
78 $chart->set_x_label_font( $font, 10 ) if $chart->can('set_x_label_font');
79 $chart->set_y_label_font( $font, 10 ) if $chart->can('set_y_label_font');
80 $chart->set_label_font( $font, 10 ) if $chart->can('set_label_font');
81 $chart->set_x_axis_font( $font, 9 ) if $chart->can('set_x_axis_font');
82 $chart->set_y_axis_font( $font, 9 ) if $chart->can('set_y_axis_font');
83 $chart->set_values_font( $font, 9 ) if $chart->can('set_values_font');
84 $chart->set_value_font( $font, 9 ) if $chart->can('set_value_font');
86 # Pie charts don't like having no input, so we show a special image
87 # that indicates an error message. Because this is used in an <img>
88 # context, it can't be a simple error message. Without this check,
89 # the chart will just be a non-loading image.
90 if ($tix->Count == 0) {
91 my $plot = GD::Image->new(600 => 400);
92 $plot->colorAllocate(255, 255, 255); # background
93 my $black = $plot->colorAllocate(0, 0, 0);
95 require GD::Text::Wrap;
96 my $error = GD::Text::Wrap->new($plot,
98 text => loc("No tickets found."),
100 $error->set_font( $font, 12 );
103 $m->comp( 'SELF:Plot', plot => $plot, %ARGS );
106 if ($chart_class eq "GD::Graph::bars") {
108 x_label => $tix->Label( $PrimaryGroupBy ),
109 x_labels_vertical => 1,
110 y_label => loc('Tickets'),
116 Queue => 'RT::Queue',
118 Creator => 'RT::User',
119 LastUpdatedBy => 'RT::User',
121 my $class = $class{ $PrimaryGroupBy };
124 while ( my $entry = $tix->Next ) {
127 my $q = $class->new( $session{'CurrentUser'} );
128 $q->Load( $entry->__Value( $value_name ) );
132 $key = $entry->__Value($value_name);
134 $key ||= '(no value)';
136 my $value = $entry->__Value( $count_name );
137 if ($chart_class eq 'GD::Graph::pie') {
138 $key = loc($key) ." - ". $value;
142 $data{ $key } = $value;
145 # XXX: Convert 1970-01-01 date to the 'Not Set'
146 # this code should be generalized!!!
147 if ( $PrimaryGroupBy =~ /(Daily|Monthly|Annually)$/ ) {
149 $re = qr{1970-01-01} if $PrimaryGroupBy =~ /Daily$/;
150 $re = qr{1970-01} if $PrimaryGroupBy =~ /Monthly$/;
151 $re = qr{1970} if $PrimaryGroupBy =~ /Annually$/;
152 foreach my $k (keys %data) {
154 $tmp =~ s/^$re/loc('Not Set')/e or next;
155 $data{$tmp} = delete $data{$k};
159 unless (keys %data) {
163 my $plot = $chart->plot( [ [sort keys %data], [map $data{$_}, sort keys %data] ] ) or die $chart->error;
164 $m->comp( 'SELF:Plot', plot => $plot, %ARGS );
172 my @types = ('png', 'gif');
174 for my $type (@types) {
178 $r->content_type("image/$type");
179 $m->out( $plot->$type );
183 die "Your GD library appears to support none of the following image types: " . join(', ', @types);