4
package Jifty::Plugin::Chart::Renderer::SimpleBars;
5
use base qw/ Jifty::Plugin::Chart::Renderer /;
9
Jifty::Plugin::Chart::Renderer::SimpleBars - a simple horizontal bar chart
13
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.
17
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".
19
It takes the following options:
25
To maximize the accessibility of your chart, set this to describe the data. This will set the table's summary attribute.
31
Please be aware that when using this object, you can change the bar color
34
div.simple_bars span.bar {
35
background-color: black;
42
Tell Jifty about the CSS and JS files SimpleBars needs.
47
Jifty->web->add_javascript('simple_bars.js');
48
Jifty->web->add_css('simple_bars.css');
53
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>.
55
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.
63
# We only handle horizontalbars, fail on all else
64
if ($args{type} ne 'horizontalbars') {
65
die 'Sorry, SimpleBars charts only handle horizontalbars chart types.';
68
# Create a fresh ID for the chart
69
my $chart_id = 'chart_' . Jifty->web->serial;
71
# Add the simple_bars class for the JavaScript to find
72
push @{ $args{class} }, 'simple_bars';
76
$table = qq{<table id="$chart_id"};
77
$table .= qq{ class="@{[ join ' ', @{ $args{class} } ]}"};
78
$table .= qq{ summary="$args{summary}"} if $args{summary};
79
$table .= qq{/><tbody>};
81
for my $index (0 .. $#{ $args{data}[0] }) {
82
my $label = $args{data}[0][$index];
83
my $point = $args{data}[1][$index];
86
$table .= "<td>@{[ Jifty->web->escape($label) ]}</td>";
87
$table .= "<td>@{[ Jifty->web->escape($point) ]}</td>";
91
$table .= '</tbody></table>';
93
Jifty->web->out($table);
100
Andrew Sterling Hanenkamp, C<< <andrew.hanenkamp@boomer.com> >>
102
=head1 COPYRIGHT AND LICENSE
104
Copyright 2007 Boomer Consulting, Inc.
106
This is free software. You may modify and redistribute it under the same terms as Perl itself.