| Jifty-Plugin-Chart documentation | Contained in the Jifty-Plugin-Chart distribution. |
Jifty::Plugin::Chart::Renderer::GD::Graph - A chart renderer using GD::Graph
In config.yml:
Plugins:
- Chart:
DefaultRenderer: Jifty::Plugin::Chart::Renderer::GD::Graph
This is a chart renderer that uses GD::Graph to build charts.
Adds the chart_img_behaviour.js script to those loaded.
Renders an IMG tag referring to the GD::Graph image view.
Andrew Sterling Hanenkamp <andrew.hanenkamp@boomer.com>
Copyright 2007 Boomer Consulting, Inc.
This is free software and may be modified and distributed under the same terms as Perl itself.
| Jifty-Plugin-Chart documentation | Contained in the Jifty-Plugin-Chart distribution. |
use strict; use warnings; package Jifty::Plugin::Chart::Renderer::GD::Graph; use base qw/ Jifty::Plugin::Chart::Renderer /;
sub init { Jifty->web->add_javascript('chart_img_behaviour.js'); }
sub render { my $self = shift; my %args = @_; # GD::Graph types from generic types my %types = ( lines => 'lines', bars => 'bars', horizontalbars => 'hbars', points => 'points', linespoints => 'linespoints', # non-standart area => 'area', pie => 'pie', mixed => 'mixed', # non-standard ); # Convert the generic type to a GD::Graph type $args{type} = $types{ $args{type} } || undef; # Save the data for retrieval from the session later my $chart_id = Jifty->web->serial; my $session_id = 'chart_' . $chart_id; Jifty->web->session->set( $session_id => Jifty::YAML::Dump(\%args) ); # Build up the chart tag my $img; $img = qq{<img}; $img .= qq{ src="/chart/gd_graph/$chart_id"}; $img .= qq{ class="@{[ join ' ', @{ $args{class} } ]}"}; my @styles; push @styles, "width:$args{width}" if defined $args{width}; push @styles, "height:$args{height}" if defined $args{height}; $img .= qq{ style="@{[ join ';', @styles ]}"} if @styles; $img .= qq{/>}; # Output the <img> tag and include the chart's configuration key Jifty->web->out($img); # Make sure we don't return anything that will get output return; }
1;