% $worksheet->write( $r, $c++, shift( @row_labels ) );
% foreach ( @{ shift( @data ) } ) {
% $total += $_;
-% $bottom_total[$c] += $_;
+% $bottom_total[$c-1] += $_;
% $worksheet->write($r, $c++, sprintf($sprintf, $_) );
% }
% unless ( $opt{'nototal'} ) {
-% $bottom_total[$c] += $total;
+% $bottom_total[$c-1] += $total;
% $worksheet->write($r, $c++, sprintf($sprintf, $total) );
% }
% }
% my $class = "Chart::$graph_type";
%
% my $chart = $class->new(976,384);
-%
+% # the chart area itself is 900 pixels wide, and the date labels are ~60 each.
+% # staggered, we can fit about 28 of them.
+% # they're about 12 pixels high, so vertically, we can fit about 60 (allowing
+% # space for them to be readable).
+% # after that we have to start skipping labels. also remove the dots, since
+% # they're just a blob at that point.
+% my $num_labels = scalar(@{ $opt{axis_labels} });
+% my %chart_opt = %{ $opt{chart_options} || {} };
+% if ( $num_labels > 28 ) {
+% $chart_opt{x_ticks} = 'vertical';
+% if ( $num_labels > 60 ) {
+% $chart_opt{skip_x_ticks} = int($num_labels / 60) + 1;
+% $chart_opt{pt_size} = 1;
+% }
+% }
% my $d = 0;
% $chart->set(
% #'min_val' => 0,
% },
% 'legend_labels' => $opt{'graph_labels'},
% 'brush_size' => 4,
+% %chart_opt,
% );
%
% http_header('Content-Type' => 'image/png' );
+% http_header('Cache-Control' => 'no-cache' );
%
% $chart->_set_colors();
%
<% $chart->scalar_png([ $opt{'axis_labels'}, @data ]) %>
%
% } else {
+% # image and download links should use the cached data
+% # just directly reference this component
+% my $myself = $p.'graph/elements/report.html?session='.$session;
%
<% include('/elements/header.html', $opt{'title'} ) %>
-% $cgi->param('_type', 'png');
+% unless ( $opt{'graph_type'} eq 'none' ) {
-<IMG SRC="<% $cgi->self_url %>" WIDTH="976" HEIGHT="384">
-<P ALIGN="right">
+<IMG SRC="<% "$myself;_type=png" %>" WIDTH="976" HEIGHT="384"
+ STYLE="page-break-after:always;">
+% }
+<P ALIGN="right" CLASS="noprint">
% unless ( $opt{'disable_download'} ) {
-% $cgi->param('_type', "xls" );
Download full results<BR>
- as <A HREF="<% $cgi->self_url %>">Excel spreadsheet</A><BR>
-% $cgi->param('_type', 'csv');
- as <A HREF="<% $cgi->self_url %>">CSV file</A></P>
-% $cgi->param('_type', "html" );
+ as <A HREF="<% "$myself;_type=xls" %>">Excel spreadsheet</A><BR>
+ as <A HREF="<% "$myself;_type=csv" %>">CSV file</A></P>
% }
%
</P>
-<% include('/elements/table.html', 'e8e8e8') %>
-
-<TR>
-
- <TD></TD>
-
+%# indexed by item, then by entry (the element indices of @{$data[$i]}).
+% my @cell = ();
+% my @styles;
+% my $num_entries = scalar(@col_labels);
+% my $num_items = scalar(@items);
+% $cell[0] = ['']; #top left corner
% foreach my $column ( @col_labels ) {
-% $column =~ s/ /\<BR\>/; # working on a smarter way to do this
- <TH><% $column %></TH>
-% }
-
-% unless ( $opt{'nototal'} ) {
- <TH>Total</TH>
-% }
-
-</TR>
-
-% my @bottom_total = ();
+% $column =~ s/ /\<BR\>/;
+% push @{$cell[0]}, $column;
+% }
+% if ( ! $opt{'nototal'} ) {
+% $num_entries++;
+% push @{$cell[0]}, emt('Total');
+% }
+
+% # i for item, e for entry
+% my $i = 1;
% foreach my $row ( @items ) {
+% #make a style
+% my $color = shift @{ $opt{'colors'} };
+% push @styles, ".i$i { text-align: right; color: #$color; }";
+% #create the data row
+% my $links = shift @{$opt{'links'}} || [''];
+% my $link_prefix = shift @$links;
+% $link_prefix = '<A CLASS="cell" HREF="'.$link_prefix if $link_prefix;
+% my $label = shift @row_labels;
+% $cell[$i] = [ $label ];
%
-% my $color = shift( @{ $opt{'colors'} } );
-% my @links = @{ shift( @{ $opt{'links'} } ) };
-% # $opt{'links'} is an array parallel to items.
-% # Each element of that is an array containing a prefix,
-% # followed by suffixes matched to the cells of the table.
-% my $link_prefix = shift @links;
-% $link_prefix = $link_prefix ? qq(<A HREF="$link_prefix) : ''; #"
-% my $label = shift( @row_labels );
-
- <TR>
-
- <TH>
- <FONT COLOR="#<% $color %>"><% $label %></FONT>
- </TH>
+% my $data_row = $data[$i-1];
+%# my $data_row = shift @data;
+% if ( ! $opt{'nototal'} ) {
+% push @$data_row, sum(@$data_row);
+% }
+% foreach ( @$data_row ) {
+% my $entry = $_;
+% $entry = $money_char . sprintf($sprintf, $entry);
+% $entry = $link_prefix . shift(@$links) . "\">$entry</A>" if $link_prefix;
+% push @{$cell[$i]}, $entry;
+% }
+% $i++;
+% }
+% if ( $opt{'bottom_total'} ) {
+% # it's an extra item
+% $num_items++;
+% push @styles, ".i$i { text-align: right; background-color: #f5f6be; }";
+% my $links = $opt{'bottom_link'} || [];
+% my $link_prefix = shift @$links;
+% $link_prefix = '<A CLASS="cell" HREF="'.$link_prefix if $link_prefix;
+% $cell[$i] = [ emt('Total') ];
+% for (my $e = 0; $e < $num_entries + 1; $e++) {
+% my $entry = sum(map { $_->[$e] } @data);
+% $entry = $money_char . sprintf($sprintf, $entry);
+% $entry = $link_prefix . shift(@$links) . "\">$entry</A>" if $link_prefix;
+% push @{$cell[$i]}, $entry;
+% }
+% }
-% my $total = 0;
-% my $col = 0;
-% foreach my $column ( @{ shift( @data ) } ) {
+<STYLE type="text/css">
+a.cell {
+ color: inherit !important;
+}
+td.cell {
+ border-color: #000;
+}
+<% join("\n", @styles) %>
+%# item labels
+.e0 {
+ text-align: center;
+ font-weight: bold;
+}
+%# totals
+% if ( ! $opt{'nototal'} ) {
+.e<% $num_entries %> {
+ text-align: right;
+ background-color: #f5f6be;
+}
+% }
+%# date labels
+.i0 {
+ text-align: center;
+ font-weight: bold;
+}
+</STYLE>
- <TD ALIGN="right" BGCOLOR="#ffffff">
- <% $link_prefix ? $link_prefix . shift(@links) . '">' : '' %><FONT COLOR="#<% $color %>"><% $money_char %><% sprintf($sprintf,, $column) %></FONT><% $link_prefix ? '</A>' : '' %>
- </TD>
+<% include('/elements/table.html', 'f8f8f8') %>
+% if ( $opt{'transpose'} ) {
+% for ( my $e = 0; $e < $num_entries + 1; $e++ ) {
+ <TR>
+% for ( my $i = 0; $i < $num_items + 1; $i++ ) {
+ <TD CLASS="<%"cell i$i e$e"%>"><% $cell[$i][$e] %></TD>
+% }
+ </TR>
+% }
%
-% $total += $column;
-% $bottom_total[$col++] += $column;
-%
-% }
-
-% unless ( $opt{'nototal'} ) {
- <TD ALIGN="right" BGCOLOR="#f5f6be">
- <% $link_prefix ? $link_prefix. shift(@links) . '">' : '' %><FONT COLOR="#<% $color %>"><% $money_char %><% sprintf($sprintf, $total) %></FONT><% $link_prefix ? '</A>' : '' %>
- </TD>
-% $bottom_total[$col++] += $total;
-% }
-
- </TR>
-
-% }
-
-% if ( $opt{'bottom_total'} ) {
+% } else { #!transpose
+%
+% for (my $i = 0; $i < $num_items + 1; $i++) {
<TR>
- <TH>Total</TH>
-% my @bottom_links = $opt{'bottom_link'} ? @{ $opt{'bottom_link'} } : ();
-% my $prefix = shift(@bottom_links);
-% pop @bottom_links if $opt{'nototal'};
-% foreach my $total ( @bottom_total ) {
-
- <TD ALIGN="right" BGCOLOR="#f5f6be">
- <% $prefix
- ? '<A HREF="'. $prefix .shift(@bottom_links). '">'
- : ''
- %><% $money_char %><% sprintf($sprintf, $total) %><% $prefix ? '</A>' : '' %>
-
- </TD>
-
-% }
-
+% for (my $e = 0; $e < $num_entries + 1; $e++) {
+ <TD CLASS="<%"cell i$i e$e"%>"><% $cell[$i][$e] %></TD>
+% }
</TR>
-
-% }
-
+% }
</TABLE>
+% }
<% include('/elements/footer.html') %>
% }
<%init>
my(%opt) = @_;
+my $session;
+# load from cache if possible, to avoid recalculating
+if ( $cgi->param('session') =~ /^(\d+)$/ ) {
+ $session = $1;
+ %opt = %{ $m->cache->get($session) };
+}
+else {
+ $session = sprintf("%010d%06d", time, int(rand(1000000)));
+ $m->cache->set($session, \%opt, '1h');
+}
my $sprintf = $opt{'sprintf'} || '%.2f';