NAME

SVG::Timeline::Compact - A Moose based SVG Timeline drawing class.

VERSION

version 0.003

SYNOPSIS

 use SVG::Timeline::Compact;
 use DateTime::Format::Natural;

 my $svg=SVG::Timeline::Compact->new();

 my $parser = DateTime::Format::Natural->new;
 my $start=$parser->parse_datetime("12pm");
 my $end=$parser->parse_datetime("1pm");

 $svg->add_event(
                start=>$start,
                end=>$end,
                name=>"Event 1",
                tooltip=>"First Event of the example",
                color=>"#ff00ff"
);

 $start=$parser->parse_datetime("12:45pm");
 $end=$parser->parse_datetime("1:20pm");

 $svg->add_event(
                start=>$start,
                end=>$end,
                name=>"Event 2",
                tooltip=>"Second Event of the example",
                color=>"#ff000f"
);

 $start=$parser->parse_datetime("3:00pm");
 $end=$parser->parse_datetime("5:20pm");

 $svg->add_event(
                start=>$start,
                end=>$end,
                name=>"Event 3",
                tooltip=>"Third Event of the example",
                color=>"#fff00f"
);

 open my $fh,">","test.svg" or die "unable to open test.svg for writing";
 print $fh $svg->to_svg;

DESCRIPTION

This module originated because SVG::Timeline did not meet my requirements.

The major difference with SVG::Timeline are as follows

  • Start and End are actual DateTime Objects.

  • Auto-calculation of timescale ( min, hours, days, months, years ) based on the events and grid size.

  • Auto Layout to fit multiple events on same row.

  • Tooltips.

METHODS

new Creates a new SVG::Timeline::Compact Object.

Takes the following parameters:

min_width:
 Default 1, If the event duration is less then min_width then the resultant bar in the graph is made equal to min_width e.g. if start==end then instead of drawing an event with width 0, an event 1 px width is drawn.
min_height:
 Default 20, The height of the bar, This assumes that our text is 12 px high.
units:
 Default 800, The width of the drawing area in px. 

add_event

 Takes a hash corresponding to L<SVG::Timeline::Compact::Event> and adds it to the event list.

The hash fields are:

id:
 Optional, Event ID.
start:
 Required, DateTime Object representing the Start Time.
end:
 Required, DateTime Object representing the End Time.
name:
 Required, Event Name.
tooltip:
 Optional, Event Tooltip.
color:
 Optional, The RGB value for filling the rectangle representing the event.

to_svg Performs an autolayout of all the added events and returns the resultant SVG as a string.

AUTHOR

Vijayvithal <jvs@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by Vijayvithal.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.