Skip to content

Commit

Permalink
make years floating point to support greater granularity in dates and…
Browse files Browse the repository at this point in the history
… amend docs

Closes davorg-cpan#1
  • Loading branch information
simbabque committed Oct 10, 2017
1 parent 3dbb8bc commit 82d4a6b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
29 changes: 26 additions & 3 deletions lib/SVG/Timeline.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ SVG::Timeline - Create SVG timeline charts
});
$tl->add_event({
start => 1939,
end => 1945,
start => 1939.66575, # 1 Sep 1939
end => 1945.34795, # 8 May 1945
text => 'World War II',
});
Expand Down Expand Up @@ -246,6 +246,29 @@ has bar_outline_colour => (

=back
=head2 add_event
Takes a hash reference with event details and adds an L<SVG::Timeline::Event>
to the timeline. The following details are supported:
=over 4
=item * text - the name of the event that is displayed on the bar. This is required.
=item * start - the start year of the event. Can be an integer for a full year,
or a floating point value where the decimal fraction is how far through the year
the date falls. For example, C<2017.5> is roughly the 2nd of July 2017, or the
middle of the year. This is required.
=item * end - the end year of the event. Can be an integer or a floating point value.
This is required.
=item * colour - the colour that is used to fill the timeline block. This should be
defined in the RGB format used by SVG. For example, red would be 'RGB(255,0,0)'.
This is optional. If not provided, the C<default_color> is used.
=back
=head2 calculated_height
The height of the timeline in "calculated units".
Expand All @@ -270,7 +293,7 @@ sub calculated_height {

=head2 calculated_width
The widtn in "calulated units".
The width in "calulated units".
=cut

Expand Down
4 changes: 2 additions & 2 deletions lib/SVG/Timeline/Event.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ has text => (

has start => (
is => 'ro',
isa => 'Int',
isa => 'Num',
required => 1,
);

has end => (
is => 'ro',
isa => 'Int',
isa => 'Num',
required => 1,
);

Expand Down
8 changes: 7 additions & 1 deletion t/01-basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ $tl->add_event({
text => 'Perl',
});

is($tl->count_events, 1, 'Correct number of events');
$tl->add_event({
start => 2017.5726,
end => localtime->year + ( localtime->yday + 1 ) / ( localtime->is_leap_year ? 365: 366 ),
text => 'SVG::Timeline on CPAN',
});

is($tl->count_events, 2, 'Correct number of events');
is($tl->events->[0]->index, 1, 'Correct index for event');
isa_ok($tl->svg, 'SVG');

Expand Down

0 comments on commit 82d4a6b

Please sign in to comment.