5 columnar_table.mas - a Mason module to display tables
11 headings => [ col name, col name,...],
12 data => [ [html, html, ...],
14 { onmouseover => "alert('ow!')",
22 __align => 'cccccc...',
23 __tableattrs => 'summary="" cellspacing="0" width="100%"',
26 __caption => 'Optional table caption',
32 # also can generate simple frequency tables of the values in the given
33 # columns, makes one table per column, printed before the main table.
34 # These auxiliary frequency tables will only be printed if there are
35 # more than 4 rows in the table.
36 frequency_tables => ['col name','col name', ...],
40 Lukas Mueller, based on Perl code by Rob Buels
48 $frequency_tables => []
52 use Lingua::EN::Inflect ();
53 use CXGN::Page::FormattingHelpers qw | columnar_table_html |;
56 if( @$frequency_tables && @$data > 4) {
57 my %heading_idx = do { my $i = 0; map {lc $_ => $i++} @$frequency_tables };
58 for my $colname (@$frequency_tables) {
59 my $idx = $heading_idx{ lc $colname };
60 my $name = $headings->[$idx];
61 my @data_slice = map $_->[$idx], @$data;
63 $stats{$_}++ for @data_slice;
68 if( @stat_disp > 1 ) {
69 push @stat_disp, [ List::Util::sum( map $_->[0], @stat_disp ), '<b>Total</b>' ];
72 print '<div style="width: 30%; float: left; margin: 2px;">'.columnar_table_html( data => \@stat_disp, __caption => Lingua::EN::Inflect::PL_N( $name ), __align => 'rl' ).'</div>';
76 <% columnar_table_html( %ARGS ) %>