From 82d4a6bd948bd280bd5852b4c1259797c53a6229 Mon Sep 17 00:00:00 2001 From: simbabque Date: Tue, 10 Oct 2017 22:08:42 +0200 Subject: [PATCH] make years floating point to support greater granularity in dates and amend docs Closes #1 --- lib/SVG/Timeline.pm | 29 ++++++++++++++++++++++++++--- lib/SVG/Timeline/Event.pm | 4 ++-- t/01-basic.t | 8 +++++++- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/lib/SVG/Timeline.pm b/lib/SVG/Timeline.pm index a0164af..41fd5e4 100644 --- a/lib/SVG/Timeline.pm +++ b/lib/SVG/Timeline.pm @@ -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', }); @@ -246,6 +246,29 @@ has bar_outline_colour => ( =back +=head2 add_event + +Takes a hash reference with event details and adds an L +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 is used. + +=back + =head2 calculated_height The height of the timeline in "calculated units". @@ -270,7 +293,7 @@ sub calculated_height { =head2 calculated_width -The widtn in "calulated units". +The width in "calulated units". =cut diff --git a/lib/SVG/Timeline/Event.pm b/lib/SVG/Timeline/Event.pm index 1e0d747..154bbc5 100644 --- a/lib/SVG/Timeline/Event.pm +++ b/lib/SVG/Timeline/Event.pm @@ -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, ); diff --git a/t/01-basic.t b/t/01-basic.t index 88916d1..7e21843 100644 --- a/t/01-basic.t +++ b/t/01-basic.t @@ -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');