Image-Timeline
view release on metacpan or search on metacpan
0.11 Wed Feb 25 22:28:12 CST 2004
- Images are now written uwing binmode() on the output filehandle,
which makes a difference on platforms like Win32. [Pa'll I'so'lfur
O'lason]
0.09 Sun Feb 22 20:15:42 CST 2004
- Added 'right_margin' parameter, which allows the user to define
some extra space in the right of the picture so that the last
legend isn't cut in the final image. [Paulo Jorge Jesus Silva]
- Added 'to_string' parameter, which allows the user to define the
function used to convert the numerical value of a date into a
string. [Paulo Jorge Jesus Silva]
0.08 Wed Jul 9 12:11:47 CDT 2003
- Apparently the "better way" from release 0.07 didn't work for
everybody, so there's yet *another* change in the testing for
it.
* width
How many pixels wide the image should be. Default is 900 pixels, for
no good reason.
* font
Which GD font should be used to label each entry in the timeline.
Default is `gdTinyFont'.
* bar_stepsize
The "tick interval" on the timeline's legend at the top. Default is
50 (i.e. 50 years).
* vspacing
How many pixels of vertical space should be left between entries.
Default is 2.
* hmargin
How many pixels should be left at the far right and far left of the
image. Default is 3.
* bg_color
* bar_color
* endcap_color
* legend_color
* text_color
These parameters affect the colors of the image. Each associated
value should be a 3-element array reference, specifying RGB values
from 0 to 255. For instance, the default value of `bar_color' is
pure red, specified as `[255,0,0]'. The defaults are reasonable, but
not necessarily attractive.
add(label, start, end)
Adds a new entry to the timeline. Supply a label that you want to
Timeline.pm view on Meta::CPAN
my ($pkg, %args) = @_;
my $self = {
width => 900,
font => gdTinyFont,
bar_stepsize => 50, # The gridsize for the top reference bar
vspacing => 2,
hmargin => 3,
bg_color => [255,255,255],
bar_color => [255,0,0],
endcap_color => [0,155,0],
legend_color => [0,0,0],
text_color => [0,0,0],
date_format => '',
to_string => sub { $_[0] },
right_margin => 0,
%args
};
# subtract right_margin to width to avoid cutting last legend
$self->{width} -= $self->{right_margin};
return bless $self, $pkg;
}
sub add {
my ($self, $label, $start, $end) = @_;
$self->{data}{$label}{start} = $start;
$self->{data}{$label}{end} = $end;
}
Timeline.pm view on Meta::CPAN
}
sub write_png { my $s = shift; $s->write('png', @_) }
sub write_gif { my $s = shift; $s->write('gif', @_) }
sub _create_image {
my ($self, $w, $h) = @_;
my $image = GD::Image->new($w + $self->{right_margin},$h);
# Allocate some colors
foreach (qw(bg bar endcap legend text)) {
$self->{colors}{$_} = $image->colorAllocate(@{$self->{"${_}_color"}});
}
$image->fill(0,0,$self->{colors}{bg});
return $image;
}
sub _create_channels {
my ($self) = @_;
Timeline.pm view on Meta::CPAN
my ($min,$max) = map {$_->{start}, $_->{end}} (each %{$self->{channels}[0]})[1];
foreach my $channel (@{$self->{channels}}) {
foreach my $entry (values %$channel) {
if ($entry->{start} < $min) {$min = $entry->{start}}
if ($entry->{end} > $max) {$max = $entry->{end}}
}
}
return ($self->{min}, $self->{max}) = ($min, $max);
}
sub draw_legend {
# Draw the top legend bar
my ($self, $image) = @_;
my ($min, $max) = $self->_minmax;
my $color = $self->{colors}{legend};
my $step = $self->{bar_stepsize}; # For convenience
if ($step =~ /^(\d+)%$/) { # Convert from percentage
$step = ($max - $min) * $1 / 100;
}
my $start_at = int($min/$step) * $step;
for (my $i=$start_at; $i <= $max + $step; $i += $step) {
$image->line($self->_convert($i), 2, $self->_convert($i), 8, $color);
my $label = $self->{date_format} ? $self->_UTC_to_string($i) : $self->{to_string}->($i);
Timeline.pm view on Meta::CPAN
sub draw {
my ($self) = @_;
$self->_create_channels;
# Add 2 to leave room for header
my $fheight = $self->{font}->height;
$self->{height} = (@{$self->{channels}} + 2) * (2*$fheight + $self->{vspacing});
my $image = $self->_create_image($self->{width}, $self->{height});
$self->draw_legend($image);
$self->draw_channels($image);
return $image;
}
sub _channel_is_free {
my ($self, $channel, $time) = @_;
# Step through the entries in this channel:
foreach my $data (values %$channel) {
Timeline.pm view on Meta::CPAN
How many pixels wide the image should be. Default is 900 pixels, for
no good reason.
=item font
Which GD font should be used to label each entry in the timeline.
Default is C<gdTinyFont>.
=item bar_stepsize
The "tick interval" on the timeline's legend at the top. Default is
50 (i.e. 50 years). If the stepsize ends with the C<%> character, it
will be interpreted as a percentage of the total data width.
Note that the stepsize is given in terms of the data space
(i.e. years), not in terms of the image space (i.e. pixels).
=item vspacing
How many pixels of vertical space should be left between entries.
Default is 2.
Timeline.pm view on Meta::CPAN
How many pixels should be left at the far right and far left of the
image. Default is 3.
=item bg_color
=item bar_color
=item endcap_color
=item legend_color
=item text_color
These parameters affect the colors of the image. Each associated
value should be a 3-element array reference, specifying RGB values
from 0 to 255. For instance, the default value of C<bar_color> is
pure red, specified as C<[255,0,0]>. The defaults are reasonable, but
not necessarily attractive.
=item date_format
By default, the numerical data describing an entry's start and end
point are also used as the label for the legend at the top of the
timeline. Typically this means that the data represent years.
However, if you supply the C<date_format> parameter, the data will be
assumed to be a Unix timestamp (similar to the output of the C<time()>
function), and it will be passed to the C<Date::Format> C<time2str>
function, using the C<date_format> parameter as the formatting string.
=item to_string
The function used to convert the numerical data describing and entry's
start and end point can be defined using this parameter. This function is
only used if the C<date_format> parameter is not defined and should take
one argument, the numerical value.
=item right_margin
How many pixels should be left over the right margin so that the last
legend isn't cut from the image.
=back
=head2 add(label, start, end)
Adds a new entry to the timeline. Supply a label that you want to
include in the image, the starting date, and the ending date.
=head2 draw()
( run in 1.108 second using v1.01-cache-2.11-cpan-49f99fa48dc )