Subject: | [PATCH] undefined x values |
Hello Martien,
GD::Graph does not handle undefined x values correctly. If an x value
is undefined, then the previous label will be rendered in the x axis,
but instead nothing should be rendered. This problem is due to a missing
defined() test in GD::Graph::axestype. The attached patch fixes the problem.
Regards,
Slaven
--- /usr/local/dist/cpan/build/GDGraph-1.43/Graph/axestype.pm 2003-07-01 07:04:10.000000000 +0200
+++ Graph/axestype.pm 2003-11-13 16:07:56.000000000 +0100
@@ -1136,19 +1136,23 @@ sub draw_x_ticks_h
($i - $self->{x_tick_offset}) % ($self->{x_label_skip}) and
$i != $self->{_data}->num_points - 1;
- $self->{gdta_x_axis}->set_text($self->{_data}->get_x($i));
-
- my $angle = 0;
- if ($self->{x_labels_vertical})
- {
- $self->{gdta_x_axis}->set_align('bottom', 'center');
- $angle = PI/2;
- }
- else
- {
- $self->{gdta_x_axis}->set_align('center', 'right');
- }
- $self->{gdta_x_axis}->draw($x - $self->{axis_space}, $y, $angle);
+ my $text = $self->{_data}->get_x($i);
+ if (defined $text)
+ {
+ $self->{gdta_x_axis}->set_text($text);
+
+ my $angle = 0;
+ if ($self->{x_labels_vertical})
+ {
+ $self->{gdta_x_axis}->set_align('bottom', 'center');
+ $angle = PI/2;
+ }
+ else
+ {
+ $self->{gdta_x_axis}->set_align('center', 'right');
+ }
+ $self->{gdta_x_axis}->draw($x - $self->{axis_space}, $y, $angle);
+ }
}
return $self;
@@ -1189,19 +1193,23 @@ sub draw_x_ticks_v
($i - $self->{x_tick_offset}) % ($self->{x_label_skip}) and
$i != $self->{_data}->num_points - 1;
- $self->{gdta_x_axis}->set_text($self->{_data}->get_x($i));
-
- my $angle = 0;
- if ($self->{x_labels_vertical})
- {
- $self->{gdta_x_axis}->set_align('center', 'right');
- $angle = PI/2;
- }
- else
- {
- $self->{gdta_x_axis}->set_align('top', 'center');
- }
- $self->{gdta_x_axis}->draw($x, $y + $self->{axis_space}, $angle);
+ my $text = $self->{_data}->get_x($i);
+ if (defined $text)
+ {
+ $self->{gdta_x_axis}->set_text($text);
+
+ my $angle = 0;
+ if ($self->{x_labels_vertical})
+ {
+ $self->{gdta_x_axis}->set_align('center', 'right');
+ $angle = PI/2;
+ }
+ else
+ {
+ $self->{gdta_x_axis}->set_align('top', 'center');
+ }
+ $self->{gdta_x_axis}->draw($x, $y + $self->{axis_space}, $angle);
+ }
}
return $self;