| 1 | package Google::Chart::WithRangeMarker; | ||
| 2 | use Moose::Role; | ||
| 3 | use namespace::clean -except => qw(meta); | ||
| 4 | |||
| 5 | has range_markers => ( | ||
| 6 | is => 'ro', | ||
| 7 | isa => 'ArrayRef', | ||
| 8 | lazy_build => 1, | ||
| 9 | ); | ||
| 10 | |||
| 11 | sub _build_range_markers { [] } | ||
| 12 | |||
| 13 | sub add_range_marker { | ||
| 14 | my ($self, @args) = @_; | ||
| 15 | push @{ $self->range_markers }, | ||
| 16 | Google::Chart::RangeMarker->new(@args); | ||
| 17 | return $self; | ||
| 18 | } | ||
| 19 | |||
| 20 | around prepare_query => sub { | ||
| 21 | my ($next, $self, @args) = @_; | ||
| 22 | |||
| 23 | my @query = $next->($self, @args); | ||
| 24 | my $markers = $self->range_markers; | ||
| 25 | my $max = scalar @$markers - 1; | ||
| 26 | |||
| 27 | my @chm; | ||
| 28 | for my $i (0..$max) { | ||
| 29 | my $marker = $markers->[$i]; | ||
| 30 | push @chm, join(',', | ||
| 31 | ($marker->orientation || '') eq 'vertical' ? 'R' : 'r', | ||
| 32 | $marker->color, | ||
| 33 | 0, | ||
| 34 | $marker->start, | ||
| 35 | $marker->end, | ||
| 36 | ); | ||
| 37 | } | ||
| 38 | |||
| 39 | if (@chm) { | ||
| 40 | push @query, (chm => join('|', @chm)); | ||
| 41 | } | ||
| 42 | |||
| 43 | return @query; | ||
| 44 | }; | ||
| 45 | |||
| 46 | package Google::Chart::RangeMarker; | ||
| 47 | use Moose; | ||
| 48 | use Moose::Util::TypeConstraints; | ||
| 49 | use namespace::clean -except => qw(meta); | ||
| 50 | |||
| 51 | has orientation => ( | ||
| 52 | is => 'ro', | ||
| 53 | isa => enum([ qw(horizontal vertical) ]), | ||
| 54 | predicate => 'has_orientation', | ||
| 55 | ); | ||
| 56 | |||
| 57 | has color => ( | ||
| 58 | is => 'ro', | ||
| 59 | isa => 'Str', | ||
| 60 | predicate => 'has_color', | ||
| 61 | ); | ||
| 62 | |||
| 63 | has start => ( | ||
| 64 | is => 'ro', | ||
| 65 | isa => 'Num', | ||
| 66 | predicate => 'has_start', | ||
| 67 | ); | ||
| 68 | |||
| 69 | has end => ( | ||
| 70 | is => 'ro', | ||
| 71 | isa => 'Num', | ||
| 72 | predicate => 'has_end', | ||
| 73 | ); | ||
| 74 | |||
| 75 | __PACKAGE__->meta->make_immutable(); | ||
| 76 | |||
| 77 | 1; |