| 1 | package Chart::Clicker::Axis::DateTime; | ||||||||||||||||||||||||||||
| 2 | 2 | $Chart::Clicker::Axis::DateTime::VERSION = '2.89'; | |||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | # ABSTRACT: An X or Y Axis using DateTime | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Chart::Clicker::Data::Marker; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use DateTime; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use DateTime::Set; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Graphics::Color::RGB; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 2 | extends 'Chart::Clicker::Axis'; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 2 | has 'format' => ( | |||||||||||||||||||||||||||
| 17 | is => 'rw', | ||||||||||||||||||||||||||||
| 18 | isa => 'Str' | ||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 2 | has 'time_zone' => ( | |||||||||||||||||||||||||||
| 23 | is => 'rw', | ||||||||||||||||||||||||||||
| 24 | isa => 'Str' | ||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | override 'prepare' => sub { | ||||||||||||||||||||||||||||
| 28 | 0 | ▶ | my ($self, $driver) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | my ($dstart, $dend); | |||||||||||||||||||||||||||
| 31 | 0 | eval { | |||||||||||||||||||||||||||
| 32 | 0 | $dstart = DateTime->from_epoch(epoch => $self->range->lower); | |||||||||||||||||||||||||||
| 33 | 0 | $dend = DateTime->from_epoch(epoch => $self->range->upper); | |||||||||||||||||||||||||||
| 34 | }; | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | if(!defined($dstart) || !defined($dend)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $dstart and defined $dend
MC/DC0%0/2
defined $dstart and defined $dend
defined $dstart
defined $dend
Truth table0%0/3
A and B
A= defined $dstartB= defined $dend
| |||||||||||||||||||||||||||||
| 37 | 0 | $dstart = DateTime->now; | |||||||||||||||||||||||||||
| 38 | 0 | $dend = DateTime->now; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | my $dur = $dend - $dstart; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | unless(defined($self->format) && length($self->format)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->format and length $self->format
MC/DC0%0/2
defined $self->format and length $self->format
defined $self->format
length $self->format
Truth table0%0/3
A and B
A= defined $self->formatB= length $self->format
| |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if($dur->years) { | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 45 | 0 | $self->format('%b %Y'); | |||||||||||||||||||||||||||
| 46 | } elsif($dur->months) { | ||||||||||||||||||||||||||||
| 47 | 0 | $self->format('%d'); | |||||||||||||||||||||||||||
| 48 | } elsif($dur->weeks) { | ||||||||||||||||||||||||||||
| 49 | 0 | $self->format('%d'); | |||||||||||||||||||||||||||
| 50 | } elsif($dur->days) { | ||||||||||||||||||||||||||||
| 51 | 0 | $self->format('%m/%d %H:%M'); | |||||||||||||||||||||||||||
| 52 | } else { | ||||||||||||||||||||||||||||
| 53 | 0 | $self->format('%H:%M'); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | super; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | my $clicker = shift; | |||||||||||||||||||||||||||
| 60 | 0 | ▶ | if(!defined($clicker)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | die('No clicker?') | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | # my @markers = @{ $clicker->markers }; | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | my $set = DateTime::Span->from_datetimes( | |||||||||||||||||||||||||||
| 67 | start => $dstart, end => $dend | ||||||||||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | my $linecolor = Graphics::Color::RGB->new({ | |||||||||||||||||||||||||||
| 71 | red => 0, green => 0, blue => 0, alpha => .35 | ||||||||||||||||||||||||||||
| 72 | }); | ||||||||||||||||||||||||||||
| 73 | 0 | my $fillcolor = Graphics::Color::RGB->new({ | |||||||||||||||||||||||||||
| 74 | red => 0, green => 0, blue => 0, alpha => .10 | ||||||||||||||||||||||||||||
| 75 | }); | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # my @dmarkers; | ||||||||||||||||||||||||||||
| 78 | # my $day = $set->start->truncate(to => 'day'); | ||||||||||||||||||||||||||||
| 79 | # | ||||||||||||||||||||||||||||
| 80 | # my $dayval; | ||||||||||||||||||||||||||||
| 81 | # while($day < $set->end) { | ||||||||||||||||||||||||||||
| 82 | # if($set->contains($day)) { | ||||||||||||||||||||||||||||
| 83 | # if(defined($dayval)) { | ||||||||||||||||||||||||||||
| 84 | # push(@dmarkers, | ||||||||||||||||||||||||||||
| 85 | # Chart::Clicker::Data::Marker->new({ | ||||||||||||||||||||||||||||
| 86 | # key => $dayval, | ||||||||||||||||||||||||||||
| 87 | # key2 => $day->epoch, | ||||||||||||||||||||||||||||
| 88 | # color => $linecolor, | ||||||||||||||||||||||||||||
| 89 | # inside_color=> $fillcolor, | ||||||||||||||||||||||||||||
| 90 | # }) | ||||||||||||||||||||||||||||
| 91 | # ); | ||||||||||||||||||||||||||||
| 92 | # $dayval = undef; | ||||||||||||||||||||||||||||
| 93 | # } else { | ||||||||||||||||||||||||||||
| 94 | # $dayval = $day->epoch; | ||||||||||||||||||||||||||||
| 95 | # } | ||||||||||||||||||||||||||||
| 96 | # } | ||||||||||||||||||||||||||||
| 97 | # $day = $day->add(days => 1); | ||||||||||||||||||||||||||||
| 98 | # } | ||||||||||||||||||||||||||||
| 99 | # if($dayval) { | ||||||||||||||||||||||||||||
| 100 | # push(@dmarkers, | ||||||||||||||||||||||||||||
| 101 | # Chart::Clicker::Data::Marker->new({ | ||||||||||||||||||||||||||||
| 102 | # key => $dayval, | ||||||||||||||||||||||||||||
| 103 | # key2 => $day->epoch, | ||||||||||||||||||||||||||||
| 104 | # color => $linecolor, | ||||||||||||||||||||||||||||
| 105 | # inside_color=> $fillcolor, | ||||||||||||||||||||||||||||
| 106 | # }) | ||||||||||||||||||||||||||||
| 107 | # ); | ||||||||||||||||||||||||||||
| 108 | # } | ||||||||||||||||||||||||||||
| 109 | # | ||||||||||||||||||||||||||||
| 110 | # push(@dmarkers, @markers); | ||||||||||||||||||||||||||||
| 111 | # $clicker->markers(\@dmarkers); | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 0 | return 1; | |||||||||||||||||||||||||||
| 114 | 2 | }; | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | sub format_value { | ||||||||||||||||||||||||||||
| 118 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
format_value: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 119 | 2 | my $value = shift; | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 2 | my %dtargs = ( | |||||||||||||||||||||||||||
| 122 | 'epoch' => $value | ||||||||||||||||||||||||||||
| 123 | ); | ||||||||||||||||||||||||||||
| 124 | 2 | ▶ | if($self->time_zone) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 1 | $dtargs{'time_zone'} = $self->time_zone; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | 2 | my $dt = DateTime->from_epoch(%dtargs); | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 2 | return $dt->strftime($self->format); | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 2 | ▶ | no Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 2 | 1; | |||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | __END__ | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | =pod | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | =head1 NAME | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | Chart::Clicker::Axis::DateTime - An X or Y Axis using DateTime | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | =head1 VERSION | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | version 2.89 | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | my $axis = Chart::Clicker::Axis::DateTime->new; | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | A temporal Axis. Requires L<DateTime> and L<DateTime::Set>. Inherits from | ||||||||||||||||||||||||||||
| 157 | Axis, so check the methods there as well. Expects that times will be in | ||||||||||||||||||||||||||||
| 158 | unix format. | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | =head2 format | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | Set/Get the formatting string used to format the DateTime. See DateTime's | ||||||||||||||||||||||||||||
| 165 | strftime. | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | =head2 time_zone | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | Set/Get the time zone to use when creating DateTime objects! Accepts an | ||||||||||||||||||||||||||||
| 170 | object or a string ('America/Chicago'). | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | =head1 METHODS | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | =head2 format_value | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | Formats the value using L<DateTime>'s strftime. | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | Cory G Watson <gphat@cpan.org> | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | This software is copyright (c) 2016 by Cory G Watson. | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 187 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | =cut | ||||||||||||||||||||||||||||