[Jifty-commit] r3724 - in jifty/trunk: . lib/Jifty/Plugin
lib/Jifty/Plugin/Chart/Renderer lib/Jifty/Plugin/Chart/XMLSWF
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Fri Jul 27 15:54:55 EDT 2007
Author: sterling
Date: Fri Jul 27 15:54:54 2007
New Revision: 3724
Added:
jifty/trunk/lib/Jifty/Plugin/Chart/
jifty/trunk/lib/Jifty/Plugin/Chart.pm
jifty/trunk/lib/Jifty/Plugin/Chart/Dispatcher.pm
jifty/trunk/lib/Jifty/Plugin/Chart/Renderer/
jifty/trunk/lib/Jifty/Plugin/Chart/Renderer.pm
jifty/trunk/lib/Jifty/Plugin/Chart/Renderer/Chart.pm
jifty/trunk/lib/Jifty/Plugin/Chart/View.pm
jifty/trunk/lib/Jifty/Plugin/Chart/Web.pm
jifty/trunk/lib/Jifty/Plugin/Chart/XMLSWF/
Modified:
jifty/trunk/ (props changed)
Log:
r8183 at riddle: andrew | 2007-07-27 12:49:07 -0700
Adding a plugin for rendering charts of data.
Added: jifty/trunk/lib/Jifty/Plugin/Chart.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/lib/Jifty/Plugin/Chart.pm Fri Jul 27 15:54:54 2007
@@ -0,0 +1,30 @@
+use strict;
+use warnings;
+
+package Jifty::Plugin::Chart;
+use base qw/ Jifty::Plugin Class::Accessor::Fast /;
+
+use Jifty::Plugin::Chart::Web;
+
+__PACKAGE__->mk_accessors(qw/ renderer /);
+
+sub init {
+ my $self = shift;
+ my %args = (
+ renderer => __PACKAGE__.'::Renderer::Chart',
+ @_,
+ );
+
+ eval "use $args{renderer}";
+ warn $@ if $@;
+ $self->renderer( $args{renderer} );
+
+ push @Jifty::Web::ISA, 'Jifty::Plugin::Chart::Web';
+}
+
+sub render {
+ my $self = shift;
+ $self->renderer->render(@_);
+}
+
+1;
Added: jifty/trunk/lib/Jifty/Plugin/Chart/Dispatcher.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/lib/Jifty/Plugin/Chart/Dispatcher.pm Fri Jul 27 15:54:54 2007
@@ -0,0 +1,21 @@
+use strict;
+use warnings;
+
+package Jifty::Plugin::Chart::Dispatcher;
+use Jifty::Dispatcher -base;
+
+use Jifty::YAML;
+
+on 'chart/*' => run {
+ my $session_id = 'chart_' . $1;
+
+ my $args = Jifty::YAML::Load( Jifty->web->session->get( $session_id ) );
+ Jifty->web->session->remove( $session_id );
+
+ last_rule unless defined $args;
+
+ set 'args' => $args;
+ show 'chart';
+};
+
+1;
Added: jifty/trunk/lib/Jifty/Plugin/Chart/Renderer.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/lib/Jifty/Plugin/Chart/Renderer.pm Fri Jul 27 15:54:54 2007
@@ -0,0 +1,6 @@
+use strict;
+use warnings;
+
+package Jifty::Plugin::Chart::Renderer;
+
+1;
Added: jifty/trunk/lib/Jifty/Plugin/Chart/Renderer/Chart.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/lib/Jifty/Plugin/Chart/Renderer/Chart.pm Fri Jul 27 15:54:54 2007
@@ -0,0 +1,32 @@
+use strict;
+use warnings;
+
+package Jifty::Plugin::Chart::Renderer::Chart;
+use base qw/ Jifty::Plugin::Chart::Renderer /;
+
+use Jifty::YAML;
+
+sub render {
+ my $self = shift;
+ my %args = (
+ type => 'points',
+ width => 400,
+ height => 300,
+ data => [],
+ @_,
+ );
+
+ for my $key (keys %args) {
+ $args{$key} = $args{$key}->(\%args) if ref $args{$key} eq 'CODE';
+ }
+
+ my $chart_id = Jifty->web->serial;
+ my $session_id = 'chart_' . $chart_id;
+ Jifty->web->session->set( $session_id => Jifty::YAML::Dump(\%args) );
+
+ Jifty->web->out(qq{<img src="/chart/$chart_id" width="$args{width}" height="$args{height}"/>});
+
+ return;
+}
+
+1;
Added: jifty/trunk/lib/Jifty/Plugin/Chart/View.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/lib/Jifty/Plugin/Chart/View.pm Fri Jul 27 15:54:54 2007
@@ -0,0 +1,25 @@
+use strict;
+use warnings;
+
+package Jifty::Plugin::Chart::View;
+use Jifty::View::Declare -base;
+
+use IO::String;
+
+template 'chart' => sub {
+ my $args = get 'args';
+
+ my $class = 'Chart::' . $args->{type};
+
+ eval "use $class";
+ die $@ if $@;
+
+ Jifty->handler->apache->content_type('image/png');
+
+ my $fh = IO::String->new;
+ my $chart = $class->new( $args->{width}, $args->{height} );
+ $chart->png($fh, $args->{data});
+ outs_raw( ${ $fh->string_ref } )
+};
+
+1;
Added: jifty/trunk/lib/Jifty/Plugin/Chart/Web.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/lib/Jifty/Plugin/Chart/Web.pm Fri Jul 27 15:54:54 2007
@@ -0,0 +1,12 @@
+use strict;
+use warnings;
+
+package Jifty::Plugin::Chart::Web;
+
+sub chart {
+ my $self = shift;
+ my ($plugin) = Jifty->find_plugin('Jifty::Plugin::Chart');
+ return $plugin->render(@_);
+}
+
+1;
More information about the Jifty-commit
mailing list