Changeset 17807 for lang

Show
Ignore:
Timestamp:
08/18/08 01:06:51 (5 years ago)
Author:
lopnor
Message:

lang/perl/Google-Chart: multiple marker support. not tested well yet.

Location:
lang/perl/Google-Chart/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Google-Chart/trunk/lib/Google/Chart/Color.pm

    r16838 r17807  
    2828subtype 'Google::Chart::Color::Data' 
    2929    => as 'Str' 
    30     => where { /^[a-f0-9]{6}/i } 
     30    => where { /^[a-f0-9]{6}$/i } 
    3131; 
    3232 
  • lang/perl/Google-Chart/trunk/lib/Google/Chart/Grid.pm

    r17789 r17807  
    5151sub parameter_value { 
    5252    my $self = shift; 
    53     return join(',',  
    54         $self->x_step_size, 
    55         $self->y_step_size, 
    56         $self->line_length, 
    57         $self->blank_length, 
    58     ); 
     53    return join(',', map { $self->$_ } qw(x_step_size y_step_size line_length blank_length)); 
    5954} 
    6055 
  • lang/perl/Google-Chart/trunk/lib/Google/Chart/Marker.pm

    r16838 r17807  
    44use Moose; 
    55use Moose::Util::TypeConstraints; 
    6 use Google::Chart::Types; 
    7 use Google::Chart::Color; 
    86 
    97use constant parameter_name => 'chm'; 
     
    119with 'Google::Chart::QueryComponent::Simple'; 
    1210 
    13 enum 'Google::Chart::Marker::Type' => ( 
     11has 'markerset' => ( 
     12    is => 'rw', 
     13    isa => 'ArrayRef[Google::Chart::Marker::Item]', 
     14    required => 1, 
     15    default => sub {  
     16        [ Google::Chart::Marker::Item->new ] ; 
     17    } 
     18); 
     19 
     20__PACKAGE__->meta->make_immutable; 
     21 
     22no Moose; 
     23 
     24sub BUILDARGS { 
     25    my $self = shift; 
     26    my @markerset; 
     27    my @markerargs; 
     28    my %args; 
     29 
     30    if (@_ == 1 && ref $_[0] eq 'ARRAY') { 
     31        @markerargs = @{$_[0]}; 
     32    } else { 
     33        %args = @_; 
     34        my $arg = delete $args{markerset}; 
     35        if (ref $arg eq 'ARRAY') { 
     36            @markerargs = @{ $arg }; 
     37        } elsif (ref $arg eq 'HASH') { 
     38            @markerargs = ( $arg ); 
     39        } 
     40    } 
     41 
     42 
     43    @markerargs = ( {} ) unless @markerargs; 
     44 
     45    foreach my $marker ( @markerargs ) { 
     46        if (! blessed $marker) { 
     47            $marker = Google::Chart::Marker::Item->new($marker) 
     48        } 
     49        push @markerset, $marker; 
     50    } 
     51 
     52    return { %args, markerset => \@markerset }; 
     53} 
     54 
     55sub parameter_value { 
     56    my $self = shift; 
     57    return join ('|', 
     58        map {$_->as_string} @{$self->markerset} 
     59    ); 
     60} 
     61 
     62package # hide from PAUSE 
     63    Google::Chart::Marker::Item; 
     64use Moose; 
     65use Moose::Util::TypeConstraints; 
     66use Google::Chart::Types; 
     67use Google::Chart::Color; 
     68 
     69coerce 'Google::Chart::Marker::Item' 
     70    => from 'HashRef' 
     71    => via { 
     72        Google::Chart::Marker::Item->new(%{$_}); 
     73    } 
     74; 
     75 
     76coerce 'Google::Chart::Marker::Item' 
     77    => from 'ArrayRef' 
     78    => via { 
     79        Google::Chart::Marker::Item->new(%{$_}); 
     80    } 
     81; 
     82 
     83enum 'Google::Chart::Marker::Item::Type' => ( 
    1484    'a', # arrow 
    1585    'c', # corrs 
     
    2696has 'marker_type' => ( 
    2797    is => 'rw', 
    28     isa => 'Google::Chart::Marker::Type', 
     98    isa => 'Google::Chart::Marker::Item::Type', 
    2999    required => 1, 
    30100    default => 'o' 
     
    35105    isa => 'Google::Chart::Color::Data', 
    36106    required => 1, 
    37     default => '000000', 
     107    default => '333333', 
    38108); 
    39109 
     
    54124has 'size' => ( 
    55125    is => 'rw', 
    56     isa => 'Int', 
     126    isa => 'Num', 
    57127    required => 1, 
    58128    default => 5, 
     
    66136); 
    67137 
     138__PACKAGE__->meta->make_immutable; 
     139 
    68140no Moose; 
    69141 
    70 sub parameter_value { 
     142sub as_string { 
    71143    my $self = shift; 
    72144 
  • lang/perl/Google-Chart/trunk/t/02_marker.t

    r16838 r17807  
    11use strict; 
    2 use Test::More (tests => 10); 
     2use Test::More (tests => 13); 
    33 
    44BEGIN 
     
    1111    ok($marker); 
    1212    isa_ok($marker, "Google::Chart::Marker"); 
    13     is( $marker->marker_type, 'o' ); 
    14     is( $marker->color, "000000" ); 
    15     is( $marker->dataset, 0 ); 
    16     is( $marker->datapoint, -1 ); 
    17     is( $marker->size, 5 ); 
    18     is( $marker->priority, 0 ); 
    1913 
    20     is( $marker->as_query, "chm=o%2C000000%2C0%2C-1%2C5%2C0" ); 
     14    is( $marker->as_query, "chm=o%2C333333%2C0%2C-1%2C5%2C0" ); 
    2115} 
     16 
     17{ 
     18    my $data = Google::Chart::Marker::Item->new( 
     19        marker_type => 'h', 
     20        color => '999999', 
     21        datapoint => '0.3', 
     22        size => '0.5', 
     23    ); 
     24    ok($data); 
     25    isa_ok($data, 'Google::Chart::Marker::Item'); 
     26    is ($data->as_string, 'h,999999,0,0.3,0.5,0'); 
     27} 
     28 
     29{ 
     30    my $marker = Google::Chart::Marker->new( 
     31        markerset =>  [ { 
     32            marker_type => 'h', 
     33            color => '999999', 
     34            datapoint => 0.3, 
     35            size => 0.5, 
     36        } ] 
     37    ); 
     38    ok($marker); 
     39    isa_ok($marker, "Google::Chart::Marker"); 
     40 
     41    is( $marker->as_query, "chm=h%2C999999%2C0%2C0.3%2C0.5%2C0" ); 
     42} 
     43{ 
     44    my $marker = Google::Chart::Marker->new( 
     45        markerset =>  { 
     46            marker_type => 'h', 
     47            color => '999999', 
     48            datapoint => 0.3, 
     49            size => 0.5, 
     50        } 
     51    ); 
     52    ok($marker); 
     53    isa_ok($marker, "Google::Chart::Marker"); 
     54 
     55    is( $marker->as_query, "chm=h%2C999999%2C0%2C0.3%2C0.5%2C0" ); 
     56}