/usr/share/perl5/Jifty/Plugin/Chart/Renderer/SimpleBars.pm is in libjifty-plugin-chart-perl 1.01+dfsg-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | use strict;
use warnings;
package Jifty::Plugin::Chart::Renderer::SimpleBars;
use base qw/ Jifty::Plugin::Chart::Renderer /;
=head1 NAME
Jifty::Plugin::Chart::Renderer::SimpleBars - a simple horizontal bar chart
=head1 DESCRIPTION
This is a simple renderer for charts created both as a dead simple way of rendering horizontal bar charts, which can be a very simple way of rendering data, and as a prototype for some other work I'm thinking of doing with the chart plugin.
=head1 OPTIONS
Of the rendering API, this only uses the first dataset given and ignores any others. It also fails if used for any type other than the only one it supports "horizontalbars".
It takes the following options:
=over
=item summary
To maximize the accessibility of your chart, set this to describe the data. This will set the table's summary attribute.
=back
=head1 STYLING
Please be aware that when using this object, you can change the bar color
using CSS like so:
div.simple_bars span.bar {
background-color: black;
}
=head1 METHODS
=head2 init
Tell Jifty about the CSS and JS files SimpleBars needs.
=cut
sub init {
Jifty->web->add_javascript('simple_bars.js');
Jifty->web->add_css('simple_bars.css');
}
=head2 render
Renders a horizontal bar chart. This is done by rendering a table of HTML values, which is then converted to a bar chart by the Javascript added to the response during L</init>.
If JavaScript is not supported by the browser, all the data is presented ina table. They can still read the data, but just not in the most readable form.
=cut
sub render {
my $self = shift;
my %args = @_;
# We only handle horizontalbars, fail on all else
if ($args{type} ne 'horizontalbars') {
die 'Sorry, SimpleBars charts only handle horizontalbars chart types.';
}
# Create a fresh ID for the chart
my $chart_id = 'chart_' . Jifty->web->serial;
# Add the simple_bars class for the JavaScript to find
push @{ $args{class} }, 'simple_bars';
# Build the table
my $table;
$table = qq{<table id="$chart_id"};
$table .= qq{ class="@{[ join ' ', @{ $args{class} } ]}"};
$table .= qq{ summary="$args{summary}"} if $args{summary};
$table .= qq{/><tbody>};
for my $index (0 .. $#{ $args{data}[0] }) {
my $label = $args{data}[0][$index];
my $point = $args{data}[1][$index];
$table .= '<tr>';
$table .= "<td>@{[ Jifty->web->escape($label) ]}</td>";
$table .= "<td>@{[ Jifty->web->escape($point) ]}</td>";
$table .= '</tr>';
}
$table .= '</tbody></table>';
Jifty->web->out($table);
return;
}
=head1 AUTHOR
Andrew Sterling Hanenkamp, C<< <andrew.hanenkamp@boomer.com> >>
=head1 COPYRIGHT AND LICENSE
Copyright 2007 Boomer Consulting, Inc.
This is free software. You may modify and redistribute it under the same terms as Perl itself.
=cut
1
|