[Jifty-commit] r6008 - in jifty/trunk: lib/Jifty/Plugin/Chart/Renderer

Jifty commits jifty-commit at lists.jifty.org
Mon Nov 17 19:19:02 EST 2008


Author: sartak
Date: Mon Nov 17 19:19:00 2008
New Revision: 6008

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty/Plugin/Chart/Renderer/GoogleViz.pm

Log:
 r75686 at onn:  sartak | 2008-11-17 19:18:51 -0500
 skeleton of GoogleViz->render


Modified: jifty/trunk/lib/Jifty/Plugin/Chart/Renderer/GoogleViz.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/Chart/Renderer/GoogleViz.pm	(original)
+++ jifty/trunk/lib/Jifty/Plugin/Chart/Renderer/GoogleViz.pm	Mon Nov 17 19:19:00 2008
@@ -3,6 +3,8 @@
 use warnings;
 use base 'Jifty::Plugin::Chart::Renderer';
 
+use Jifty::JSON;
+
 =head2 init
 
 We need to load Google's JS.
@@ -21,12 +23,32 @@
 
 sub render {
     my $self = shift;
-    if (ref($self) eq __PACKAGE) {
-        Carp::croak("You must use a subclass of GoogleViz, such as GoogleViz::AnnotatedTimeLine");
-    }
-    else {
-        Carp::croak(ref($self) . " does not implement render.");
-    }
+    my $chart_id = 'chart_' . Jifty->web->serial;
+    my $chart_class = $self->chart_class;
+    my $load_params = objToJson {
+        packages => [ $self->packages_to_load ],
+    };
+    my $draw_params = objToJson($self->draw_params);
+
+    Jifty->web->out(<< "JS_HEADER");
+        <script type="text/javascript">
+            google.load('visualization', 1, $load_params);
+            google.setOnLoadCallback(function () {
+                var data = new google.visualization.DataTable();
+JS_HEADER
+
+    $self->render_data;
+
+    Jifty->web->out(<< "JS_FOOTER");
+                var chart = new $chart_class(document.getElementById('$chart_id'));
+                chart.draw(data, $draw_params);
+            });
+        </script>
+JS_FOOTER
+
+    Jifty->web->out(qq{<div id="$chart_id"></div>});
+
+    return;
 }
 
 1;


More information about the Jifty-commit mailing list