Subject: | GD-Graph-Cartesian min/max cache is broken |
From: Colin Goddard at discuva.com
Sent: Monday, March 19, 2012 8:57 AM
Hi Michael,
This is an extremely useful module, but it looks like you intended to
make the following changes, then never got around to it. In sub maxy{}
you have the following code:-
sub maxy {
my $self=shift();
unless (defined($self->{'maxy'})) {
my ($min, $max)=$self->_minmaxy;
$self->{'maxy'}=$max;
}
return $self->{'maxy'};
}
The line:-
unless (defined($self->{'maxy'})) {
means that _minmaxy is only called once by this method, which is good
for large data sets, as _minmaxy performs a sort on all data; points,
lines and text. Unfortunately, minx, miny and maxx do not have the
unless (defined($self->{'mxxx'})) {
so they call the sort routine every time they are called, such as for
every point they plot or line they draw. For a data-set of 4500
points, this can take more than 30 seconds to plot. By updating them to
the following, the draw time can be reduced to 0.1 sec for a dataset of
this size:-
=head2 minx
=cut
sub minx {
my $self=shift();
unless (defined($self->{'minx'})) {
my ($min, $max)=$self->_minmaxx;
$self->{'minx'}=$min;
}
return $self->{'minx'};
}
=head2 maxx
=cut
sub maxx {
my $self=shift();
unless (defined($self->{'maxx'})) {
my ($min, $max)=$self->_minmaxx;
$self->{'maxx'}=$max;
}
return $self->{'maxx'};
}
=head2 miny
=cut
sub miny {
my $self=shift();
unless (defined($self->{'miny'})) {
my ($min, $max)=$self->_minmaxy;
$self->{'miny'}=$min;
}
return $self->{'miny'};
}
Regards,
Colin Goddard