| Jifty-Plugin-Chart documentation | Contained in the Jifty-Plugin-Chart distribution. |
Jifty::Plugin::Chart::Dispatcher - Dispatcher for the chart API plugin
Grabs the chart configuration stored in the key indicated in $1 and unpacks it using YAML. It then passes it to the correct Jifty::Plugin::Chart::View template.
Andrew Sterling Hanenkamp <andrew.hanenkamp@boomer.com>
Copyright 2007 Boomer Consulting, Inc.
This is free software and may be modified and redistributed 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::Dispatcher; use Jifty::Dispatcher -base; use Jifty::YAML;
my %classes = ( chart => 'Chart::$TYPE', gd_graph => 'GD::Graph::$TYPE', xmlswf => 'XML::Simple', );
on 'chart/*/*' => run { my $renderer = $1; # No renderer? Act like a 404. last_rule if not defined $classes{$renderer}; # Create a session ID to lookup the chart configuration my $session_id = 'chart_' . $2; # Unpack the data and then clear it from the session my $args = Jifty::YAML::Load( Jifty->web->session->get( $session_id ) ); # XXX if there are a lot of charts, this could asplode #Jifty->web->session->remove( $session_id ); # No data? Act like a 404 last_rule unless defined $args; # Request might override width/height: $args->{width} = get 'width' if get 'width'; $args->{height} = get 'height' if get 'height'; # XXX TODO Is there a better way to guess the pixel heights when using CSS # heights initially? # Remove 'px' from width/height and set to 400/300 if not in pixels ($args->{width} =~ s/px$//) or ($args->{width} = 400); ($args->{height} =~ s/px$//) or ($args->{height} = 300); # No zeroes! Ba Ba Blacksheep. $args->{width} ||= 400; $args->{height} ||= 300; if (my $class = $classes{$renderer}) { # Use the "type" to determine which class to use $class =~ s/\$TYPE/$args->{type}/g; # Load that class or die if it does not exist $class->require; # Remember the class name for the view $args->{class} = $class; } # Send them on to chart the chart set 'args' => $args; show "chart/$renderer"; };
1;