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

Jifty commits jifty-commit at lists.jifty.org
Fri Jul 25 11:22:38 EDT 2008


Author: trs
Date: Fri Jul 25 11:22:32 2008
New Revision: 5580

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

Log:
 r37967 at zot:  tom | 2008-07-25 11:14:12 -0400
 * Format data values to not waste URL and domain/range space
 * Support setting range labels


Modified: jifty/trunk/lib/Jifty/Plugin/Chart/Renderer/Google.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/Chart/Renderer/Google.pm	(original)
+++ jifty/trunk/lib/Jifty/Plugin/Chart/Renderer/Google.pm	Fri Jul 25 11:22:32 2008
@@ -33,6 +33,7 @@
         geoarea   => 'world',
         min_minus => 0,
         max_plus  => 0,
+        format    => '%0.1f',
         @_
     );
 
@@ -140,9 +141,20 @@
     # Add the type
     $url .= "cht=$type";
 
-    # Add the width - XXX TODO: we don't validate these yet
+    # Add the width
     $url .= "&chs=$args{'width'}x$args{'height'}";
 
+    # Format the data
+    unless ( not defined $args{'format'} ) {
+        for my $set ( @{$args{'data'}} ) {
+            @$set = map {
+                        looks_like_number($_)
+                            ? sprintf $args{'format'}, $_
+                            : $_
+                    } @$set;
+        }
+    }
+
     # Add the data (encoding it first)
     if ( $type eq 't' ) {
         # Map!
@@ -165,6 +177,14 @@
         my $min = $args{'min_value'} - $args{'min_minus'};
         my $max = $args{'max_value'} + $args{'max_plus'};
 
+        unless ( not defined $args{'format'} ) {
+            $min = sprintf $args{'format'}, $min;
+            $max = sprintf $args{'format'}, $max;
+        }
+
+        $args{'calculated_min'} = $min;
+        $args{'calculated_max'} = $max;
+
         # If it's a number, pass it through, otherwise replace it with a
         # number out of range to mark it as undefined
         my @data;
@@ -189,15 +209,23 @@
     # Add any axes
     if ( $args{'axes'} ) {
         $url .= "&chxt=" . $args{'axes'};
-        
-        my $labels;
-        my $index = 0;
-        for my $labelset ( @{ $args{'labels'} } ) {
-            $labels .= "$index:|" . join '|', map { uri_escape($_) } @$labelset
-                if @$labelset;
-            $index++;
+
+        if ( defined $args{'labels'} ) {
+            my @labels;
+            my @ranges;
+            my $index = 0;
+            for my $labelset ( @{ $args{'labels'} } ) {
+                if ( ref $labelset eq 'ARRAY' and @$labelset ) {
+                    push @labels, "$index:|" . join '|', map { uri_escape($_) } @$labelset;
+                }
+                elsif ( not ref $labelset and $labelset eq 'RANGE' ) {
+                    push @ranges, "$index,$args{'calculated_min'},$args{'calculated_max'}";
+                }
+                $index++;
+            }
+            $url .= "&chxl=" . join '|', @labels if @labels;
+            $url .= "&chxr=" . join '|', @ranges if @ranges;
         }
-        $url .= "&chxl=$labels" if defined $labels;
     }
 
     # Add colors


More information about the Jifty-commit mailing list