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

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Sat Aug 4 18:30:53 EDT 2007


Author: sterling
Date: Sat Aug  4 18:30:52 2007
New Revision: 3787

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty/Plugin/Chart/Renderer/Chart.pm
   jifty/trunk/lib/Jifty/Plugin/Chart/Renderer/GD/Graph.pm
   jifty/trunk/lib/Jifty/Plugin/Chart/Renderer/PlotKit.pm
   jifty/trunk/lib/Jifty/Plugin/Chart/Web.pm

Log:
 r8351 at dynpc145:  andrew | 2007-08-04 16:13:23 -0500
 Standardizing the chart types across the three current renderers.


Modified: jifty/trunk/lib/Jifty/Plugin/Chart/Renderer/Chart.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/Chart/Renderer/Chart.pm	(original)
+++ jifty/trunk/lib/Jifty/Plugin/Chart/Renderer/Chart.pm	Sat Aug  4 18:30:52 2007
@@ -36,8 +36,25 @@
     my $self = shift;
     my %args = @_;
 
-    # Make sure the type is ready to be used as a class name
-    $args{type} = ucfirst lc $args{type};
+    # Conversion from generic types to Chart types
+    my %types = (
+        'bars'           => 'Bars',
+        'composite'      => 'Composite', # non-standard
+        'direction'      => 'Direction', # non-standard
+        'errorbars'      => 'ErrorBars', # non-standard
+        'horizontalbars' => 'HorizontalBars',
+        'lines'          => 'Lines',
+        'linespoints'    => 'LinesPoints',
+        'mountain'       => 'Mountain',  # non-standard
+        'pareto'         => 'Pareto',    # non-standard
+        'pie'            => 'Pie',
+        'points'         => 'Points',
+        'split'          => 'Split',     # non-standard
+        'stackedbars'    => 'StackedBars',
+    );
+
+    # Make sure the type is ready to be used as a Chart class name
+    $args{type} = $types{ $args{type} } || undef;
 
     # Save the data for retrieval from the session later
     my $chart_id   = Jifty->web->serial;

Modified: jifty/trunk/lib/Jifty/Plugin/Chart/Renderer/GD/Graph.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/Chart/Renderer/GD/Graph.pm	(original)
+++ jifty/trunk/lib/Jifty/Plugin/Chart/Renderer/GD/Graph.pm	Sat Aug  4 18:30:52 2007
@@ -42,8 +42,20 @@
     my $self = shift;
     my %args = @_;
 
-    # Convert the type to lowercase
-    $args{type} = lc $args{type};
+    # 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;

Modified: jifty/trunk/lib/Jifty/Plugin/Chart/Renderer/PlotKit.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/Chart/Renderer/PlotKit.pm	(original)
+++ jifty/trunk/lib/Jifty/Plugin/Chart/Renderer/PlotKit.pm	Sat Aug  4 18:30:52 2007
@@ -49,13 +49,16 @@
     }
 
     my %types = (
-        Lines   => 'line',
-        Bars    => 'bar',
-        Pie     => 'pie',
+        lines          => { type => 'line' },
+        bars           => { type => 'bar', orientation => 'vertical' },
+        pie            => { type => 'pie' },
+        horizontalbars => { type => 'bar', orientation => 'horizontal' },
     );
 
     # Make sure the type is ready to be used
-    $args{type} = $types{ ucfirst lc $args{type} } || undef;
+    my $options = $types{ $args{type} } || {};
+    $args{type} = delete $options{type};
+    $args{options}{$_} = $options{$_} foreach keys %$options;
 
     if ( not defined $args{type} ) {
         Jifty->log->warn("Unsupported chart type: $args{type}!");

Modified: jifty/trunk/lib/Jifty/Plugin/Chart/Web.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/Chart/Web.pm	(original)
+++ jifty/trunk/lib/Jifty/Plugin/Chart/Web.pm	Sat Aug  4 18:30:52 2007
@@ -25,34 +25,38 @@
 
 =item type
 
-This will be one of the following scalar values indicating the kind of chart:
+This will be one of the following scalar values indicating the kind of chart. A given renderer may not support every type listed here. A renderer might support others in addition to these, but if it supports these it should use these names.
 
 =over
 
-=item Points
+=item points
 
 This is the default value. A scatter plot with each dataset represented using differnet dot styles.
 
-=item Lines
+=item lines
 
 A line plot with each dataset presented as separate line.
 
-=item Bars
+=item bars
 
 A bar chart with each dataset set side-by-side.
 
-=item StackedBars
+=item stackedbars
 
 A bar chart with each dataset stacked on top of each other.
 
-=item Pie
+=item pie
 
 A pie chart with a single dataset representing the values for different pieces of the pie.
 
-=item HorizontalBars
+=item horizontalbars
 
 A bar chart turned sideways.
 
+=item area
+
+An area chart uses lines to represent each dataset, but the lines are stacked on top of each other with filled areas underneath.
+
 =back
 
 =item width
@@ -81,6 +85,10 @@
 
 This allows you to use a different renderer than the one configured in F<config.yml>. Give the renderer as a class name, which will be initialized for you.
 
+=item options
+
+This is a hash containing additional options to pass to the renderer and are renderer specific. This may include anything that is not otherwise set by one of the other options above.
+
 =back
 
 Here's an example:
@@ -125,6 +133,9 @@
     $args{width}  .= 'px' if looks_like_number($args{width});
     $args{height} .= 'px' if looks_like_number($args{height});
 
+    # canonicalize the type argument (always lowercase)
+    $args{type} = lc $args{type};
+
     # canonicalize the class argument
     if (not ref $args{class}) {
         $args{class} = defined $args{class} ? [ $args{class} ] : [];


More information about the Jifty-commit mailing list