line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
SVG::Timelime::Event - A single event in an SVG timeline. |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
See L<SVG::Timeline>. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=cut |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use 5.010; |
13
|
2
|
|
|
2
|
|
58
|
|
|
2
|
|
|
|
|
9
|
|
14
|
|
|
|
|
|
|
use Moose; |
15
|
2
|
|
|
2
|
|
17
|
use Moose::Util::TypeConstraints; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
17
|
|
16
|
2
|
|
|
2
|
|
15542
|
use DateTime::Format::Strptime; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
21
|
|
17
|
2
|
|
|
2
|
|
5755
|
|
|
2
|
|
|
|
|
1453095
|
|
|
2
|
|
|
|
|
12
|
|
18
|
|
|
|
|
|
|
coerce __PACKAGE__, |
19
|
|
|
|
|
|
|
from 'HashRef', |
20
|
|
|
|
|
|
|
via { __PACKAGE__->new($_) }; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Chosen format: yyyy-mm-dd |
23
|
|
|
|
|
|
|
subtype 'SVG::Timeline::DateStr', |
24
|
|
|
|
|
|
|
as 'Str', |
25
|
|
|
|
|
|
|
where { m/ \d{4}-\d{2}-\d{2} /ax }; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
subtype 'SVG::Timeline::YearMonthStr', |
28
|
|
|
|
|
|
|
as 'Str', |
29
|
|
|
|
|
|
|
where { m/ \d{4}-\d{2} /ax }; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
subtype 'SVG::Timeline::YearStr', |
32
|
|
|
|
|
|
|
as 'Str', |
33
|
|
|
|
|
|
|
where { m/ \d{4} /as }; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
subtype 'SVG::Timeline::Num', |
36
|
|
|
|
|
|
|
as 'Num'; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
coerce 'SVG::Timeline::DateStr', |
39
|
|
|
|
|
|
|
from 'SVG::Timeline::YearStr', |
40
|
|
|
|
|
|
|
via { $_ . '-01-01' }; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
coerce 'SVG::Timeline::DateStr', |
43
|
|
|
|
|
|
|
from 'SVG::Timeline::YearMonthStr', |
44
|
|
|
|
|
|
|
via { $_ . '-01' }; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
coerce 'SVG::Timeline::Num', |
47
|
|
|
|
|
|
|
from 'SVG::Timeline::DateStr', |
48
|
|
|
|
|
|
|
via \&str2num; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
has index => ( |
51
|
|
|
|
|
|
|
is => 'ro', |
52
|
|
|
|
|
|
|
isa => 'Int', |
53
|
|
|
|
|
|
|
required => 1, |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
has text => ( |
57
|
|
|
|
|
|
|
is => 'ro', |
58
|
|
|
|
|
|
|
isa => 'Str', |
59
|
|
|
|
|
|
|
required => 1, |
60
|
|
|
|
|
|
|
); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my ($datestr) = @_; |
63
|
|
|
|
|
|
|
|
64
|
2
|
|
|
2
|
0
|
21
|
my $date = DateTime::Format::Strptime->new( pattern => '%Y-%m-%d' ) |
65
|
|
|
|
|
|
|
->parse_datetime($datestr); |
66
|
2
|
|
|
|
|
12
|
|
67
|
|
|
|
|
|
|
return $date->year + ( $date->day_of_year / ($date->is_leap_year ? 366 : 365) ); |
68
|
|
|
|
|
|
|
} |
69
|
2
|
50
|
|
|
|
5058
|
|
70
|
|
|
|
|
|
|
has start => ( |
71
|
|
|
|
|
|
|
is => 'ro', |
72
|
|
|
|
|
|
|
isa => 'SVG::Timeline::Num', |
73
|
|
|
|
|
|
|
required => 1, |
74
|
|
|
|
|
|
|
coerce => 1, |
75
|
|
|
|
|
|
|
); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
has end => ( |
78
|
|
|
|
|
|
|
is => 'ro', |
79
|
|
|
|
|
|
|
isa => 'SVG::Timeline::Num', |
80
|
|
|
|
|
|
|
required => 1, |
81
|
|
|
|
|
|
|
coerce => 1, |
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
has colour => ( |
85
|
|
|
|
|
|
|
is => 'ro', |
86
|
|
|
|
|
|
|
isa => 'Maybe[Str]', |
87
|
|
|
|
|
|
|
required => 0, |
88
|
|
|
|
|
|
|
); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 METHODS |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 draw_on($tl) |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Draw the event inside the given timeline object. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my $self = shift; |
99
|
|
|
|
|
|
|
my ($tl) = @_; |
100
|
|
|
|
|
|
|
|
101
|
3
|
|
|
3
|
1
|
55
|
my $x = $self->start * $tl->units_per_year; |
102
|
3
|
|
|
|
|
8
|
my $y = ($tl->bar_height * $self->index) |
103
|
|
|
|
|
|
|
+ ($tl->bar_height * $tl->bar_spacing |
104
|
3
|
|
|
|
|
85
|
* ($self->index - 1)); |
105
|
3
|
|
|
|
|
74
|
|
106
|
|
|
|
|
|
|
$tl->rect( |
107
|
|
|
|
|
|
|
x => $x, |
108
|
|
|
|
|
|
|
y => $y, |
109
|
3
|
|
33
|
|
|
73
|
width => ($self->end - $self->start) * $tl->units_per_year, |
110
|
|
|
|
|
|
|
height => $tl->bar_height, |
111
|
|
|
|
|
|
|
fill => $self->colour // $tl->default_colour, |
112
|
|
|
|
|
|
|
stroke => $tl->bar_outline_colour, |
113
|
|
|
|
|
|
|
'stroke-width' => 1 |
114
|
|
|
|
|
|
|
); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
$tl->text( |
117
|
|
|
|
|
|
|
x => ($x + $tl->bar_height * 0.2), |
118
|
|
|
|
|
|
|
y => $y + $tl->bar_height * 0.8, |
119
|
3
|
|
|
|
|
366
|
'font-size' => $tl->bar_height * 0.8, |
120
|
|
|
|
|
|
|
)->cdata($self->text); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
no Moose; |
124
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
125
|
|
|
|
|
|
|
|
126
|
2
|
|
|
2
|
|
1256
|
=head1 AUTHOR |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
19
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Dave Cross <dave@perlhacks.com> |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENCE |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Copyright (c) 2017, Magnum Solutions Ltd. All Rights Reserved. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it |
135
|
|
|
|
|
|
|
under the same terms as Perl itself. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
1; |