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

Jifty commits jifty-commit at lists.jifty.org
Thu Aug 14 22:19:07 EDT 2008


Author: trs
Date: Thu Aug 14 22:19:06 2008
New Revision: 5725

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

Log:
 r39241 at zot:  tom | 2008-08-14 22:16:42 -0400
 Support range markers and actually calculate the position with the chart range correctly for all markers


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	Thu Aug 14 22:19:06 2008
@@ -273,7 +273,7 @@
         $url .= "&chbh=" . join ',', @{ $args{'bar_width'} };
     }
 
-    # Add shape markers
+    # Add shape/range markers
     if ( @{ $args{'markers'} } ) {
         my @markers;
         for my $data ( @{$args{'markers'}} ) {
@@ -289,15 +289,34 @@
 
             # Calculate where the position should be for horizontal lines
             if ( $marker{'type'} eq 'h' ) {
-                $marker{'position'} /= abs( $args{'calculated_max'} - $args{'calculated_min'} );
+                $marker{'position'} = $self->_position_in_range( $marker{'position'},
+                                                                 $args{'calculated_min'},
+                                                                 $args{'calculated_max'} );
+            }
+            # Calculate where the position should be for ranges
+            elsif ( lc($marker{'type'}) eq 'r' ) {
+                for (qw( start end )) {
+                    $marker{$_} = $args{'calculated_min'} if $marker{$_} eq 'MIN';
+                    $marker{$_} = $args{'calculated_max'} if $marker{$_} eq 'MAX';
+
+                    $marker{$_} = $self->_position_in_range( $marker{$_},
+                                                             $args{'calculated_min'},
+                                                             $args{'calculated_max'} );
+                }
             }
             # Fix text type
             elsif ( $marker{'type'} eq 't' ) {
                 $marker{'type'} .= uri_escape( $marker{'text'} );
             }
 
-            # Format the position
-            $marker{'position'} = sprintf $args{'format'}, $marker{'position'};
+            if ( lc($marker{'type'}) eq 'r' ) {
+                $marker{'position'} = sprintf $args{'format'}, $marker{'start'};
+                $marker{'size'}     = sprintf $args{'format'}, $marker{'end'};
+            }
+            else {
+                # Format the position
+                $marker{'position'} = sprintf $args{'format'}, $marker{'position'};
+            }
 
             push @markers, join(',', @marker{qw( type color dataset position size priority )});
         }
@@ -310,6 +329,11 @@
     return;
 }
 
+sub _position_in_range {
+    my ( $self, $point, $min, $max ) = @_;
+    return ($point - $min) / ($max - $min);
+}
+
 # Borrowed with slight modifications from Google::Chart::Data::SimpleEncoding
 sub _simple_encode_data {
     my $self = shift;


More information about the Jifty-commit mailing list