[Jifty-commit] r3832 - in jifty/branches/virtual-models: .
lib/Jifty/Plugin lib/Jifty/Plugin/Chart
lib/Jifty/Plugin/Chart/Renderer lib/Jifty/View/Declare
share/plugins/Jifty/Plugin/Chart/web/static/css
share/plugins/Jifty/Plugin/Chart/web/static/flash
share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf
share/plugins/Jifty/Plugin/Chart/web/static/js
share/plugins/Jifty/Plugin/Chart/web/static/js/PlotKit
share/web/static/js
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Thu Aug 9 17:41:08 EDT 2007
Author: sterling
Date: Thu Aug 9 17:41:06 2007
New Revision: 3832
Added:
jifty/branches/virtual-models/lib/Jifty/Plugin/Chart/Renderer/SimpleBars.pm
jifty/branches/virtual-models/lib/Jifty/Plugin/Chart/Renderer/XMLSWF.pm
jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/css/
jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/css/simple_bars.css
jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/
jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/
jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts.swf (contents, props changed)
jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/
jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/arno.swf (contents, props changed)
jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/arst.swf (contents, props changed)
jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/brfl.swf (contents, props changed)
jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/brno.swf (contents, props changed)
jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/brst.swf (contents, props changed)
jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/cl3d.swf (contents, props changed)
jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/clfl.swf (contents, props changed)
jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/clno.swf (contents, props changed)
jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/clp3.swf (contents, props changed)
jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/cls3.swf (contents, props changed)
jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/clst.swf (contents, props changed)
jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/cnno.swf (contents, props changed)
jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/lnno.swf (contents, props changed)
jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/mxno.swf (contents, props changed)
jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/pi3d.swf (contents, props changed)
jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/pino.swf (contents, props changed)
jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/pono.swf (contents, props changed)
jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/scno.swf (contents, props changed)
jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/js/simple_bars.js
Modified:
jifty/branches/virtual-models/ (props changed)
jifty/branches/virtual-models/Makefile.PL
jifty/branches/virtual-models/lib/Jifty/Plugin/Chart/ (props changed)
jifty/branches/virtual-models/lib/Jifty/Plugin/Chart.pm
jifty/branches/virtual-models/lib/Jifty/Plugin/Chart/Dispatcher.pm
jifty/branches/virtual-models/lib/Jifty/Plugin/Chart/Renderer.pm
jifty/branches/virtual-models/lib/Jifty/Plugin/Chart/Renderer/PlotKit.pm
jifty/branches/virtual-models/lib/Jifty/Plugin/Chart/View.pm
jifty/branches/virtual-models/lib/Jifty/View/Declare/CRUD.pm
jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/js/PlotKit/PlotKit_Packed-20060807-custom.js
jifty/branches/virtual-models/share/web/static/js/jifty.js
Log:
r8466 at riddle: andrew | 2007-08-09 16:09:13 -0500
Merge down from trunk.
r8370 at riddle: andrew | 2007-08-04 17:29:36 -0500
r8356 at dynpc145: andrew | 2007-08-04 16:33:13 -0500
Added better error handling on renderer require.
r8371 at riddle: andrew | 2007-08-04 17:30:09 -0500
r8357 at dynpc145: andrew | 2007-08-04 16:33:37 -0500
Fixed typos in the new type handling code and fixed error handling.
r8372 at riddle: andrew | 2007-08-04 17:30:09 -0500
r8358 at dynpc145: andrew | 2007-08-04 16:46:12 -0500
Fixing my previous brain damage and additional typos.
r8373 at riddle: andrew | 2007-08-04 17:30:10 -0500
r8359 at dynpc145: andrew | 2007-08-04 16:53:49 -0500
Improved the way the DIV tag is generated for PlotKit.
r8374 at riddle: andrew | 2007-08-04 17:30:10 -0500
r8360 at dynpc145: andrew | 2007-08-04 16:59:22 -0500
Removed some redundant code from the PlotKit renderer and added support for options to the GD::Graph and Chart renderers.
r8386 at riddle: andrew | 2007-08-05 16:23:50 -0500
Adding the SimpleBars renderer as a decent, dead-simple HTML-based renderer for HorizontalBars and a prototype for using tables for client-side chart configuration.
r8392 at riddle: andrew | 2007-08-05 18:06:59 -0500
r8388 at dynpc145: andrew | 2007-08-05 17:19:52 -0500
Make sure we do not attempt to render 0 pixel values no matter what.
r8461 at riddle: andrew | 2007-08-09 08:26:27 -0500
r8425 at riddle (orig r3796): trs | 2007-08-05 19:34:44 -0500
r25915 at zot: tom | 2007-08-05 20:34:08 -0400
Render onAvailable instead of on window load so that we work in regions
r8426 at riddle (orig r3797): trs | 2007-08-05 20:35:49 -0500
r25919 at zot: tom | 2007-08-05 21:35:39 -0400
Use PlotKit.Base.map explicitly
r8449 at riddle (orig r3820): trs | 2007-08-06 16:18:23 -0500
r25943 at zot: tom | 2007-08-06 17:17:51 -0400
Without the conditional we'll hide errors as soon as we display them
r8450 at riddle (orig r3821): trs | 2007-08-06 18:38:53 -0500
r25961 at zot: tom | 2007-08-06 19:38:14 -0400
Fix view CRUD template's method of getting the record
r8451 at riddle (orig r3822): trs | 2007-08-07 23:54:59 -0500
r25997 at zot: tom | 2007-08-08 00:54:25 -0400
Bunch of updates to the chart plugin
- Refactored dispatcher
- Added XML SWF renderer
- Renderers are now passed the configuration hash when init'd
r8452 at riddle (orig r3823): trs | 2007-08-08 00:01:40 -0500
r25999 at zot: tom | 2007-08-08 01:01:30 -0400
- Treat the width and height appropriately
- Add the XML::Simple dep
r8453 at riddle (orig r3824): trs | 2007-08-08 00:12:55 -0500
r26001 at zot: tom | 2007-08-08 01:12:44 -0400
Don't specify an align attribute
r8454 at riddle (orig r3825): trs | 2007-08-08 00:46:05 -0500
r26005 at zot: tom | 2007-08-08 01:45:55 -0400
Whoops. Forgot to check in the actual XML SWF library. This is version 4.6.
Modified: jifty/branches/virtual-models/Makefile.PL
==============================================================================
--- jifty/branches/virtual-models/Makefile.PL (original)
+++ jifty/branches/virtual-models/Makefile.PL Thu Aug 9 17:41:06 2007
@@ -155,6 +155,7 @@
recommends('Chart::Base'),
recommends('GD'), # for a testing hack
recommends('GD::Graph'),
+ recommends('XML::Simple'),
recommends('Image::Info'), # for testing
],
);
Modified: jifty/branches/virtual-models/lib/Jifty/Plugin/Chart.pm
==============================================================================
--- jifty/branches/virtual-models/lib/Jifty/Plugin/Chart.pm (original)
+++ jifty/branches/virtual-models/lib/Jifty/Plugin/Chart.pm Thu Aug 9 17:41:06 2007
@@ -76,7 +76,7 @@
$self->renderers({});
# Load the default renderer
- $self->renderer( $self->init_renderer($args{renderer}) );
+ $self->renderer( $self->init_renderer( $args{renderer}, %args ) );
push @Jifty::Web::ISA, 'Jifty::Plugin::Chart::Web';
}
@@ -90,7 +90,7 @@
=cut
sub init_renderer {
- my ($self, $renderer_class) = @_;
+ my ( $self, $renderer_class ) = ( shift, shift );
# If it's already an object, just return that
if ( blessed($renderer_class)
@@ -108,10 +108,11 @@
return $renderer if defined $renderer;
# Tell perl to load the class
- $renderer_class->require;
+ $renderer_class->require
+ or warn $@;
# Initialize the renderer
- $renderer = $renderer_class->new;
+ $renderer = $renderer_class->new( @_ );
# Remember it
$self->renderers->{ $renderer_class } = $renderer;
Modified: jifty/branches/virtual-models/lib/Jifty/Plugin/Chart/Dispatcher.pm
==============================================================================
--- jifty/branches/virtual-models/lib/Jifty/Plugin/Chart/Dispatcher.pm (original)
+++ jifty/branches/virtual-models/lib/Jifty/Plugin/Chart/Dispatcher.pm Thu Aug 9 17:41:06 2007
@@ -10,66 +10,35 @@
Jifty::Plugin::Chart::Dispatcher - Dispatcher for the chart API plugin
-=head1 RULES
-
-=head2 chart/chart/*
-
-Grabs the chart configuration stored in the key indicated in C<$1> and unpacks it using L<YAML>. It then passes it to the L<Jifty::Plugin::Chart::View/chart> template.
-
=cut
-on 'chart/chart/*' => run {
- # Create a session ID to lookup the chart configuration
- my $session_id = 'chart_' . $1;
-
- # 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';
+my %classes = (
+ chart => 'Chart::$TYPE',
+ gd_graph => 'GD::Graph::$TYPE',
+ xmlswf => 'XML::Simple',
+);
- # 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);
+=head1 RULES
- # Use the "type" to determine which class to use
- my $class = 'Chart::' . $args->{type};
+=head2 chart/*/*
- # Load that class or die if it does not exist
- $class->require;
+Grabs the chart configuration stored in the key indicated in C<$1> and unpacks it using L<YAML>. It then passes it to the correct L<Jifty::Plugin::Chart::View> template.
- # Remember the class name for the view
- $args->{class} = $class;
-
- # Send them on to chart the chart
- set 'args' => $args;
- show 'chart/chart'
-};
-
-=head2 chart/gd_graph/*
+=cut
-Grabs the chart configuration stored in the key indicated in C<$1> and unpacks it using L<YAML>. It then passes it to the L<Jifty::Plugin::Chart::View/chart> template.
+on 'chart/*/*' => run {
+ my $renderer = $1;
-=cut
+ # No renderer? Act like a 404.
+ last_rule if not defined $classes{$renderer};
-on 'chart/gd_graph/*' => run {
# Create a session ID to lookup the chart configuration
- my $session_id = 'chart_' . $1;
+ 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 lots of charts, this could asplode
+ # XXX if there are a lot of charts, this could asplode
#Jifty->web->session->remove( $session_id );
# No data? Act like a 404
@@ -86,8 +55,14 @@
($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;
+
+ my $class = $classes{$renderer};
+
# Use the "type" to determine which class to use
- my $class = 'GD::Graph::' . $args->{type};
+ $class =~ s/\$TYPE/$args->{type}/g;
# Load that class or die if it does not exist
$class->require;
@@ -97,7 +72,7 @@
# Send them on to chart the chart
set 'args' => $args;
- show 'chart/gd_graph'
+ show "chart/$renderer";
};
=head1 SEE ALSO
Modified: jifty/branches/virtual-models/lib/Jifty/Plugin/Chart/Renderer.pm
==============================================================================
--- jifty/branches/virtual-models/lib/Jifty/Plugin/Chart/Renderer.pm (original)
+++ jifty/branches/virtual-models/lib/Jifty/Plugin/Chart/Renderer.pm Thu Aug 9 17:41:06 2007
@@ -50,7 +50,7 @@
sub new {
my $class = shift;
my $self = bless {}, $class;
- $self->init;
+ $self->init( @_ );
return $self;
}
@@ -58,7 +58,7 @@
$renderer->init();
-This is called by C<new> immediately after constructing the object. Subclasses should implement this method to do any required initialization such as letting Jifty know about required CSS files, JS files, etc.
+This is called by C<new> immediately after constructing the object. It is passed a param hash from the config file. Subclasses should implement this method to do any required initialization such as letting Jifty know about required CSS files, JS files, etc.
=cut
Modified: jifty/branches/virtual-models/lib/Jifty/Plugin/Chart/Renderer/PlotKit.pm
==============================================================================
--- jifty/branches/virtual-models/lib/Jifty/Plugin/Chart/Renderer/PlotKit.pm (original)
+++ jifty/branches/virtual-models/lib/Jifty/Plugin/Chart/Renderer/PlotKit.pm Thu Aug 9 17:41:06 2007
@@ -43,36 +43,47 @@
my $self = shift;
my %args = ( options => {}, @_ );
- # Turn any subs into values returned
- for my $key (keys %args) {
- $args{$key} = $args{$key}->(\%args) if ref $args{$key} eq 'CODE';
- }
-
+ # translations from generic type to PlotKit types
my %types = (
lines => { type => 'line' },
- bars => { type => 'bar', orientation => 'vertical' },
+ bars => { type => 'bar', barOrientation => 'vertical' },
pie => { type => 'pie' },
- horizontalbars => { type => 'bar', orientation => 'horizontal' },
+ horizontalbars => { type => 'bar', barOrientation => 'horizontal' },
);
+ # save it for error reporting
+ my $orig_type = $args{type};
+
# Make sure the type is ready to be used
my $options = $types{ $args{type} } || {};
- $args{type} = delete $options{type};
- $args{options}{$_} = $options{$_} foreach keys %$options;
+ $args{type} = delete $options->{type};
+ $args{options}{$_} = $options->{$_} foreach keys %$options;
+ # Bad stuff, not a supported type
if ( not defined $args{type} ) {
- Jifty->log->warn("Unsupported chart type: $args{type}!");
+ Jifty->log->warn("Unsupported chart type: $orig_type!");
return;
}
+ # Kill the "px" unit
+ $args{width} =~ s/px$//;
+ $args{height} =~ s/px$//;
+
$self->_transform_data( \%args );
# Save the data for retrieval from the session later
my $chart_id = 'chart_' . Jifty->web->serial;
# Output the <canvas> tag and include the chart's JS
+ my $div;
+ $div = qq{<div id="$chart_id"};
+ $div .= qq{ class="@{[ join ' ', @{ $args{class} } ]}"};
+ $div .= qq{ height="$args{height}"} if $args{height};
+ $div .= qq{ width="$args{width}"} if $args{width};
+ $div .= qq{></div>};
+
Jifty->web->out(<<" END_OF_HTML");
-<div id="$chart_id" height="$args{height}" width="$args{width}"></div>
+$div
<script type="text/javascript">
var plot = function() {
@@ -83,7 +94,7 @@
@{[Jifty::JSON::objToJson( $args{data} )]}
);
};
-YAHOO.util.Event.addListener( window, "load", plot );
+YAHOO.util.Event.onAvailable( "$chart_id", plot );
</script>
END_OF_HTML
Added: jifty/branches/virtual-models/lib/Jifty/Plugin/Chart/Renderer/SimpleBars.pm
==============================================================================
--- (empty file)
+++ jifty/branches/virtual-models/lib/Jifty/Plugin/Chart/Renderer/SimpleBars.pm Thu Aug 9 17:41:06 2007
@@ -0,0 +1,109 @@
+use strict;
+use warnings;
+
+package Jifty::Plugin::Chart::Renderer::SimpleBars;
+use base qw/ Jifty::Plugin::Chart::Renderer /;
+
+=head1 NAME
+
+Jifty::Plugin::Chart::Renderer::SimpleBars - a simple horizontal bar chart
+
+=head1 DESCRIPTION
+
+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.
+
+=head1 OPTIONS
+
+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".
+
+It takes the following options:
+
+=over
+
+=item summary
+
+To maximize the accessibility of your chart, set this to describe the data. This will set the table's summary attribute.
+
+=back
+
+=head1 STYLING
+
+Please be aware that when using this object, you must add background color to the application CSS file to see the bars.
+
+ div.simple_bars span.bar {
+ background-color: black;
+ }
+
+=head1 METHODS
+
+=head2 init
+
+Tell Jifty about the CSS and JS files SimpleBars needs.
+
+=cut
+
+sub init {
+ Jifty->web->add_javascript('simple_bars.js');
+ Jifty->web->add_css('simple_bars.css');
+}
+
+=head2 render
+
+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>.
+
+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.
+
+=cut
+
+sub render {
+ my $self = shift;
+ my %args = @_;
+
+ # We only handle horizontalbars, fail on all else
+ if ($args{type} ne 'horizontalbars') {
+ die 'Sorry, SimpleBars charts only handle horizontalbars chart types.';
+ }
+
+ # Create a fresh ID for the chart
+ my $chart_id = 'chart_' . Jifty->web->serial;
+
+ # Add the simple_bars class for the JavaScript to find
+ push @{ $args{class} }, 'simple_bars';
+
+ # Build the table
+ my $table;
+ $table = qq{<table id="$chart_id"};
+ $table .= qq{ class="@{[ join ' ', @{ $args{class} } ]}"};
+ $table .= qq{ summary="$args{summary}"} if $args{summary};
+ $table .= qq{/><tbody>};
+
+ for my $index (0 .. $#{ $args{data}[0] }) {
+ my $label = $args{data}[0][$index];
+ my $point = $args{data}[1][$index];
+
+ $table .= '<tr>';
+ $table .= "<td>@{[ Jifty->web->escape($label) ]}</td>";
+ $table .= "<td>@{[ Jifty->web->escape($point) ]}</td>";
+ $table .= '</tr>';
+ }
+
+ $table .= '</tbody></table>';
+
+ Jifty->web->out($table);
+
+ return;
+}
+
+=head1 AUTHOR
+
+Andrew Sterling Hanenkamp, C<< <andrew.hanenkamp at boomer.com> >>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2007 Boomer Consulting, Inc.
+
+This is free software. You may modify and redistribute it under the same terms as Perl itself.
+
+=cut
+
+1
Added: jifty/branches/virtual-models/lib/Jifty/Plugin/Chart/Renderer/XMLSWF.pm
==============================================================================
--- (empty file)
+++ jifty/branches/virtual-models/lib/Jifty/Plugin/Chart/Renderer/XMLSWF.pm Thu Aug 9 17:41:06 2007
@@ -0,0 +1,156 @@
+use strict;
+use warnings;
+
+package Jifty::Plugin::Chart::Renderer::XMLSWF;
+use base qw/ Jifty::Plugin::Chart::Renderer /;
+
+use Jifty::YAML;
+
+=head1 NAME
+
+Jifty::Plugin::Chart::Renderer::XMLSWF - A chart renderer using XML SWF charts
+
+=head1 DESCRIPTION
+
+This chart renderer uses the XML SWF charting tools to render charts.
+
+ Plugins:
+ - Chart:
+ renderer: XMLSWF
+ license_key: YOUR_OPTIONAL_LICENSE_KEY
+
+=head1 METHODS
+
+=head2 init
+
+Save the license key, if any
+
+=cut
+
+our $LICENSE = "";
+
+sub init {
+ my $self = shift;
+ my %args = ( @_ );
+
+ if ( defined $args{license_key} ) {
+ $LICENSE = $args{license_key};
+ }
+}
+
+=head2 render
+
+Implemented the L<Jifty::Plugin::Chart::Renderer/render> method interface.
+
+=cut
+
+sub render {
+ my $self = shift;
+ my %args = (
+ bgcolor => '#ffffff',
+ wmode => 'transparent',
+ @_
+ );
+
+ # Conversion from generic types to XML SWF types -- incomplete
+ my %types = (
+ 'bars' => 'column',
+ 'stackedbars' => 'stacked column',
+ 'horizontalbars' => 'bar',
+ 'lines' => 'line',
+ 'pie' => '3d pie',
+ 'points' => 'scatter',
+ );
+
+ # Make sure the type is ready to be used
+ $args{type} = $types{ $args{type} } || undef;
+
+ # Kill the "px" unit
+ $args{width} =~ s/px$//;
+ $args{height} =~ s/px$//;
+
+ # 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 $src = '/static/flash/xmlswf/charts.swf?';
+
+ my $query = Jifty->web->query_string(
+ library_path => '/static/flash/xmlswf/charts_library',
+ xml_source => "/chart/xmlswf/$chart_id",
+ license => $LICENSE
+ );
+ $query =~ s/;/&/g;
+ $src .= $query;
+
+ my $tags = {
+ embed => {
+ src => $src,
+ quality => 'high',
+ bgcolor => $args{bgcolor},
+ width => $args{width},
+ height => $args{height},
+ name => $session_id,
+ wmode => $args{wmode},
+ type => 'application/x-shockwave-flash',
+ swLiveConnect => 'true',
+ pluginspage => 'http://www.macromedia.com/go/getflashplayer',
+ },
+ object => {
+ classid => 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000',
+ codebase => 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0',
+ width => $args{width},
+ height => $args{height},
+ id => $session_id,
+ class => join( ' ', @{$args{class}} ),
+ },
+ params => {
+ movie => $src,
+ quality => 'high',
+ bgcolor => $args{bgcolor},
+ wmode => $args{wmode},
+ },
+ };
+
+ my $html = "<div>\n";
+ $html .= "<object";
+ $html .= qq[ $_="@{[$tags->{object}{$_}]}"]
+ for keys %{ $tags->{object} };
+ $html .= ">\n";
+
+ $html .= qq[<param name="$_" value="@{[$tags->{params}{$_}]}" />\n] # /damn vim
+ for keys %{ $tags->{params} };
+
+ $html .= "<embed";
+ $html .= qq[ $_="@{[$tags->{embed}{$_}]}"]
+ for keys %{ $tags->{embed} };
+ $html .= "></embed>\n";
+ $html .= "</object>\n";
+ $html .= "</div>\n";
+
+ # Output the HTML and include the chart's configuration key
+ Jifty->web->out($html);
+
+ # Make sure we don't return anything that will get output
+ return;
+}
+
+=head1 SEE ALSO
+
+L<Jifty::Plugin::Chart>, L<Jifty::Plugin::Chart::Renderer>
+
+=head1 AUTHOR
+
+Thomas Sibley
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2007 Best Practical Solutions, LLC
+
+This is free software and may be modified and distributed under the same terms as Perl itself.
+
+=cut
+
+1;
Modified: jifty/branches/virtual-models/lib/Jifty/Plugin/Chart/View.pm
==============================================================================
--- jifty/branches/virtual-models/lib/Jifty/Plugin/Chart/View.pm (original)
+++ jifty/branches/virtual-models/lib/Jifty/Plugin/Chart/View.pm Thu Aug 9 17:41:06 2007
@@ -28,6 +28,7 @@
# Render the chart and output the PNG file generated
eval {
my $chart = $args->{class}->new( $args->{width}, $args->{height} );
+ $chart->set(%{ $args->{options} }) if $args->{options};
# XXX scalar_png() is undocumented!!! Might bad to rely upon.
outs_raw($chart->scalar_png($args->{data}));
};
@@ -57,6 +58,7 @@
# Render the chart and output the PNG file generated
eval {
my $graph = $args->{class}->new( $args->{width}, $args->{height} );
+ $graph->set(%{ $args->{options} }) if $args->{options};
my $gd = $graph->plot($args->{data})
or die $graph->error;
outs_raw($gd->png);
@@ -69,6 +71,56 @@
}
};
+=head2 chart/xmlswf
+
+This shows a chart using XML SWF. It expects to find the arguments in the C<args> parameter, which is setup for it in L<Jifty::Plugin::Chart::Dispatcher>.
+
+This will output an XML source file unless there is an error building the chart.
+
+=cut
+
+template 'chart/xmlswf' => sub {
+ # Load the arguments
+ my $args = get 'args';
+
+ # Set the output type to the XML file type
+ Jifty->handler->apache->content_type('application/xml');
+
+ # The KeyAttr thing is a bloody hack to get ordering right
+ my $xml = $args->{class}->new(
+ RootName => 'chart',
+ KeyAttr => { row => '+string' }
+ );
+
+ my $labels = shift @{ $args->{data} };
+
+ # Base chart options
+ my %chart = (
+ chart_type => { content => $args->{type} },
+ axis_category => { size => '11', color => '808080' },
+ axis_value => { size => '11', color => '808080' },
+ axis_ticks => { major_color => '808080' },
+ legend_label => { size => '11' },
+ chart_value => { position => 'cursor', size => '11', color => '666666' },
+ %{ $args->{options} },
+ chart_data => {
+ row => [
+ {
+ string => [ {}, @$labels ],
+ },
+ ],
+ },
+ );
+
+ for my $i ( 0 .. $#{ $args->{data} } ) {
+ push @{$chart{'chart_data'}{'row'}}, {
+ string => [ $args->{legend}[$i] || {} ],
+ number => $args->{data}[$i],
+ };
+ }
+
+ outs_raw( $xml->XMLout( \%chart ) );
+};
=head1 SEE ALSO
L<Jifty::Plugin::Chart::Dispatcher>
Modified: jifty/branches/virtual-models/lib/Jifty/View/Declare/CRUD.pm
==============================================================================
--- jifty/branches/virtual-models/lib/Jifty/View/Declare/CRUD.pm (original)
+++ jifty/branches/virtual-models/lib/Jifty/View/Declare/CRUD.pm Thu Aug 9 17:41:06 2007
@@ -191,7 +191,9 @@
=cut
template 'view' => sub :CRUDView {
- my ($self, $record) = @_;
+ my $self = shift;
+ my $record = $self->_get_record( get('id') );
+
my $update = new_action(
class => 'Update' . $self->object_type,
moniker => "update-" . Jifty->web->serial,
Added: jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/css/simple_bars.css
==============================================================================
--- (empty file)
+++ jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/css/simple_bars.css Thu Aug 9 17:41:06 2007
@@ -0,0 +1,31 @@
+div.simple_bars div.row {
+ position: relative;
+ padding: 3px 1%;
+ width: 100%;
+ overflow: auto;
+}
+
+div.simple_bars div.row span.label {
+ display: block;
+ float: left;
+ width: 30%;
+ overflow: hidden;
+}
+
+div.simple_bars div.row span.barArea {
+ display: block;
+ float: left;
+ width: 60%;
+ overflow: hidden;
+}
+
+div.simple_bars div.row span.barArea span.bar {
+ display: block;
+}
+
+div.simple_bars div.row span.value {
+ display: block;
+ float: left;
+ width: 8%;
+ text-align: right;
+}
Added: jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts.swf
==============================================================================
Binary file. No diff available.
Added: jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/arno.swf
==============================================================================
Binary file. No diff available.
Added: jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/arst.swf
==============================================================================
Binary file. No diff available.
Added: jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/brfl.swf
==============================================================================
Binary file. No diff available.
Added: jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/brno.swf
==============================================================================
Binary file. No diff available.
Added: jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/brst.swf
==============================================================================
Binary file. No diff available.
Added: jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/cl3d.swf
==============================================================================
Binary file. No diff available.
Added: jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/clfl.swf
==============================================================================
Binary file. No diff available.
Added: jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/clno.swf
==============================================================================
Binary file. No diff available.
Added: jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/clp3.swf
==============================================================================
Binary file. No diff available.
Added: jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/cls3.swf
==============================================================================
Binary file. No diff available.
Added: jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/clst.swf
==============================================================================
Binary file. No diff available.
Added: jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/cnno.swf
==============================================================================
Binary file. No diff available.
Added: jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/lnno.swf
==============================================================================
Binary file. No diff available.
Added: jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/mxno.swf
==============================================================================
Binary file. No diff available.
Added: jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/pi3d.swf
==============================================================================
Binary file. No diff available.
Added: jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/pino.swf
==============================================================================
Binary file. No diff available.
Added: jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/pono.swf
==============================================================================
Binary file. No diff available.
Added: jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/flash/xmlswf/charts_library/scno.swf
==============================================================================
Binary file. No diff available.
Modified: jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/js/PlotKit/PlotKit_Packed-20060807-custom.js
==============================================================================
--- jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/js/PlotKit/PlotKit_Packed-20060807-custom.js (original)
+++ jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/js/PlotKit/PlotKit_Packed-20060807-custom.js Thu Aug 9 17:41:06 2007
@@ -590,7 +590,7 @@
var _118=MochiKit.Base.itemgetter;
var _119=_116(this.datasets).length;
var _120=_116(this.datasets)[0][1];
-var _121=sum(map(_118(1),_120));
+var _121=sum(PlotKit.Base.map(_118(1),_120));
this.slices=new Array();
var _122=0;
for(var i=0;i<_120.length;i++){
@@ -680,7 +680,7 @@
var _142=function(tick){
return [tick[0]+(this.minxdelta*this.xscale)/2,tick[1]];
};
-this.xticks=MochiKit.Base.map(MochiKit.Base.bind(_142,this),this.xticks);
+this.xticks=PlotKit.Base.map(MochiKit.Base.bind(_142,this),this.xticks);
if(this.options.barOrientation=="horizontal"){
var _143=this.xticks;
this.xticks=this.yticks;
@@ -688,7 +688,7 @@
var _144=function(tick){
return [1-tick[0],tick[1]];
};
-this.xticks=MochiKit.Base.map(_144,this.xticks);
+this.xticks=PlotKit.Base.map(_144,this.xticks);
}
};
PlotKit.Layout.prototype._evaluatePieTicks=function(){
Added: jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/js/simple_bars.js
==============================================================================
--- (empty file)
+++ jifty/branches/virtual-models/share/plugins/Jifty/Plugin/Chart/web/static/js/simple_bars.js Thu Aug 9 17:41:06 2007
@@ -0,0 +1,69 @@
+/*
+ * $Id$
+ * simple_bars.js
+ * by Andrew Sterling Hanenkamp
+ *
+ * Copyright 2007 Boomer Consulting, Inc.
+ *
+ * A custom and extremely simple way of rendering a horizontal bar chart. This
+ * code was custom built for use with Jifty, but could be reused elsewhere.
+ *
+ * This is free software. You may modify or redistribute this code under the
+ * terms of the GNU General Public License or the Artistic license.
+ */
+
+function SimpleBars(table) {
+ var dataset = $H();
+
+ for (var i = 0; i < table.tBodies[0].rows.length; i++) {
+ var table_row = table.tBodies[0].rows[i];
+ dataset[table_row.cells[0].innerHTML] = table_row.cells[1].innerHTML;
+ }
+
+ var max_value = 0;
+ dataset.values().each(function(v,i){max_value=Math.max(max_value, v);});
+
+ var simple_bars = document.createElement('div');
+ simple_bars.id = table.id;
+ simple_bars.className = table.className;
+
+ dataset.keys().each(function(k, i) {
+ var v = dataset[k];
+
+ var row = document.createElement('div');
+ row.className = 'row';
+
+ var row_label = document.createElement('span');
+ row_label.className = 'label';
+ row_label.innerHTML = k;
+ row.appendChild(row_label);
+
+ var row_bar_area = document.createElement('span');
+ row_bar_area.className = 'barArea';
+ row.appendChild(row_bar_area);
+
+ var row_bar = document.createElement('span');
+ row_bar.className = 'bar';
+ row_bar.style.width = Math.round( 100 * v / max_value ) + '%';
+ row_bar.innerHTML = ' ';
+ row_bar_area.appendChild(row_bar);
+
+ var row_value = document.createElement('span');
+ row_value.className = 'value';
+ row_value.innerHTML = v;
+ row.appendChild(row_value);
+
+ simple_bars.appendChild(row);
+ });
+
+ table.parentNode.insertBefore(simple_bars, table);
+ table.parentNode.removeChild(table);
+
+ return this;
+}
+
+Behaviour.register({
+ 'table.simple_bars': function(table) {
+ new SimpleBars(table);
+ }
+});
Modified: jifty/branches/virtual-models/share/web/static/js/jifty.js
==============================================================================
--- jifty/branches/virtual-models/share/web/static/js/jifty.js (original)
+++ jifty/branches/virtual-models/share/web/static/js/jifty.js Thu Aug 9 17:41:06 2007
@@ -719,7 +719,7 @@
}
},
'.form_field .error, .form_field .warning, .form_field .canonicalization_note': function(e) {
- Element.hide(e);
+ if ( e.innerHTML == "" ) Element.hide(e);
}
});
More information about the Jifty-commit
mailing list