Changeset 16838
- Timestamp:
- 07/30/08 10:53:50 (5 years ago)
- Location:
- lang/perl/Google-Chart/trunk
- Files:
-
- 38 added
- 19 removed
- 13 modified
-
.shipit (deleted)
-
Changes (modified) (1 diff)
-
MANIFEST (modified) (2 diffs)
-
MANIFEST.SKIP (deleted)
-
Makefile.PL (modified) (1 diff)
-
README (deleted)
-
lib/Google/Chart.pm (modified) (3 diffs)
-
lib/Google/Chart/Axis (added)
-
lib/Google/Chart/Axis.pm (added)
-
lib/Google/Chart/Axis/Item.pm (added)
-
lib/Google/Chart/Axis/Style.pm (added)
-
lib/Google/Chart/Base.pm (deleted)
-
lib/Google/Chart/Color.pm (modified) (1 diff)
-
lib/Google/Chart/Color/Data.pm (deleted)
-
lib/Google/Chart/Data.pm (modified) (1 diff)
-
lib/Google/Chart/Data/Extended.pm (added)
-
lib/Google/Chart/Data/ExtendedEncoding.pm (deleted)
-
lib/Google/Chart/Data/Simple.pm (added)
-
lib/Google/Chart/Data/SimpleEncoding.pm (deleted)
-
lib/Google/Chart/Data/Text.pm (added)
-
lib/Google/Chart/Factory.pm (deleted)
-
lib/Google/Chart/Fill (added)
-
lib/Google/Chart/Fill.pm (added)
-
lib/Google/Chart/Fill/LinearGradient.pm (added)
-
lib/Google/Chart/Fill/LinearStripes.pm (added)
-
lib/Google/Chart/Fill/Solid.pm (added)
-
lib/Google/Chart/Legend.pm (added)
-
lib/Google/Chart/Marker.pm (added)
-
lib/Google/Chart/QueryComponent (added)
-
lib/Google/Chart/QueryComponent.pm (added)
-
lib/Google/Chart/QueryComponent/Simple.pm (added)
-
lib/Google/Chart/Size.pm (modified) (1 diff)
-
lib/Google/Chart/Title.pm (added)
-
lib/Google/Chart/Type.pm (modified) (1 diff)
-
lib/Google/Chart/Type/Bar.pm (modified) (1 diff)
-
lib/Google/Chart/Type/Bar/HorizontalGrouped.pm (deleted)
-
lib/Google/Chart/Type/Bar/HorizontalStacked.pm (deleted)
-
lib/Google/Chart/Type/Bar/VerticalGrouped.pm (deleted)
-
lib/Google/Chart/Type/Bar/VerticalStacked.pm (deleted)
-
lib/Google/Chart/Type/Line.pm (modified) (1 diff)
-
lib/Google/Chart/Type/Line/LineX.pm (deleted)
-
lib/Google/Chart/Type/Line/LineXY.pm (deleted)
-
lib/Google/Chart/Type/Pie.pm (modified) (1 diff)
-
lib/Google/Chart/Type/Pie/ThreeDimensional.pm (deleted)
-
lib/Google/Chart/Type/Pie/TwoDimensional.pm (deleted)
-
lib/Google/Chart/Type/QRcode.pm (added)
-
lib/Google/Chart/Type/Radar.pm (added)
-
lib/Google/Chart/Type/ScatterPlot.pm (modified) (1 diff)
-
lib/Google/Chart/Type/Simple.pm (added)
-
lib/Google/Chart/Type/SparkLine.pm (added)
-
lib/Google/Chart/Type/Venn.pm (modified) (1 diff)
-
lib/Google/Chart/Types.pm (added)
-
t/00_compile.t (added)
-
t/01_basic.t (deleted)
-
t/01_size.t (added)
-
t/02_extended_encoding.t (deleted)
-
t/02_marker.t (added)
-
t/10_text.t (added)
-
t/11_extended.t (added)
-
t/20_color.t (added)
-
t/21_legend.t (added)
-
t/50_line.t (added)
-
t/51_bar.t (added)
-
t/52_pie.t (added)
-
t/53_qrcode.t (added)
-
t/60_axis.t (added)
-
t/61_fill.t (added)
-
t/99-pod-coverage.t (added)
-
t/99-pod.t (added)
-
t/perlcriticrc (deleted)
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 1 Changes 2 ====== 3 4 0.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 8 0.05000_02 25 Jul 2008 9 * Fix Fill::LinearStripes and Fill::LinearGradient 10 * Slight modification Google::Chart accessor generation 11 12 0.05000_01 24 Jul 2008 13 * Mooooooooooooooose 14 * Backwards incompatible! Beware! -
lang/perl/Google-Chart/trunk/MANIFEST
r9833 r16838 1 1 Changes 2 inc/Module/AutoInstall.pm3 2 inc/Module/Install.pm 4 inc/Module/Install/AutoInstall.pm5 3 inc/Module/Install/Base.pm 6 4 inc/Module/Install/Can.pm … … 9 7 inc/Module/Install/Makefile.pm 10 8 inc/Module/Install/Metadata.pm 11 inc/Module/Install/StandardTests.pm12 inc/Module/Install/Template.pm13 9 inc/Module/Install/Win32.pm 14 10 inc/Module/Install/WriteAll.pm 15 11 inc/Test/Compile.pm 16 inc/Test/Differences.pm17 12 inc/Test/More.pm 18 inc/UNIVERSAL/require.pm19 13 lib/Google/Chart.pm 20 lib/Google/Chart/Base.pm 14 lib/Google/Chart/Axis.pm 15 lib/Google/Chart/Axis/Item.pm 16 lib/Google/Chart/Axis/Style.pm 21 17 lib/Google/Chart/Color.pm 22 lib/Google/Chart/Color/Data.pm23 18 lib/Google/Chart/Data.pm 24 lib/Google/Chart/Data/ExtendedEncoding.pm 25 lib/Google/Chart/Data/SimpleEncoding.pm 26 lib/Google/Chart/Factory.pm 19 lib/Google/Chart/Data/Extended.pm 20 lib/Google/Chart/Data/Simple.pm 21 lib/Google/Chart/Data/Text.pm 22 lib/Google/Chart/Fill.pm 23 lib/Google/Chart/Fill/LinearGradient.pm 24 lib/Google/Chart/Fill/LinearStripes.pm 25 lib/Google/Chart/Fill/Solid.pm 26 lib/Google/Chart/Legend.pm 27 lib/Google/Chart/Marker.pm 28 lib/Google/Chart/QueryComponent.pm 29 lib/Google/Chart/QueryComponent/Simple.pm 27 30 lib/Google/Chart/Size.pm 31 lib/Google/Chart/Title.pm 28 32 lib/Google/Chart/Type.pm 29 33 lib/Google/Chart/Type/Bar.pm 30 lib/Google/Chart/Type/Bar/HorizontalGrouped.pm31 lib/Google/Chart/Type/Bar/HorizontalStacked.pm32 lib/Google/Chart/Type/Bar/VerticalGrouped.pm33 lib/Google/Chart/Type/Bar/VerticalStacked.pm34 34 lib/Google/Chart/Type/Line.pm 35 lib/Google/Chart/Type/Line/LineX.pm36 lib/Google/Chart/Type/Line/LineXY.pm37 35 lib/Google/Chart/Type/Pie.pm 38 lib/Google/Chart/Type/ Pie/ThreeDimensional.pm39 lib/Google/Chart/Type/ Pie/TwoDimensional.pm36 lib/Google/Chart/Type/QRcode.pm 37 lib/Google/Chart/Type/Radar.pm 40 38 lib/Google/Chart/Type/ScatterPlot.pm 39 lib/Google/Chart/Type/Simple.pm 40 lib/Google/Chart/Type/SparkLine.pm 41 41 lib/Google/Chart/Type/Venn.pm 42 lib/Google/Chart/Types.pm 42 43 Makefile.PL 43 44 MANIFEST This list of files 44 45 META.yml 45 README 46 t/01_basic.t 47 t/02_extended_encoding.t 48 t/perlcriticrc 46 t/00_compile.t 47 t/01_size.t 48 t/02_marker.t 49 t/10_text.t 50 t/11_extended.t 51 t/20_color.t 52 t/21_legend.t 53 t/50_line.t 54 t/51_bar.t 55 t/52_pie.t 56 t/53_qrcode.t 57 t/60_axis.t 58 t/61_fill.t 59 t/99-pod-coverage.t 60 t/99-pod.t -
lang/perl/Google-Chart/trunk/Makefile.PL
r9832 r16838 1 use strict; 1 2 use inc::Module::Install; 2 include 'Module::AutoInstall';3 3 4 4 name 'Google-Chart'; 5 all_from 'lib/Google/Chart.pm';6 perl_version '5.006';7 5 8 requires 'Class::Accessor::Complex'; 9 requires 'Class::Accessor::Constructor'; 10 requires 'Class::Accessor::FactoryTyped' => '0.03'; 11 requires 'Class::Factory::Enhanced'; 6 all_from('lib/Google/Chart.pm'); 7 12 8 requires 'LWP::UserAgent'; 9 requires 'Moose', '0.54'; 10 requires 'Class::MOP', '0.63'; 11 requires 'URI'; 12 requires 'URI::Escape'; 13 requires 'Scalar::Util'; 13 14 14 build_requires 'Test::More' => '0.70';15 build_requires 'Test::Differences';15 test_requires 'Test::More'; 16 test_requires 'Test::Compile'; 16 17 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;26 18 auto_include; 27 19 WriteAll; -
lang/perl/Google-Chart/trunk/lib/Google/Chart.pm
r9832 r16838 1 # $Id$ 2 1 3 package Google::Chart; 2 3 use strict; 4 use warnings; 4 use Moose; 5 use Google::Chart::Axis; 6 use Google::Chart::Legend; 7 use Google::Chart::Color; 8 use Google::Chart::Data; 9 use Google::Chart::Size; 10 use Google::Chart::Type; 11 use Google::Chart::Types; 5 12 use LWP::UserAgent; 6 7 8 our $VERSION = '0.04'; 9 10 11 use base qw( 12 Google::Chart::Base 13 Google::Chart::Factory 13 use URI; 14 use overload 15 '""' => \&as_uri, 16 fallback => 1, 17 ; 18 our $USER_AGENT; 19 20 use constant BASE_URI => URI->new("http://chart.apis.google.com/chart"); 21 22 our $VERSION = '0.05000'; 23 our $AUTHORITY = 'cpan:DMAKI'; 24 25 my %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 } 14 70 ); 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,71 my @COMPONENTS = keys %COMPONENTS; 72 73 { 74 while (my ($name, $spec) = each %COMPONENTS ) { 75 has $name => %$spec; 76 } 77 } 78 79 has 'ua' => ( 80 is => 'rw', 81 isa => 'LWP::UserAgent', 82 required => 1, 83 lazy => 1, 84 default => sub { $USER_AGENT ||= LWP::UserAgent->new() } 29 85 ); 30 86 31 32 use constant API_URI => 'http://chart.apis.google.com/chart?'; 33 34 35 sub make_obj { 87 __PACKAGE__->meta->make_immutable; 88 89 no 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 96 sub as_uri { 36 97 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/&/&/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 } 108 118 109 119 sub render { 110 120 my $self = shift; 111 my $response = $self->ua->get($self-> get_url);121 my $response = $self->ua->get($self->as_uri); 112 122 113 123 if ($response->is_success) { … … 118 128 } 119 129 120 121 130 sub render_to_file { 122 131 my ($self, $filename) = @_; … … 127 136 } 128 137 129 130 138 1; 131 139 132 133 140 __END__ 134 141 135 {% USE p = PodGenerated %} 142 =encoding UTF-8 136 143 137 144 =head1 NAME 138 145 139 {% p.package %} - Draw a chart with Google Chart 146 Google::Chart - Interface to Google Charts API 140 147 141 148 =head1 SYNOPSIS 142 149 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 163 Google::Chart provides a Perl Interface to Google Charts API 164 (http://code.google.com/apis/chart/). 165 166 Please note that version 0.05000 is a major rewrite, and has little to no 167 backwards compatibility. 172 168 173 169 =head1 METHODS 174 170 171 =head2 new(%args) 172 175 173 =over 4 176 174 177 {% p.write_methods %} 175 =item type 176 177 Specifies 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 179 invoking argument-less constructor. 180 181 If you want to pass parameters to the constructor, either pass in an 182 already instanstiated object, or pass in a hash, which will be coerced to 183 the 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 196 Specifies the chart size. Strings like "400x300", hash references, or already 197 instantiated 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 212 Specifies the markers that go on line charts. 213 214 =item axis 215 216 Specifies the axis labels and such that go on line and bar charts 178 217 179 218 =back 180 219 181 {% p.write_inheritance %} 182 183 {% PROCESS standard_pod %} 184 220 =head2 as_uri() 221 222 Returns the URI that represents the chart object. 223 224 =head2 render() 225 226 Generates the chart image, and returns the contents. 227 228 =head2 render_to_file( %args ) 229 230 Generates the chart, and writes the contents out to the file specified by 231 `filename' parameter 232 233 =head1 FEEDBACK 234 235 We don't believe that we fully utilize Google Chart's abilities. So there 236 might be things missing, things that should be changed for easier use. 237 If you find any such case, PLEASE LET US KNOW! Suggestions are welcome, but 238 code snippets, pseudocode, or even better, test cases, are most welcome. 239 240 =head1 TODO 241 242 =over 4 243 244 =item Standardize Interface 245 246 Objects 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 251 There must be an easy way to just plug it in. 252 253 =item Moose-ish Errors 254 255 I've been reported that some Moose-related errors occur on certain platforms. 256 I have not been able to reproduce it myself, so if you do, please let me 257 know. 258 259 =back 260 261 =head1 AUTHORS 262 263 Daisuke Maki C<< <daisuke@endeworks.jp> >> (current maintainer) 264 265 Nobuo Danjou C<< <nobuo.danjou@gmail.com> >> 266 267 Marcel Grünauer C<< <marcel@cpan.org> >> (original author) 268 269 =head1 LICENSE 270 271 This program is free software; you can redistribute it and/or modify it 272 under the same terms as Perl itself. 273 274 See http://www.perl.com/perl/misc/Artistic.html 185 275 =cut 186 -
lang/perl/Google-Chart/trunk/lib/Google/Chart/Color.pm
r9832 r16838 1 1 package Google::Chart::Color; 2 use Moose; 3 use Moose::Util::TypeConstraints; 2 4 3 use strict; 4 use warnings; 5 use constant parameter_name => 'chco'; 5 6 7 with 'Google::Chart::QueryComponent::Simple'; 6 8 7 our $VERSION = '0.04'; 9 coerce 'Google::Chart::Color' 10 => from 'ArrayRef' 11 => via { 12 Google::Chart::Color->new(values => $_); 13 } 14 ; 15 coerce 'Google::Chart::Color' 16 => from 'HashRef' 17 => via { 18 Google::Chart::Color->new(%{$_}); 19 } 20 ; 21 coerce 'Google::Chart::Color' 22 => from 'Str' 23 => via { 24 Google::Chart::Color->new(values => [$_]); 25 } 26 ; 8 27 28 subtype 'Google::Chart::Color::Data' 29 => as 'Str' 30 => where { /^[a-f0-9]{6}/i } 31 ; 9 32 10 use base qw(Google::Chart::Base); 33 subtype 'Google::Chart::Color::DataList' 34 => as 'ArrayRef[Google::Chart::Color::Data]' 35 ; 11 36 37 coerce 'Google::Chart::Color::DataList' 38 => from 'Str' 39 => via { [ $_ ] } 40 ; 12 41 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, 42 has 'values' => ( 43 is => 'rw', 44 isa => 'Google::Chart::Color::DataList', 45 coerce => 1, 46 required => 1, 47 default => sub { +[] } 21 48 ); 22 49 50 __PACKAGE__->meta->make_immutable; 23 51 24 sub new_from_rgbt { 25 my ($class, $rgbt) = @_; 26 my $self = $class->new; 27 $self->rgbt($rgbt);28 $self;52 no Moose; 53 54 sub parameter_value { 55 my $self = shift; 56 join(',', @{ $self->values }); 29 57 } 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 chaining49 } 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 chaining69 } else {70 my $to_hex = sub { substr sprintf('0%x', shift), -2 };71 my $value = uc72 join '' =>73 map { $to_hex->($self->$_) }74 qw(red green blue);75 $value .= $to_hex->($self->transparency) if76 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 chaining92 }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 $k130 }131 132 58 133 59 1; 134 60 135 136 61 __END__ 137 138 {% USE p = PodGenerated %}139 62 140 63 =head1 NAME 141 64 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 %} 65 Google::Chart::Color - Google::Chart Color 171 66 172 67 =cut 173 -
lang/perl/Google-Chart/trunk/lib/Google/Chart/Data.pm
r9832 r16838 1 # $Id$ 2 1 3 package Google::Chart::Data; 4 use Moose::Role; 2 5 3 use strict; 4 use warnings; 6 use constant parameter_name => 'chd'; 5 7 8 with 'Google::Chart::QueryComponent::Simple'; 6 9 7 our $VERSION = '0.04'; 10 has 'dataset' => ( 11 is => 'rw', 12 isa => 'ArrayRef', 13 required => 1, 14 default => sub { +[] } 15 ); 8 16 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 17 no Moose; 37 18 38 19 1; 39 20 40 41 21 __END__ 42 43 {% USE p = PodGenerated %}44 22 45 23 =head1 NAME 46 24 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 %} 25 Google::Chart::Data - Google::Chart Data Role 76 26 77 27 =cut 78 -
lang/perl/Google-Chart/trunk/lib/Google/Chart/Size.pm
r9832 r16838 1 # $Id$ 2 1 3 package Google::Chart::Size; 4 use Moose; 5 use Moose::Util::TypeConstraints; 6 use Google::Chart::Types qw(hash_coercion); 2 7 3 use strict; 4 use warnings; 8 use constant parameter_name => 'chs'; 5 9 10 with 'Google::Chart::QueryComponent::Simple'; 6 11 7 our $VERSION = '0.04'; 12 coerce 'Google::Chart::Size' 13 => from 'Str' 14 => via { 15 if (! /^(\d+)x(\d+)$/) { 16 confess "Could not parse $_ as size"; 17 } 8 18 19 return Google::Chart::Size->new(width => $1, height => $2); 20 } 21 ; 9 22 10 use base qw(Google::Chart::Base); 23 coerce 'Google::Chart::Size' 24 => from 'HashRef' 25 => hash_coercion( prefix => 'Google::Chart::Size', default => '+Google::Chart::Size' ) 26 ; 11 27 28 has 'width' => ( 29 is => 'rw', 30 isa => 'Int', 31 required => 1 32 ); 12 33 13 __PACKAGE__->mk_scalar_accessors(qw(x y)); 34 has 'height' => ( 35 is => 'rw', 36 isa => 'Int', 37 required => 1 38 ); 14 39 40 no Moose; 15 41 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; 42 sub parameter_value { 43 my $self = shift; 44 return join('x', $self->width, $self->height); 50 45 } 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 64 46 65 47 1; 66 48 67 68 49 __END__ 69 70 {% USE p = PodGenerated %}71 50 72 51 =head1 NAME 73 52 74 {% p.package %} - Draw a chart with Google Chart 53 Google::Chart::Size - Google::Chart Size Specification 75 54 76 55 =head1 SYNOPSIS 77 56 78 {% p.package %}->new; 57 Google::Chart->new( 58 size => "400x300" 59 ) 79 60 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 ) 91 67 92 68 =head1 METHODS 93 69 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 103 71 104 72 =cut 105 -
lang/perl/Google-Chart/trunk/lib/Google/Chart/Type.pm
r9832 r16838 1 # $Id$ 2 1 3 package Google::Chart::Type; 4 use Moose::Role; 2 5 3 use strict; 4 use warnings; 6 with 'Google::Chart::QueryComponent'; 5 7 6 7 our $VERSION = '0.04'; 8 9 10 use base qw(Google::Chart::Base); 11 12 13 use constant has_content => 1; 14 8 no Moose; 15 9 16 10 1; 17 11 18 19 12 __END__ 20 21 {% USE p = PodGenerated %}22 13 23 14 =head1 NAME 24 15 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 %} 16 Google::Chart::Type - Google::Chart Type Role 46 17 47 18 =cut 48 -
lang/perl/Google-Chart/trunk/lib/Google/Chart/Type/Bar.pm
r9832 r16838 1 # $Id$ 2 1 3 package Google::Chart::Type::Bar; 4 use Moose; 5 use Moose::Util::TypeConstraints; 2 6 3 use strict; 4 use warnings; 7 with 'Google::Chart::Type::Simple'; 5 8 9 enum 'Google::Chart::Type::Bar::Orientation' => qw(horizontal vertical); 6 10 7 our $VERSION = '0.04'; 11 has 'colored' => ( 12 is => 'rw', 13 isa => 'Bool', 14 required => 1, 15 default => 0, 16 ); 8 17 18 has 'orientation' => ( 19 is => 'rw', 20 isa => 'Google::Chart::Type::Bar::Orientation', 21 required => 1, 22 default => 'vertical', 23 ); 9 24 10 use base qw(Google::Chart::Type);25 __PACKAGE__->meta->make_immutable; 11 26 27 no Moose; 28 29 sub 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 } 12 37 13 38 1; 14 39 15 16 40 __END__ 17 18 {% USE p = PodGenerated %}19 41 20 42 =head1 NAME 21 43 22 {% p.package %} - Draw a chart with Google Chart 44 Google::Chart::Type::Bar - Google::Chart Bar Type 23 45 24 46 =head1 SYNOPSIS 25 47 26 {% p.package %}->new; 48 Google::Chart->new( 49 type => { 50 module => "Bar", 51 orientation => "horizontal", 52 } 53 ); 27 54 28 =head1 WARNING55 =head1 METHODS 29 56 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 43 58 44 59 =cut 45 -
lang/perl/Google-Chart/trunk/lib/Google/Chart/Type/Line.pm
r9832 r16838 1 # $Id$ 2 1 3 package Google::Chart::Type::Line; 4 use Moose; 5 use constant parameter_value => 'lc'; 2 6 3 use strict; 4 use warnings; 7 with 'Google::Chart::Type::Simple'; 5 8 6 7 our $VERSION = '0.04'; 8 9 10 use base qw(Google::Chart::Type); 11 9 no Moose; 12 10 13 11 1; 14 12 15 16 13 __END__ 17 18 {% USE p = PodGenerated %}19 14 20 15 =head1 NAME 21 16 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 %} 17 Google::Chart::Type::Line - Google::Chart Line Type 43 18 44 19 =cut 45 -
lang/perl/Google-Chart/trunk/lib/Google/Chart/Type/Pie.pm
r9832 r16838 1 # $Id$ 2 1 3 package Google::Chart::Type::Pie; 4 use Moose; 5 use Moose::Util::TypeConstraints; 2 6 3 use strict; 4 use warnings; 7 with 'Google::Chart::Type::Simple'; 5 8 9 has 'pie_type' => ( 10 is => 'rw', 11 isa => enum([ qw(2d 3d) ]), 12 required => 1, 13 default => '2d' 14 ); 6 15 7 our $VERSION = '0.04';16 __PACKAGE__->meta->make_immutable; 8 17 18 no Moose; 9 19 10 use base qw(Google::Chart::Type); 20 sub parameter_value { 21 my $self = shift; 11 22 23 return $self->pie_type eq '3d' ? 'p3' : 'p'; 24 } 12 25 13 26 1; 14 27 15 16 28 __END__ 17 18 {% USE p = PodGenerated %}19 29 20 30 =head1 NAME 21 31 22 {% p.package %} - Draw a chart with Google Chart 32 Google::Chart::Type::Pie - Google::Chart Pie Chart Type 23 33 24 34 =head1 SYNOPSIS 25 35 26 {% p.package %}->new; 36 Google::Chart->new( 37 type => 'Pie' 38 ); 27 39 28 =head1 WARNING 40 Google::Chart->new( 41 type => { 42 module => 'Pie', 43 args => { 44 pie_type => '3d' 45 } 46 } 47 ); 29 48 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 34 50 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 43 52 44 53 =cut 45 -
lang/perl/Google-Chart/trunk/lib/Google/Chart/Type/ScatterPlot.pm
r9832 r16838 1 # $Id$ 2 1 3 package Google::Chart::Type::ScatterPlot; 4 use Moose; 5 use constant parameter_value => 's'; 2 6 3 use strict; 4 use warnings; 7 with 'Google::Chart::Type::Simple'; 5 8 9 __PACKAGE__->meta->make_immutable; 6 10 7 our $VERSION = '0.04'; 8 9 10 use base qw(Google::Chart::Type); 11 12 13 use constant as_string => 'cht=s'; 14 11 no Moose; 15 12 16 13 1; 17 14 18 19 15 __END__ 20 16 21 {% USE p = PodGenerated %} 17 =head1 NAME 22 18 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 %} 19 Google::Chart::Type::ScatterPlot - Google::Chart ScatterPlot Type 46 20 47 21 =cut 48 -
lang/perl/Google-Chart/trunk/lib/Google/Chart/Type/Venn.pm
r9832 r16838 1 # $Id$ 2 1 3 package Google::Chart::Type::Venn; 4 use Moose; 2 5 3 use strict; 4 use warnings; 6 use constant parameter_value => 'v'; 5 7 8 with 'Google::Chart::Type::Simple'; 6 9 7 our $VERSION = '0.04';10 __PACKAGE__->meta->make_immutable; 8 11 9 10 use base qw(Google::Chart::Type); 11 12 13 use constant as_string => 'cht=v'; 14 12 no Moose; 15 13 16 14 1; 17 15 18 19 16 __END__ 20 17 21 {% USE p = PodGenerated %} 18 =head1 NAME 22 19 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 %} 20 Google::Chart::Type::Venn - Google::Chart Venn Type 46 21 47 22 =cut 48
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)