Changeset 16838

Show
Ignore:
Timestamp:
07/30/08 10:53:50 (5 years ago)
Author:
daisuke
Message:

apply moose branch to trunk

Location:
lang/perl/Google-Chart/trunk
Files:
38 added
19 removed
13 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Google-Chart/trunk/Changes

    r12762 r16838  
    1 --- 
    2 global: 
    3   name: Google-Chart 
    4 releases: 
    5   - author: 'Marcel Gruenauer <marcel@cpan.org>' 
    6     changes: 
    7       - set the version to 0.04 
    8       - '.shipit: fixed svk.tagpattern for CodeRepos' 
    9       - 'Makefile.PL: requires Test::Differences' 
    10       - 'Google::Chart::Data: made as_string() more generic' 
    11       - 'Google::Chart::Data::SimpleEncoding: uses new inherited as_string()' 
    12       - "Google::Chart::Factory: enabled mapping for 'data_extended_encoding' object type" 
    13       - 't/01_basic.t: uses Test::Differences' 
    14       - added lib/Google/Chart/Data/ExtendedEncoding.pm 
    15       - added t/02_extended_encoding.t 
    16       - updated MANIFEST 
    17       - updated MANIFEST 
    18       - '.shipit: fixed svk.tagpattern' 
    19     date: 2008-05-29T12:05:17Z 
    20     tags: [] 
    21     version: 0.04 
    22   - author: 'Marcel Gruenauer <marcel@cpan.org>' 
    23     changes: 
    24       - set the version to 0.03 
    25       - 'exposed user agent in Google::Chart so you can overlay it, e.g., for using a proxy' 
    26     date: 2007-12-24T14:34:55Z 
    27     tags: [] 
    28     version: 0.03 
    29   - author: 'Marcel Gruenauer <marcel@cpan.org>' 
    30     changes: 
    31       - set the version to 0.02 
    32       - moved things around (API is still fluid) 
    33       - added basic color support 
    34       - added more chart types 
    35       - added lib/Google/Chart/Type/Bar 
    36       - added lib/Google/Chart/Type/Bar.pm 
    37       - added lib/Google/Chart/Type/Line 
    38       - added lib/Google/Chart/Type/ScatterPlot.pm 
    39       - added lib/Google/Chart/Type/Venn.pm 
    40       - added lib/Google/Chart/Color 
    41       - added lib/Google/Chart/Color.pm 
    42     date: 2007-12-07T21:43:21Z 
    43     tags: [] 
    44     version: 0.02 
    45   - author: 'Marcel Gruenauer <marcel@cpan.org>' 
    46     changes: 
    47       - original version 
    48     date: 2007-12-06T19:37:44Z 
    49     tags: [] 
    50     version: 0.01 
     1Changes 
     2====== 
     3 
     40.05000_03 29 Jul 2008 
     5  * Make Data::Extended capable of handling multiple sets of data (danjou) 
     6  * Add proper color support and legend support (danjou) 
     7 
     80.05000_02 25 Jul 2008 
     9  * Fix Fill::LinearStripes and Fill::LinearGradient 
     10  * Slight modification Google::Chart accessor generation 
     11 
     120.05000_01 24 Jul 2008 
     13  * Mooooooooooooooose 
     14  * Backwards incompatible! Beware! 
  • lang/perl/Google-Chart/trunk/MANIFEST

    r9833 r16838  
    11Changes 
    2 inc/Module/AutoInstall.pm 
    32inc/Module/Install.pm 
    4 inc/Module/Install/AutoInstall.pm 
    53inc/Module/Install/Base.pm 
    64inc/Module/Install/Can.pm 
     
    97inc/Module/Install/Makefile.pm 
    108inc/Module/Install/Metadata.pm 
    11 inc/Module/Install/StandardTests.pm 
    12 inc/Module/Install/Template.pm 
    139inc/Module/Install/Win32.pm 
    1410inc/Module/Install/WriteAll.pm 
    1511inc/Test/Compile.pm 
    16 inc/Test/Differences.pm 
    1712inc/Test/More.pm 
    18 inc/UNIVERSAL/require.pm 
    1913lib/Google/Chart.pm 
    20 lib/Google/Chart/Base.pm 
     14lib/Google/Chart/Axis.pm 
     15lib/Google/Chart/Axis/Item.pm 
     16lib/Google/Chart/Axis/Style.pm 
    2117lib/Google/Chart/Color.pm 
    22 lib/Google/Chart/Color/Data.pm 
    2318lib/Google/Chart/Data.pm 
    24 lib/Google/Chart/Data/ExtendedEncoding.pm 
    25 lib/Google/Chart/Data/SimpleEncoding.pm 
    26 lib/Google/Chart/Factory.pm 
     19lib/Google/Chart/Data/Extended.pm 
     20lib/Google/Chart/Data/Simple.pm 
     21lib/Google/Chart/Data/Text.pm 
     22lib/Google/Chart/Fill.pm 
     23lib/Google/Chart/Fill/LinearGradient.pm 
     24lib/Google/Chart/Fill/LinearStripes.pm 
     25lib/Google/Chart/Fill/Solid.pm 
     26lib/Google/Chart/Legend.pm 
     27lib/Google/Chart/Marker.pm 
     28lib/Google/Chart/QueryComponent.pm 
     29lib/Google/Chart/QueryComponent/Simple.pm 
    2730lib/Google/Chart/Size.pm 
     31lib/Google/Chart/Title.pm 
    2832lib/Google/Chart/Type.pm 
    2933lib/Google/Chart/Type/Bar.pm 
    30 lib/Google/Chart/Type/Bar/HorizontalGrouped.pm 
    31 lib/Google/Chart/Type/Bar/HorizontalStacked.pm 
    32 lib/Google/Chart/Type/Bar/VerticalGrouped.pm 
    33 lib/Google/Chart/Type/Bar/VerticalStacked.pm 
    3434lib/Google/Chart/Type/Line.pm 
    35 lib/Google/Chart/Type/Line/LineX.pm 
    36 lib/Google/Chart/Type/Line/LineXY.pm 
    3735lib/Google/Chart/Type/Pie.pm 
    38 lib/Google/Chart/Type/Pie/ThreeDimensional.pm 
    39 lib/Google/Chart/Type/Pie/TwoDimensional.pm 
     36lib/Google/Chart/Type/QRcode.pm 
     37lib/Google/Chart/Type/Radar.pm 
    4038lib/Google/Chart/Type/ScatterPlot.pm 
     39lib/Google/Chart/Type/Simple.pm 
     40lib/Google/Chart/Type/SparkLine.pm 
    4141lib/Google/Chart/Type/Venn.pm 
     42lib/Google/Chart/Types.pm 
    4243Makefile.PL 
    4344MANIFEST                        This list of files 
    4445META.yml 
    45 README 
    46 t/01_basic.t 
    47 t/02_extended_encoding.t 
    48 t/perlcriticrc 
     46t/00_compile.t 
     47t/01_size.t 
     48t/02_marker.t 
     49t/10_text.t 
     50t/11_extended.t 
     51t/20_color.t 
     52t/21_legend.t 
     53t/50_line.t 
     54t/51_bar.t 
     55t/52_pie.t 
     56t/53_qrcode.t 
     57t/60_axis.t 
     58t/61_fill.t 
     59t/99-pod-coverage.t 
     60t/99-pod.t 
  • lang/perl/Google-Chart/trunk/Makefile.PL

    r9832 r16838  
     1use strict; 
    12use inc::Module::Install; 
    2 include 'Module::AutoInstall'; 
    33 
    44name 'Google-Chart'; 
    5 all_from 'lib/Google/Chart.pm'; 
    6 perl_version '5.006'; 
    75 
    8 requires 'Class::Accessor::Complex'; 
    9 requires 'Class::Accessor::Constructor'; 
    10 requires 'Class::Accessor::FactoryTyped' => '0.03'; 
    11 requires 'Class::Factory::Enhanced'; 
     6all_from('lib/Google/Chart.pm'); 
     7 
    128requires 'LWP::UserAgent'; 
     9requires 'Moose', '0.54'; 
     10requires 'Class::MOP', '0.63'; 
     11requires 'URI'; 
     12requires 'URI::Escape'; 
     13requires 'Scalar::Util'; 
    1314 
    14 build_requires 'Test::More' => '0.70'; 
    15 build_requires 'Test::Differences'; 
     15test_requires 'Test::More'; 
     16test_requires 'Test::Compile'; 
    1617 
    17 process_templates( 
    18     first_year => 2007, 
    19     rest_from  => "$ENV{HOME}/.mitlib/standard_pod", 
    20     start_tag  => '{%', 
    21     end_tag    => '%}', 
    22 ); 
    23  
    24 use_standard_tests(without => 'pod_coverage'); 
    25 auto_install; 
    2618auto_include; 
    2719WriteAll; 
  • lang/perl/Google-Chart/trunk/lib/Google/Chart.pm

    r9832 r16838  
     1# $Id$ 
     2 
    13package Google::Chart; 
    2  
    3 use strict; 
    4 use warnings; 
     4use Moose; 
     5use Google::Chart::Axis; 
     6use Google::Chart::Legend; 
     7use Google::Chart::Color; 
     8use Google::Chart::Data; 
     9use Google::Chart::Size; 
     10use Google::Chart::Type; 
     11use Google::Chart::Types; 
    512use LWP::UserAgent; 
    6  
    7  
    8 our $VERSION = '0.04'; 
    9  
    10  
    11 use base qw( 
    12     Google::Chart::Base 
    13     Google::Chart::Factory 
     13use URI; 
     14use overload 
     15    '""' => \&as_uri, 
     16    fallback => 1, 
     17; 
     18our $USER_AGENT; 
     19 
     20use constant BASE_URI => URI->new("http://chart.apis.google.com/chart"); 
     21 
     22our $VERSION   = '0.05000'; 
     23our $AUTHORITY = 'cpan:DMAKI'; 
     24 
     25my %COMPONENTS = ( 
     26    type => { 
     27        is => 'rw', 
     28        does => 'Google::Chart::Type', 
     29        coerce => 1, 
     30        required => 1, 
     31    }, 
     32    data => { 
     33        is       => 'rw', 
     34        does     => 'Google::Chart::Data', 
     35        coerce   => 1, 
     36    }, 
     37    color => { 
     38        is       => 'rw', 
     39        isa      => 'Google::Chart::Color', 
     40        coerce   => 1, 
     41    }, 
     42    legend => { 
     43        is       => 'rw', 
     44        does     => 'Google::Chart::Legend', 
     45        coerce   => 1, 
     46    }, 
     47    size => { 
     48        is       => 'rw', 
     49        isa      => 'Google::Chart::Size', 
     50        coerce   => 1, 
     51        required => 1, 
     52        lazy     => 1, 
     53        default  => sub { Google::Chart::Size->new( width => 400, height => 300 ) }, 
     54    }, 
     55    marker => { 
     56        is       => 'rw', 
     57        isa      => 'Google::Chart::Marker', 
     58        coerce   => 1, 
     59    }, 
     60    axis => { 
     61        is       => 'rw', 
     62        isa      => 'Google::Chart::Axis', 
     63        coerce   => 1, 
     64    }, 
     65    fill => { 
     66        is       => 'rw', 
     67        does     => 'Google::Chart::Fill', 
     68        coerce   => 1 
     69    } 
    1470); 
    15  
    16  
    17 __PACKAGE__ 
    18     ->mk_scalar_accessors(qw(title ua)) 
    19     ->mk_factory_typed_accessors('Google::Chart::Factory', 
    20         data       => 'data', 
    21         type       => 'type', 
    22         size       => 'size', 
    23         color_data => 'color_data', 
    24     ); 
    25  
    26  
    27 use constant DEFAULTS => ( 
    28     ua => LWP::UserAgent->new, 
     71my @COMPONENTS = keys %COMPONENTS; 
     72 
     73{ 
     74    while (my ($name, $spec) = each %COMPONENTS ) { 
     75        has $name => %$spec; 
     76    } 
     77} 
     78 
     79has 'ua' => ( 
     80    is       => 'rw', 
     81    isa      => 'LWP::UserAgent', 
     82    required => 1, 
     83    lazy     => 1, 
     84    default  => sub { $USER_AGENT ||= LWP::UserAgent->new() } 
    2985); 
    3086 
    31  
    32 use constant API_URI => 'http://chart.apis.google.com/chart?'; 
    33  
    34  
    35 sub make_obj { 
     87__PACKAGE__->meta->make_immutable; 
     88 
     89no Moose; 
     90 
     91# XXX  
     92# We need a trigger function that gets called whenever a component 
     93# is set, so we can validate if the combination of components are 
     94# actually feasible. 
     95 
     96sub as_uri { 
    3697    my $self = shift; 
    37     Google::Chart::Factory->make_object_for_type(@_); 
    38 } 
    39  
    40  
    41 # Convenience methods for using underlying objects 
    42  
    43 sub set_size { 
    44     my $self = shift; 
    45     my ($x, $y); 
    46     if (@_ == 1 && ref $_[0] eq 'ARRAY') { 
    47         ($x, $y) = @{ $_[0] }; 
    48     } else { 
    49         ($x, $y) = @_; 
    50     } 
    51     $self->size->x($x); 
    52     $self->size->y($y); 
    53 } 
    54  
    55  
    56 sub type_name { 
    57     my ($self, $type_name, @args) = @_; 
    58     $self->type($self->make_obj($type_name, @args)); 
    59 } 
    60  
    61  
    62 sub data_spec { 
    63     my ($self, $args) = @_; 
    64     die "data_spec has no 'encoding' key\n" unless $args->{encoding}; 
    65     my $encoding = delete $args->{encoding}; 
    66     $self->data($self->make_obj($encoding, %$args)); 
    67 } 
    68  
    69  
    70 sub colors { 
    71     my ($self, @args) = @_; 
    72     @args = 
    73         map { $self->make_obj('color')->guess($_) } 
    74         @args; 
    75     $self->color_data(colors => \@args); 
    76 } 
    77  
    78  
    79 # End of convenience methods 
    80  
    81  
    82 sub validate { 
    83     my $self = shift; 
    84     my @error = map { $self->$_->validate } qw( 
    85         size type data color_data 
    86     ); 
    87     die join "\n" => @error if @error; 
    88 } 
    89  
    90  
    91 sub get_url { 
    92     my $self = shift; 
    93     my $url = $self->API_URI . 
    94         join '&' => 
    95         map { $self->$_->as_string } 
    96         grep { $self->$_->has_content } 
    97         qw(size data type color_data); 
    98 } 
    99  
    100  
    101 sub img_tag { 
    102     my $self = shift; 
    103     my $url = $self->get_url; 
    104     $url =~ s/&/&amp;/g; 
    105     qq{<IMG SRC="$url" />}; 
    106 } 
    107  
     98 
     99    my %query; 
     100    foreach my $c (@COMPONENTS) { 
     101        my $component = $self->$c; 
     102        next unless $component; 
     103        my @params = $component->as_query; 
     104        while (@params) { 
     105            my ($name, $value) = splice(@params, 0, 2); 
     106            next unless length $value; 
     107            $query{$name} = $value; 
     108        } 
     109    } 
     110 
     111    # If in case you want to change this for debugging or whatever... 
     112    my $uri = $ENV{GOOGLE_CHART_URI} ?  
     113        URI->new($ENV{GOOGLE_CHART_URI}) : 
     114        BASE_URI->clone; 
     115    $uri->query_form( %query ); 
     116    return $uri; 
     117} 
    108118 
    109119sub render { 
    110120    my $self = shift; 
    111     my $response = $self->ua->get($self->get_url); 
     121    my $response = $self->ua->get($self->as_uri); 
    112122 
    113123    if ($response->is_success) { 
     
    118128} 
    119129 
    120  
    121130sub render_to_file { 
    122131    my ($self, $filename) = @_; 
     
    127136} 
    128137 
    129  
    1301381; 
    131139 
    132  
    133140__END__ 
    134141 
    135 {% USE p = PodGenerated %} 
     142=encoding UTF-8 
    136143 
    137144=head1 NAME 
    138145 
    139 {% p.package %} - Draw a chart with Google Chart 
     146Google::Chart - Interface to Google Charts API 
    140147 
    141148=head1 SYNOPSIS 
    142149 
    143     use Google::Chart; 
    144      
    145     my $chart = Google::Chart->new( 
    146         type_name => 'type_pie_3d', 
    147         set_size  => [ 300, 100 ], 
    148         data_spec => { 
    149             encoding  => 'data_simple_encoding', 
    150             max_value => 100, 
    151             value_sets => [ [ map { $_ * 10 } 0..10 ] ], 
    152         }, 
    153     ); 
    154  
    155     print $chart->get_url; 
    156     $chart->render_to_file('my_chart.png'); 
    157  
    158 =head1 WARNING 
    159  
    160 This is a very early alpha release. It is more a proof of concept, but for 
    161 very simple cases it already works. Documentation and more complete support of 
    162 the Google Chart API will follow shortly. For now, the code more or less is 
    163 the documentation. Patches welcome. 
    164  
    165 I've neverthless released the distribution, in the I<spirit of one-point-oh>, 
    166 as Douglas Coupland puts it, or rather, in the spirit of point-oh-one. 
    167  
    168 =head1 DESCRIPTION 
    169  
    170 This set of classes uses the Google Chart API - see 
    171 L<http://code.google.com/apis/chart/> - to draw charts. 
     150  use Google::Chart; 
     151 
     152  my $chart = Google::Chart->new( 
     153    type => "Bar", 
     154    data => [ 1, 2, 3, 4, 5 ] 
     155  ); 
     156 
     157  print $chart->as_uri, "\n"; # or simply print $chart, "\n" 
     158 
     159  $chart->render_to_file( filename => 'filename.png' ); 
     160 
     161=head1 DESCRITPION 
     162 
     163Google::Chart provides a Perl Interface to Google Charts API  
     164(http://code.google.com/apis/chart/). 
     165 
     166Please note that version 0.05000 is a major rewrite, and has little to no 
     167backwards compatibility. 
    172168 
    173169=head1 METHODS 
    174170 
     171=head2 new(%args) 
     172 
    175173=over 4 
    176174 
    177 {% p.write_methods %} 
     175=item type 
     176 
     177Specifies the chart type, such as line, bar, pie, etc. If given a string like 
     178'Bar', it will instantiate an instance of Google::Chart::Type::Bar by 
     179invoking argument-less constructor. 
     180 
     181If you want to pass parameters to the constructor, either pass in an 
     182already instanstiated object, or pass in a hash, which will be coerced to 
     183the appropriate object 
     184 
     185  my $chart = Google::Chart->new( 
     186    type => { 
     187      module => "Bar", 
     188      args   => { 
     189        orientation => "horizontal" 
     190      } 
     191    } 
     192  ); 
     193 
     194=item size 
     195 
     196Specifies the chart size. Strings like "400x300", hash references, or already 
     197instantiated objects can be used: 
     198 
     199  my $chart = Google::Chart->new( 
     200    size => "400x300", 
     201  ); 
     202 
     203  my $chart = Google::Chart->new( 
     204    size => { 
     205      width => 400, 
     206      height => 300 
     207    } 
     208  ); 
     209 
     210=item marker 
     211 
     212Specifies the markers that go on line charts. 
     213 
     214=item axis 
     215 
     216Specifies the axis labels and such that go on line and bar charts 
    178217 
    179218=back 
    180219 
    181 {% p.write_inheritance %} 
    182  
    183 {% PROCESS standard_pod %} 
    184  
     220=head2 as_uri() 
     221 
     222Returns the URI that represents the chart object. 
     223 
     224=head2 render() 
     225 
     226Generates the chart image, and returns the contents. 
     227 
     228=head2 render_to_file( %args ) 
     229 
     230Generates the chart, and writes the contents out to the file specified by 
     231`filename' parameter 
     232 
     233=head1 FEEDBACK 
     234 
     235We don't believe that we fully utilize Google Chart's abilities. So there 
     236might be things missing, things that should be changed for easier use. 
     237If you find any such case, PLEASE LET US KNOW! Suggestions are welcome, but 
     238code snippets, pseudocode, or even better, test cases, are most welcome. 
     239 
     240=head1 TODO 
     241 
     242=over 4 
     243 
     244=item Standardize Interface 
     245 
     246Objects need to expect data in a standard format. This is not the case yet. 
     247(comments welcome) 
     248 
     249=item Adding New Components Is Cumbersome 
     250 
     251There must be an easy way to just plug it in. 
     252 
     253=item Moose-ish Errors 
     254 
     255I've been reported that some Moose-related errors occur on certain platforms. 
     256I have not been able to reproduce it myself, so if you do, please let me 
     257know. 
     258 
     259=back 
     260 
     261=head1 AUTHORS 
     262 
     263Daisuke Maki C<< <daisuke@endeworks.jp> >> (current maintainer) 
     264 
     265Nobuo Danjou C<< <nobuo.danjou@gmail.com> >> 
     266 
     267Marcel Grünauer C<< <marcel@cpan.org> >> (original author) 
     268 
     269=head1 LICENSE 
     270 
     271This program is free software; you can redistribute it and/or modify it 
     272under the same terms as Perl itself. 
     273 
     274See http://www.perl.com/perl/misc/Artistic.html 
    185275=cut 
    186  
  • lang/perl/Google-Chart/trunk/lib/Google/Chart/Color.pm

    r9832 r16838  
    11package Google::Chart::Color; 
     2use Moose; 
     3use Moose::Util::TypeConstraints; 
    24 
    3 use strict; 
    4 use warnings; 
     5use constant parameter_name => 'chco'; 
    56 
     7with 'Google::Chart::QueryComponent::Simple'; 
    68 
    7 our $VERSION = '0.04'; 
     9coerce 'Google::Chart::Color' 
     10    => from 'ArrayRef' 
     11    => via { 
     12        Google::Chart::Color->new(values => $_); 
     13    } 
     14; 
     15coerce 'Google::Chart::Color' 
     16    => from 'HashRef' 
     17    => via { 
     18        Google::Chart::Color->new(%{$_}); 
     19    } 
     20; 
     21coerce 'Google::Chart::Color' 
     22    => from 'Str' 
     23    => via { 
     24        Google::Chart::Color->new(values => [$_]); 
     25    } 
     26; 
    827 
     28subtype 'Google::Chart::Color::Data' 
     29    => as 'Str' 
     30    => where { /^[a-f0-9]{6}/i } 
     31; 
    932 
    10 use base qw(Google::Chart::Base); 
     33subtype 'Google::Chart::Color::DataList' 
     34    => as 'ArrayRef[Google::Chart::Color::Data]' 
     35; 
    1136 
     37coerce 'Google::Chart::Color::DataList' 
     38    => from 'Str' 
     39    => via { [ $_ ] } 
     40; 
    1241 
    13 __PACKAGE__ 
    14     ->mk_scalar_accessors(qw(red green blue transparency)); 
    15  
    16  
    17 use constant DEFAULTS => ( 
    18     red   => 0, 
    19     green => 0, 
    20     blue  => 0, 
     42has 'values' => ( 
     43    is => 'rw', 
     44    isa => 'Google::Chart::Color::DataList', 
     45    coerce => 1, 
     46    required => 1, 
     47    default => sub { +[] } 
    2148); 
    2249 
     50__PACKAGE__->meta->make_immutable; 
    2351 
    24 sub new_from_rgbt { 
    25     my ($class, $rgbt) = @_; 
    26     my $self = $class->new; 
    27     $self->rgbt($rgbt); 
    28     $self; 
     52no Moose; 
     53 
     54sub parameter_value { 
     55    my $self = shift; 
     56    join(',', @{ $self->values }); 
    2957} 
    30  
    31  
    32 sub new_from_hex { 
    33     my ($class, $hex) = @_; 
    34     my $self = $class->new; 
    35     $self->hex($hex); 
    36     $self; 
    37 } 
    38  
    39  
    40 sub rgbt { 
    41     my $self = shift; 
    42     if (@_) { 
    43         my ($red, $green, $blue, $transparency) = @{ $_[0] }; 
    44         $self->red($red); 
    45         $self->green($green); 
    46         $self->blue($blue); 
    47         $self->transparency($transparency); 
    48         return $self;   # for chaining 
    49     } else { 
    50         return [ $self->red, $self->green, $self->blue, $self->transparency ]; 
    51     } 
    52 } 
    53  
    54  
    55 sub hex { 
    56     my $self = shift; 
    57     if (@_) { 
    58         my $hex = shift; 
    59         $hex =~ s/^#//; 
    60         $hex =~ s/(.)/$1$1/g if length($hex) == 3; 
    61         my ($red, $green, $blue, $transparency) = 
    62             map { defined($_) ? hex : undef } 
    63             $hex =~ /(.{2})/g; 
    64         $self->red($red); 
    65         $self->green($green); 
    66         $self->blue($blue); 
    67         $self->transparency($transparency); 
    68         return $self;   # for chaining 
    69     } else { 
    70         my $to_hex = sub { substr sprintf('0%x', shift), -2 }; 
    71         my $value = uc 
    72             join '' => 
    73             map { $to_hex->($self->$_) } 
    74             qw(red green blue); 
    75         $value .= $to_hex->($self->transparency) if 
    76             defined $self->transparency; 
    77         return $value; 
    78     } 
    79 } 
    80  
    81  
    82 sub guess { 
    83     my ($self, $input) = @_; 
    84     if (ref $input eq 'ARRAY') { 
    85         $self->rgbt($input) 
    86     } elsif (UNIVERSAL::can($input, 'rgbt')) { 
    87         $self->rgbt($input->rgbt) 
    88     } else { 
    89         $self->hex($input); 
    90     } 
    91     $self;   # for chaining 
    92 } 
    93  
    94  
    95 sub validate { 
    96     my ($self, $chart) = @_; 
    97      
    98     my @error; 
    99     for (qw(red green blue transparency)) { 
    100         unless ($_ eq 'transparency' || defined $self->$_) { 
    101             push @error, "$_ color component is not defined"; 
    102             next; 
    103         } 
    104  
    105         unless ($self->is_number($self->$_)) { 
    106             push @error, "$_ color component is not a number"; 
    107             next; 
    108         } 
    109  
    110         my $value = int $self->$_; 
    111  
    112         if ($value < 0) { 
    113             push @error, "$_ color component is less than zero"; 
    114             next; 
    115         } 
    116  
    117         if ($value > 255) { 
    118             push @error, "$_ color component is greater than 255"; 
    119             next; 
    120         } 
    121     } 
    122  
    123     @error; 
    124 } 
    125  
    126  
    127 sub as_string { 
    128     my $self = shift; 
    129     my $k 
    130 } 
    131  
    13258 
    133591; 
    13460 
    135  
    13661__END__ 
    137  
    138 {% USE p = PodGenerated %} 
    13962 
    14063=head1 NAME 
    14164 
    142 {% p.package %} - Draw a chart with Google Chart 
    143  
    144 =head1 SYNOPSIS 
    145  
    146     {% p.package %}->new; 
    147  
    148 =head1 WARNING 
    149  
    150 This is a very early alpha release. It is more a proof of concept, but for 
    151 very simple cases it already works. Documentation and more complete support of 
    152 the Google Chart API will follow shortly. For now, the code more or less is 
    153 the documentation. Patches welcome. 
    154  
    155 =head1 DESCRIPTION 
    156  
    157 This set of classes uses the Google Chart API - see 
    158 L<http://code.google.com/apis/chart/> - to draw charts. 
    159  
    160 =head1 METHODS 
    161  
    162 =over 4 
    163  
    164 {% p.write_methods %} 
    165  
    166 =back 
    167  
    168 {% p.write_inheritance %} 
    169  
    170 {% PROCESS standard_pod %} 
     65Google::Chart::Color - Google::Chart Color 
    17166 
    17267=cut 
    173  
  • lang/perl/Google-Chart/trunk/lib/Google/Chart/Data.pm

    r9832 r16838  
     1# $Id$ 
     2 
    13package Google::Chart::Data; 
     4use Moose::Role; 
    25 
    3 use strict; 
    4 use warnings; 
     6use constant parameter_name => 'chd'; 
    57 
     8with 'Google::Chart::QueryComponent::Simple'; 
    69 
    7 our $VERSION = '0.04'; 
     10has 'dataset' => ( 
     11    is => 'rw', 
     12    isa => 'ArrayRef', 
     13    required => 1, 
     14    default => sub { +[] } 
     15); 
    816 
    9  
    10 use base qw(Google::Chart::Base); 
    11  
    12  
    13 __PACKAGE__ 
    14     ->mk_scalar_accessors(qw(max_value)) 
    15     ->mk_array_accessors(qw(value_sets)) 
    16     ->mk_abstract_accessors(qw(encode_value_set)); 
    17  
    18  
    19 use constant ENCODING_TYPE_VALUE => '?';   # override in subclasses 
    20  
    21  
    22 sub has_content { 
    23     my $self = shift; 
    24     $self->value_sets_count; 
    25 } 
    26  
    27  
    28 sub as_string { 
    29     my $self = shift; 
    30     sprintf 'chd=%s:%s', 
    31         $self->ENCODING_TYPE_VALUE, 
    32         join ',' => 
    33         map { $self->encode_value_set($_) } 
    34         $self->value_sets; 
    35 } 
    36  
     17no Moose; 
    3718 
    38191; 
    3920 
    40  
    4121__END__ 
    42  
    43 {% USE p = PodGenerated %} 
    4422 
    4523=head1 NAME 
    4624 
    47 {% p.package %} - Draw a chart with Google Chart 
    48  
    49 =head1 SYNOPSIS 
    50  
    51     {% p.package %}->new; 
    52  
    53 =head1 WARNING 
    54  
    55 This is a very early alpha release. It is more a proof of concept, but for 
    56 very simple cases it already works. Documentation and more complete support of 
    57 the Google Chart API will follow shortly. For now, the code more or less is 
    58 the documentation. Patches welcome. 
    59  
    60 =head1 DESCRIPTION 
    61  
    62 This set of classes uses the Google Chart API - see 
    63 L<http://code.google.com/apis/chart/> - to draw charts. 
    64  
    65 =head1 METHODS 
    66  
    67 =over 4 
    68  
    69 {% p.write_methods %} 
    70  
    71 =back 
    72  
    73 {% p.write_inheritance %} 
    74  
    75 {% PROCESS standard_pod %} 
     25Google::Chart::Data - Google::Chart Data Role 
    7626 
    7727=cut 
    78  
  • lang/perl/Google-Chart/trunk/lib/Google/Chart/Size.pm

    r9832 r16838  
     1# $Id$ 
     2 
    13package Google::Chart::Size; 
     4use Moose; 
     5use Moose::Util::TypeConstraints; 
     6use Google::Chart::Types qw(hash_coercion); 
    27 
    3 use strict; 
    4 use warnings; 
     8use constant parameter_name => 'chs'; 
    59 
     10with 'Google::Chart::QueryComponent::Simple'; 
    611 
    7 our $VERSION = '0.04'; 
     12coerce 'Google::Chart::Size' 
     13    => from 'Str' 
     14    => via { 
     15        if (! /^(\d+)x(\d+)$/) { 
     16            confess "Could not parse $_ as size"; 
     17        } 
    818 
     19        return Google::Chart::Size->new(width => $1, height => $2); 
     20    } 
     21; 
    922 
    10 use base qw(Google::Chart::Base); 
     23coerce 'Google::Chart::Size' 
     24    => from 'HashRef' 
     25    => hash_coercion( prefix => 'Google::Chart::Size', default => '+Google::Chart::Size' ) 
     26; 
    1127 
     28has 'width' => ( 
     29    is => 'rw', 
     30    isa => 'Int', 
     31    required => 1 
     32); 
    1233 
    13 __PACKAGE__->mk_scalar_accessors(qw(x y)); 
     34has 'height' => ( 
     35    is => 'rw', 
     36    isa => 'Int', 
     37    required => 1 
     38); 
    1439 
     40no Moose; 
    1541 
    16 sub validate { 
    17     my ($self, $chart) = @_; 
    18  
    19     my @error; 
    20  
    21     if ($self->size_x < 0) { 
    22         push @error, sprintf 'width [%s] is negative', $self->size_x; 
    23     } 
    24  
    25     if ($self->size_x == 0) { 
    26         push @error, sprintf 'width [%s] is zero', $self->size_x; 
    27     } 
    28  
    29     if ($self->size_x > 1000) { 
    30         push @error, sprintf 'width [%s] is greater than 1000', $self->size_x; 
    31     } 
    32  
    33     if ($self->size_y < 0) { 
    34         push @error, sprintf 'height [%s] is negative', $self->size_y; 
    35     } 
    36  
    37     if ($self->size_y == 0) { 
    38         push @error, sprintf 'height [%s] is zero', $self->size_y; 
    39     } 
    40  
    41     if ($self->size_y > 1000) { 
    42         push @error, sprintf 'height [%s] is greater than 1000', $self->size_x; 
    43     } 
    44  
    45     if ($self->size_x * $self->size_y > 300_000) { 
    46         push @error, sprintf 'area is more than 300,000 pixels'; 
    47     } 
    48  
    49     @error; 
     42sub parameter_value { 
     43    my $self = shift; 
     44    return join('x', $self->width, $self->height); 
    5045} 
    51  
    52  
    53 sub has_content { 
    54     my $self = shift; 
    55     defined($self->x) && defined $self->y; 
    56 } 
    57  
    58  
    59 sub as_string { 
    60     my $self = shift; 
    61     sprintf 'chs=%sx%s', int($self->x), int($self->y); 
    62 } 
    63  
    6446 
    65471; 
    6648 
    67  
    6849__END__ 
    69  
    70 {% USE p = PodGenerated %} 
    7150 
    7251=head1 NAME 
    7352 
    74 {% p.package %} - Draw a chart with Google Chart 
     53Google::Chart::Size - Google::Chart Size Specification 
    7554 
    7655=head1 SYNOPSIS 
    7756 
    78     {% p.package %}->new; 
     57  Google::Chart->new( 
     58    size => "400x300" 
     59  ) 
    7960 
    80 =head1 WARNING 
    81  
    82 This is a very early alpha release. It is more a proof of concept, but for 
    83 very simple cases it already works. Documentation and more complete support of 
    84 the Google Chart API will follow shortly. For now, the code more or less is 
    85 the documentation. Patches welcome. 
    86  
    87 =head1 DESCRIPTION 
    88  
    89 This set of classes uses the Google Chart API - see 
    90 L<http://code.google.com/apis/chart/> - to draw charts. 
     61  Google::Chart->new( 
     62    size => { 
     63      width => 400, 
     64      height => 300 
     65    } 
     66  ) 
    9167 
    9268=head1 METHODS 
    9369 
    94 =over 4 
    95  
    96 {% p.write_methods %} 
    97  
    98 =back 
    99  
    100 {% p.write_inheritance %} 
    101  
    102 {% PROCESS standard_pod %} 
     70=head2 parameter_value 
    10371 
    10472=cut 
    105  
  • lang/perl/Google-Chart/trunk/lib/Google/Chart/Type.pm

    r9832 r16838  
     1# $Id$ 
     2 
    13package Google::Chart::Type; 
     4use Moose::Role; 
    25 
    3 use strict; 
    4 use warnings; 
     6with 'Google::Chart::QueryComponent'; 
    57 
    6  
    7 our $VERSION = '0.04'; 
    8  
    9  
    10 use base qw(Google::Chart::Base); 
    11  
    12  
    13 use constant has_content => 1; 
    14  
     8no Moose; 
    159 
    16101; 
    1711 
    18  
    1912__END__ 
    20  
    21 {% USE p = PodGenerated %} 
    2213 
    2314=head1 NAME 
    2415 
    25 {% p.package %} - Draw a chart with Google Chart 
    26  
    27 =head1 SYNOPSIS 
    28  
    29     {% p.package %}->new; 
    30  
    31 =head1 WARNING 
    32  
    33 This is a very early alpha release. It is more a proof of concept, but for 
    34 very simple cases it already works. Documentation and more complete support of 
    35 the Google Chart API will follow shortly. For now, the code more or less is 
    36 the documentation. Patches welcome. 
    37  
    38 =head1 DESCRIPTION 
    39  
    40 This set of classes uses the Google Chart API - see 
    41 L<http://code.google.com/apis/chart/> - to draw charts. 
    42  
    43 {% p.write_inheritance %} 
    44  
    45 {% PROCESS standard_pod %} 
     16Google::Chart::Type - Google::Chart Type Role 
    4617 
    4718=cut 
    48  
  • lang/perl/Google-Chart/trunk/lib/Google/Chart/Type/Bar.pm

    r9832 r16838  
     1# $Id$ 
     2 
    13package Google::Chart::Type::Bar; 
     4use Moose; 
     5use Moose::Util::TypeConstraints; 
    26 
    3 use strict; 
    4 use warnings; 
     7with 'Google::Chart::Type::Simple'; 
    58 
     9enum 'Google::Chart::Type::Bar::Orientation' => qw(horizontal vertical); 
    610 
    7 our $VERSION = '0.04'; 
     11has 'colored' => ( 
     12    is => 'rw', 
     13    isa => 'Bool', 
     14    required => 1, 
     15    default => 0, 
     16); 
    817 
     18has 'orientation' => ( 
     19    is => 'rw', 
     20    isa => 'Google::Chart::Type::Bar::Orientation', 
     21    required => 1, 
     22    default => 'vertical', 
     23); 
    924 
    10 use base qw(Google::Chart::Type); 
     25__PACKAGE__->meta->make_immutable; 
    1126 
     27no Moose; 
     28 
     29sub parameter_value { 
     30    my $self = shift; 
     31 
     32    return sprintf( 'b%s%s',  
     33        $self->orientation eq 'vertical' ? 'v' : 'h', 
     34        $self->colored                   ? 'g' : 's' 
     35    ); 
     36} 
    1237 
    13381; 
    1439 
    15  
    1640__END__ 
    17  
    18 {% USE p = PodGenerated %} 
    1941 
    2042=head1 NAME 
    2143 
    22 {% p.package %} - Draw a chart with Google Chart 
     44Google::Chart::Type::Bar - Google::Chart Bar Type 
    2345 
    2446=head1 SYNOPSIS 
    2547 
    26     {% p.package %}->new; 
     48  Google::Chart->new( 
     49    type => { 
     50      module => "Bar", 
     51      orientation => "horizontal", 
     52    } 
     53  ); 
    2754 
    28 =head1 WARNING 
     55=head1 METHODS 
    2956 
    30 This is a very early alpha release. It is more a proof of concept, but for 
    31 very simple cases it already works. Documentation and more complete support of 
    32 the Google Chart API will follow shortly. For now, the code more or less is 
    33 the documentation. Patches welcome. 
    34  
    35 =head1 DESCRIPTION 
    36  
    37 This set of classes uses the Google Chart API - see 
    38 L<http://code.google.com/apis/chart/> - to draw charts. 
    39  
    40 {% p.write_inheritance %} 
    41  
    42 {% PROCESS standard_pod %} 
     57=head2 parameter_value 
    4358 
    4459=cut 
    45  
  • lang/perl/Google-Chart/trunk/lib/Google/Chart/Type/Line.pm

    r9832 r16838  
     1# $Id$ 
     2 
    13package Google::Chart::Type::Line; 
     4use Moose; 
     5use constant parameter_value => 'lc'; 
    26 
    3 use strict; 
    4 use warnings; 
     7with 'Google::Chart::Type::Simple'; 
    58 
    6  
    7 our $VERSION = '0.04'; 
    8  
    9  
    10 use base qw(Google::Chart::Type); 
    11  
     9no Moose; 
    1210 
    13111; 
    1412 
    15  
    1613__END__ 
    17  
    18 {% USE p = PodGenerated %} 
    1914 
    2015=head1 NAME 
    2116 
    22 {% p.package %} - Draw a chart with Google Chart 
    23  
    24 =head1 SYNOPSIS 
    25  
    26     {% p.package %}->new; 
    27  
    28 =head1 WARNING 
    29  
    30 This is a very early alpha release. It is more a proof of concept, but for 
    31 very simple cases it already works. Documentation and more complete support of 
    32 the Google Chart API will follow shortly. For now, the code more or less is 
    33 the documentation. Patches welcome. 
    34  
    35 =head1 DESCRIPTION 
    36  
    37 This set of classes uses the Google Chart API - see 
    38 L<http://code.google.com/apis/chart/> - to draw charts. 
    39  
    40 {% p.write_inheritance %} 
    41  
    42 {% PROCESS standard_pod %} 
     17Google::Chart::Type::Line - Google::Chart Line Type 
    4318 
    4419=cut 
    45  
  • lang/perl/Google-Chart/trunk/lib/Google/Chart/Type/Pie.pm

    r9832 r16838  
     1# $Id$ 
     2 
    13package Google::Chart::Type::Pie; 
     4use Moose; 
     5use Moose::Util::TypeConstraints; 
    26 
    3 use strict; 
    4 use warnings; 
     7with 'Google::Chart::Type::Simple'; 
    58 
     9has 'pie_type' => ( 
     10    is => 'rw', 
     11    isa => enum([ qw(2d 3d) ]), 
     12    required => 1, 
     13    default => '2d' 
     14); 
    615 
    7 our $VERSION = '0.04'; 
     16__PACKAGE__->meta->make_immutable; 
    817 
     18no Moose; 
    919 
    10 use base qw(Google::Chart::Type); 
     20sub parameter_value { 
     21    my $self = shift; 
    1122 
     23    return $self->pie_type eq '3d' ? 'p3' : 'p'; 
     24} 
    1225 
    13261; 
    1427 
    15  
    1628__END__ 
    17  
    18 {% USE p = PodGenerated %} 
    1929 
    2030=head1 NAME 
    2131 
    22 {% p.package %} - Draw a chart with Google Chart 
     32Google::Chart::Type::Pie - Google::Chart Pie Chart Type 
    2333 
    2434=head1 SYNOPSIS 
    2535 
    26     {% p.package %}->new; 
     36  Google::Chart->new( 
     37    type => 'Pie' 
     38  ); 
    2739 
    28 =head1 WARNING 
     40  Google::Chart->new( 
     41    type => { 
     42      module => 'Pie', 
     43      args   => { 
     44        pie_type => '3d' 
     45      } 
     46    } 
     47  ); 
    2948 
    30 This is a very early alpha release. It is more a proof of concept, but for 
    31 very simple cases it already works. Documentation and more complete support of 
    32 the Google Chart API will follow shortly. For now, the code more or less is 
    33 the documentation. Patches welcome. 
     49=head1 METHODS 
    3450 
    35 =head1 DESCRIPTION 
    36  
    37 This set of classes uses the Google Chart API - see 
    38 L<http://code.google.com/apis/chart/> - to draw charts. 
    39  
    40 {% p.write_inheritance %} 
    41  
    42 {% PROCESS standard_pod %} 
     51=head2 parameter_value 
    4352 
    4453=cut 
    45  
  • lang/perl/Google-Chart/trunk/lib/Google/Chart/Type/ScatterPlot.pm

    r9832 r16838  
     1# $Id$ 
     2 
    13package Google::Chart::Type::ScatterPlot; 
     4use Moose; 
     5use constant parameter_value => 's'; 
    26 
    3 use strict; 
    4 use warnings; 
     7with 'Google::Chart::Type::Simple'; 
    58 
     9__PACKAGE__->meta->make_immutable; 
    610 
    7 our $VERSION = '0.04'; 
    8  
    9  
    10 use base qw(Google::Chart::Type); 
    11  
    12  
    13 use constant as_string => 'cht=s'; 
    14  
     11no Moose; 
    1512 
    16131; 
    1714 
    18  
    1915__END__ 
    2016 
    21 {% USE p = PodGenerated %} 
     17=head1 NAME  
    2218 
    23 =head1 NAME 
    24  
    25 {% p.package %} - Draw a chart with Google Chart 
    26  
    27 =head1 SYNOPSIS 
    28  
    29     {% p.package %}->new; 
    30  
    31 =head1 WARNING 
    32  
    33 This is a very early alpha release. It is more a proof of concept, but for 
    34 very simple cases it already works. Documentation and more complete support of 
    35 the Google Chart API will follow shortly. For now, the code more or less is 
    36 the documentation. Patches welcome. 
    37  
    38 =head1 DESCRIPTION 
    39  
    40 This set of classes uses the Google Chart API - see 
    41 L<http://code.google.com/apis/chart/> - to draw charts. 
    42  
    43 {% p.write_inheritance %} 
    44  
    45 {% PROCESS standard_pod %} 
     19Google::Chart::Type::ScatterPlot - Google::Chart ScatterPlot Type 
    4620 
    4721=cut 
    48  
  • lang/perl/Google-Chart/trunk/lib/Google/Chart/Type/Venn.pm

    r9832 r16838  
     1# $Id$ 
     2 
    13package Google::Chart::Type::Venn; 
     4use Moose; 
    25 
    3 use strict; 
    4 use warnings; 
     6use constant parameter_value => 'v'; 
    57 
     8with 'Google::Chart::Type::Simple'; 
    69 
    7 our $VERSION = '0.04'; 
     10__PACKAGE__->meta->make_immutable; 
    811 
    9  
    10 use base qw(Google::Chart::Type); 
    11  
    12  
    13 use constant as_string => 'cht=v'; 
    14  
     12no Moose; 
    1513 
    16141; 
    1715 
    18  
    1916__END__ 
    2017 
    21 {% USE p = PodGenerated %} 
     18=head1 NAME  
    2219 
    23 =head1 NAME 
    24  
    25 {% p.package %} - Draw a chart with Google Chart 
    26  
    27 =head1 SYNOPSIS 
    28  
    29     {% p.package %}->new; 
    30  
    31 =head1 WARNING 
    32  
    33 This is a very early alpha release. It is more a proof of concept, but for 
    34 very simple cases it already works. Documentation and more complete support of 
    35 the Google Chart API will follow shortly. For now, the code more or less is 
    36 the documentation. Patches welcome. 
    37  
    38 =head1 DESCRIPTION 
    39  
    40 This set of classes uses the Google Chart API - see 
    41 L<http://code.google.com/apis/chart/> - to draw charts. 
    42  
    43 {% p.write_inheritance %} 
    44  
    45 {% PROCESS standard_pod %} 
     20Google::Chart::Type::Venn - Google::Chart Venn Type 
    4621 
    4722=cut 
    48