Subject: | Suppress last tick on the x-axis [PATCH] |
When using x_label_skip, the last tick is always shown even if the x
value is not a multiple of x_label_skip. This can be an issue if the
last value is only slightly above that of the penultimate tick.
Therefore, I have added a new setting - x_label_skip_last - which
indicates whether the last tick/label should be skipped if not a
multiple of x_label_skip: 0 = show last tick/label (DEFAULT), 1 = skip
last tick/label if not a multiple of x_label_skip.
A patch to axestype.pm is attached. Note that, although it is
independent of my previous patches, the patch assumes that those patches
have been applied. If not, the line numbers may have to be adjusted.
Subject: | 04_last_tick.diff |
*** old\axestype.pm Tue Nov 09 17:24:35 2010
--- new\axestype.pm Wed Nov 10 16:09:07 2010
***************
*** 42,47 ****
--- 42,50 ----
# if 2 will print every second, etc..
x_label_skip => 1,
y_label_skip => 1,
+
+ # Whether to skip the last label when skipping labels on the x-axis
+ x_label_skip_last => 0,
# Do we want ticks on the x axis?
x_ticks => 1,
***************
*** 1114,1119 ****
--- 1117,1126 ----
my $tick_length = $self->{x_tick_length};
$tick_length = 0 if $self->{x_long_ticks} && ($self->{x_tick_length} > 0);
+ my $last_tick = $self->{_data}->num_points - 1;
+ # Stop the last tick appearing if not a multiple of the skip value
+ $last_tick += $self->{x_label_skip} if $self->{x_label_skip_last};
+
for (my $i = 0; $i < $self->{_data}->num_points; $i++)
{
my ($x, $y) = $self->val_to_pixel($i + 1, 0, 1);
***************
*** 1123,1129 ****
# CONTRIB Damon Brodie for x_tick_offset
next if (!$self->{x_all_ticks} and
($i - $self->{x_tick_offset}) % $self->{x_label_skip} and
! $i != $self->{_data}->num_points - 1
);
if ($self->{x_ticks})
--- 1130,1136 ----
# CONTRIB Damon Brodie for x_tick_offset
next if (!$self->{x_all_ticks} and
($i - $self->{x_tick_offset}) % $self->{x_label_skip} and
! $i < $last_tick
);
if ($self->{x_ticks})
***************
*** 1142,1148 ****
# CONTRIB Damon Brodie for x_tick_offset
next if
($i - $self->{x_tick_offset}) % ($self->{x_label_skip}) and
! $i != $self->{_data}->num_points - 1;
my $text = $self->{_data}->get_x($i);
if (defined $text)
--- 1149,1155 ----
# CONTRIB Damon Brodie for x_tick_offset
next if
($i - $self->{x_tick_offset}) % ($self->{x_label_skip}) and
! $i < $last_tick;
my $text = $self->{_data}->get_x($i);
if (defined $text)
***************
*** 1178,1183 ****
--- 1185,1194 ----
# as the gridlines will overwrite the ticks
my $tick_length = $self->{x_tick_length};
$tick_length = 0 if $self->{x_long_ticks} && ($self->{x_tick_length} > 0);
+
+ my $last_tick = $self->{_data}->num_points - 1;
+ # Stop the last tick appearing if not a multiple of the skip value
+ $last_tick += $self->{x_label_skip} if $self->{x_label_skip_last};
for (my $i = 0; $i < $self->{_data}->num_points; $i++)
{
***************
*** 1188,1194 ****
# CONTRIB Damon Brodie for x_tick_offset
next if (!$self->{x_all_ticks} and
($i - $self->{x_tick_offset}) % $self->{x_label_skip} and
! $i != $self->{_data}->num_points - 1
);
if ($self->{x_ticks})
--- 1199,1205 ----
# CONTRIB Damon Brodie for x_tick_offset
next if (!$self->{x_all_ticks} and
($i - $self->{x_tick_offset}) % $self->{x_label_skip} and
! $i < $last_tick
);
if ($self->{x_ticks})
***************
*** 1207,1213 ****
# CONTRIB Damon Brodie for x_tick_offset
next if
($i - $self->{x_tick_offset}) % ($self->{x_label_skip}) and
! $i != $self->{_data}->num_points - 1;
my $text = $self->{_data}->get_x($i);
if (defined $text)
--- 1218,1224 ----
# CONTRIB Damon Brodie for x_tick_offset
next if
($i - $self->{x_tick_offset}) % ($self->{x_label_skip}) and
! $i < $last_tick;
my $text = $self->{_data}->get_x($i);
if (defined $text)
***************
*** 1283,1288 ****
--- 1294,1303 ----
my $tick_length = $self->{x_tick_length};
$tick_length = 0 if $self->{x_long_ticks} && ($self->{x_tick_length} > 0);
+ my $last_tick = $self->{x_tick_number};
+ # Stop the last tick appearing if not a multiple of the skip value
+ $last_tick += $self->{x_label_skip} if $self->{x_label_skip_last};
+
for my $i (0 .. $self->{x_tick_number})
{
my ($value, $x, $y);
***************
*** 1318,1325 ****
}
# If we have to skip labels, we'll do it here.
! # Make sure to always draw the last one.
! next if $i % $self->{x_label_skip} && $i != $self->{x_tick_number};
$self->{gdta_x_axis}->set_text($self->{x_labels}[$i]);
--- 1333,1340 ----
}
# If we have to skip labels, we'll do it here.
! # Make sure to always draw the last one unless asked not to.
! next if $i % $self->{x_label_skip} && $i < $last_tick;
$self->{gdta_x_axis}->set_text($self->{x_labels}[$i]);