Skip Menu |

This queue is for tickets about the WebService-Simple-Google-Chart CPAN distribution.

Report information
The Basics
Id: 42108
Status: new
Priority: 0/
Queue: WebService-Simple-Google-Chart

People
Owner: Nobody in particular
Requestors: michael [...] thegrebs.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: (no value)
Fixed in: (no value)



Subject: [PATCH] Multiple Fixes and Improvements
The attached patch provides a couple of bugfixes as well as enhancements against WebService::Simple::Google::Chart version 0.04. The enhancements support sending the labels correctly for map and spark line charts and allowing passing the data and labels as an arrayref in addition to the current hashref method. This allows preserving the order of the fields, necessary for line charts and spark line charts. Lastly, a bugfix. The encoded values for the text encoded method are meant to be percentage of the maximum value not percentage of the total value as the module provides without this patch. This is not noticeable on pie charts or line/bar charts but is very noticeable on the map charts. A sample of graphs produced with this module with the patch applied are available at <http://thegrebs.com/spam/>. The map and encoding sections of the patch were included in a patch I emailed to you directly some months back. If you don't have the time to keep up with the module I would be interested in co-maintainer status for the module so that I could upload a new release with this patch plus a docs patch I'm working on. Mike
Subject: 0001-Encode-values-as-of-max-not-of-total-as-specifie.patch
From a497183b36c90da73a46a022e19448606e0a4aa9 Mon Sep 17 00:00:00 2001 From: Michael Greb <mgreb@linode.com> Date: Fri, 2 Jan 2009 15:17:24 -0500 Subject: [PATCH] Encode values as % of max not % of total as specified in API docs. Support map chart types Support spark line chart types Allow labels and values to be passed as array refs to preserve ordering --- lib/WebService/Simple/Google/Chart.pm | 31 ++++++++++++++++++++++--------- 1 files changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/WebService/Simple/Google/Chart.pm b/lib/WebService/Simple/Google/Chart.pm index b10ceaf..c712953 100644 --- a/lib/WebService/Simple/Google/Chart.pm +++ b/lib/WebService/Simple/Google/Chart.pm @@ -28,16 +28,29 @@ sub render_to_file { sub _set_data_param { my ($self, $data) = @_; - my ( @label, @value, $total_count ); - $total_count = 0; - map { $total_count += $data->{$_} } keys %$data; - foreach my $key ( keys %$data ) { - push( @label, $key ); - my $percent = int( $data->{$key} / $total_count * 100 + 0.5 ); - push( @value, $percent ); + my ( @label, @value ); + + my $max = 0; + if (ref($data) eq 'HASH') { + map { $max = $data->{$_} > $max ? $data->{$_} : $max } keys %$data; + foreach my $key ( keys %$data ) { + push( @label, $key ); + push( @value, sprintf("%.1f", $data->{$key} / $max * 100) ); + } + my $data_param = {}; + } else { + map { $max = $_ > $max ? $_ : $max } @{$data->[1]}; + @label = @{$data->[0]}; + @value = map { sprintf("%.1f", $_ / $max * 100) } @{$data->[1]}; + } + + if ($self->{request_param}{cht} ne 'ls') { + if ($self->{request_param}{cht} ne 't') { + $self->{request_param}->{chl} = join( "|", @label ); + } else { + $self->{request_param}->{chld} = join( "", @label ); + } } - my $data_param = {}; - $self->{request_param}->{chl} = join( "|", @label ); $self->{request_param}->{chd} = "t:" . join( ",", @value ); } -- 1.6.0.5