| 1 | package SVG::Timeline::Compact::Event; | ||||||||||||||||||
| 2 | |||||||||||||||||||
| 3 | # ABSTRACT: Event Container for SVG::Timeline::Compact | ||||||||||||||||||
| 4 | |||||||||||||||||||
| 5 | 1 | ▶ | use DateTime; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 6 | 1 | ▶ | use DateTime::Duration; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 7 | 1 | ▶ | use v5.10; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 8 | 1 | ▶ | use Moose; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 9 | |||||||||||||||||||
| 10 | |||||||||||||||||||
| 11 | 1 | has resolution=>(is=>'rw',isa=>'DateTime::Duration'); | |||||||||||||||||
| 12 | 1 | has id =>(is=>'rw',isa=>'Int'); | |||||||||||||||||
| 13 | 1 | has origin=>(is=>'rw',isa=>'DateTime'); | |||||||||||||||||
| 14 | 1 | has start =>(is=>'ro',isa=>'DateTime'); | |||||||||||||||||
| 15 | 1 | has end=>(is=>'ro',isa=>'DateTime'); | |||||||||||||||||
| 16 | 1 | has name =>(is=>'ro'); | |||||||||||||||||
| 17 | 1 | has tooltip =>(is=>'ro'); | |||||||||||||||||
| 18 | 1 | has color =>(is=>'ro', isa=>"Str"); | |||||||||||||||||
| 19 | 1 | has min_width =>(is=>'ro',isa=>'Int'); | |||||||||||||||||
| 20 | 1 | has _start =>(is=>'rw',isa=>'DateTime'); | |||||||||||||||||
| 21 | 1 | has _width =>(is=>'rw',isa=>'Int'); | |||||||||||||||||
| 22 | 75 | ▶ | sub x0{ | ||||||||||||||||
|
Subroutine
x0: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||
| 23 | 75 | my $self=shift; | |||||||||||||||||
| 24 | 75 | return $self->distance($self->origin,$self->start,0); | |||||||||||||||||
| 25 | } | ||||||||||||||||||
| 26 | 43 | ▶ | sub width{ | ||||||||||||||||
|
Subroutine
width: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||
| 27 | 43 | my $self=shift; | |||||||||||||||||
| 28 | #p $self->start; | ||||||||||||||||||
| 29 | #p $self->end; | ||||||||||||||||||
| 30 | 43 | my $width= $self->distance($self->start,$self->end); | |||||||||||||||||
| 31 | #p $self->resolution; | ||||||||||||||||||
| 32 | #p $width; | ||||||||||||||||||
| 33 | 43 | return $width; | |||||||||||||||||
| 34 | |||||||||||||||||||
| 35 | } | ||||||||||||||||||
| 36 | 118 | ▶ | sub distance { | ||||||||||||||||
|
Subroutine
distance: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||
| 37 | 118 | my ($self,$start,$end,$minwidth)=@_; | |||||||||||||||||
| 38 | 118 | ▶ | $minwidth=$self->min_width if !defined $minwidth; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 39 | 118 | my $dist=$end -$start;#/$self->resolution ; | |||||||||||||||||
| 40 | #p $dist; #mon day min sec | ||||||||||||||||||
| 41 | 118 | my $retval=$self->_get_scaled($dist); | |||||||||||||||||
| 42 | |||||||||||||||||||
| 43 | 118 | ▶ | $retval=$minwidth if $retval<$minwidth; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 44 | 118 | return $retval; | |||||||||||||||||
| 45 | } | ||||||||||||||||||
| 46 | 118 | ▶ | sub _get_scaled{ | ||||||||||||||||
|
Subroutine
_get_scaled: called CC=4 SCAR=16.6
| |||||||||||||||||||
| 47 | 118 | my ($self,$distance)=@_; | |||||||||||||||||
| 48 | 118 | my $duration=$self->resolution; | |||||||||||||||||
| 49 | 118 | my $weeks=$distance->in_units('months')*5 +$duration->in_units('weeks'); | |||||||||||||||||
| 50 | 118 | my $days=$distance->in_units('months')*30 +$duration->in_units('days'); | |||||||||||||||||
| 51 | 118 | my $minutes=$days*24*60+$distance->in_units('minutes'); | |||||||||||||||||
| 52 | #p $minutes; | ||||||||||||||||||
| 53 | 118 | my $scale; | |||||||||||||||||
| 54 | 118 | ▶ | if ($duration->in_units('months')>0){ | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 55 | 0 | $scale=POSIX::ceil($duration->in_units('months')); | |||||||||||||||||
| 56 | 0 | return $distance->in_units('months')/$scale; | |||||||||||||||||
| 57 | }elsif ($duration->in_units('days')>0){ | ||||||||||||||||||
| 58 | 0 | $scale=POSIX::ceil($duration->in_units('days')); | |||||||||||||||||
| 59 | 0 | return $days/$scale; | |||||||||||||||||
| 60 | }elsif ($duration->in_units('minutes')>0){ | ||||||||||||||||||
| 61 | 118 | $scale=POSIX::ceil($duration->in_units('minutes')); | |||||||||||||||||
| 62 | 118 | return $minutes/$scale; | |||||||||||||||||
| 63 | }else{ | ||||||||||||||||||
| 64 | 0 | print STDERR "Error Parsing Duration"; | |||||||||||||||||
| 65 | 0 | return $0; | |||||||||||||||||
| 66 | } | ||||||||||||||||||
| 67 | } | ||||||||||||||||||
| 68 | 1 | 1; | |||||||||||||||||
| 69 | |||||||||||||||||||
| 70 | __END__ | ||||||||||||||||||