Subject: | Allow ticks outside the axes with long_ticks |
Using a negative value for tick length tells GD::Graph to put the ticks
outside the axes; however, long_ticks currently overrides the
tick_length setting and so ticks do not appear on the axes if long_ticks
are used.
Long ticks are effectively grid lines and it would be useful to use both
options together so I have attached a patch to axestype.pm which draws
both gridlines and ticks where tick_length is negative and long_ticks
are used.
Using ActiveState Perl 5.8.9 on Windows XP and Perl 5.8.8 on Red Hat
Enterprise Linux 5.3 (64-bit).
N.B. This patch should be applied after the previous patch (Min/Max y
values do not work for two axes) for the line numbers to be correct.
Subject: | long_tick.diff |
*** axestype-patched.pm Mon Nov 08 17:24:08 2010
--- axestype.pm Tue Nov 09 17:24:35 2010
***************
*** 998,1003 ****
--- 998,1008 ----
{
my $self = shift;
+ # Get tick length - set to zero if greater than zero and using long ticks
+ # as the gridlines will overwrite the ticks
+ my $tick_length = $self->{y_tick_length};
+ $tick_length = 0 if $self->{y_long_ticks} && ($self->{y_tick_length} > 0);
+
for my $t (0 .. $self->{y_tick_number})
{
for my $axis (1 .. ($self->{two_axes} + 1))
***************
*** 1006,1030 ****
my $label = $self->{y_labels}[$axis][$t];
my ($x, $y) = $self->val_to_pixel(0, $value, -$axis);
$y = ($axis == 1) ? $self->{bottom} : $self->{top};
! if ($self->{y_long_ticks})
{
! $self->{graph}->line(
! $x, $self->{bottom},
! $x, $self->{top},
! $self->{fgci}
! ) unless ($axis-1);
! }
! else
! {
! $self->{graph}->line(
! $x, $y,
! $x, $y - $self->{y_tick_length},
! $self->{fgci}
! );
}
!
next
if $t % ($self->{y_label_skip}) || ! $self->{y_plot_values};
--- 1011,1028 ----
my $label = $self->{y_labels}[$axis][$t];
my ($x, $y) = $self->val_to_pixel(0, $value, -$axis);
+ my $y1 = ($axis == 1) ? $self->{bottom} : $self->{top};
+ my $y2 = ($axis == 1) ? $self->{bottom} - $tick_length:
+ $self->{top} + $tick_length;
$y = ($axis == 1) ? $self->{bottom} : $self->{top};
! if ($self->{y_long_ticks} && $axis == 1) # draw the gridline
{
! $y1 -= $tick_length;
! $y2 = $self->{top};
}
! $self->{graph}->line($x, $y1, $x, $y2, $self->{fgci}) if $y1 != $y2;
!
next
if $t % ($self->{y_label_skip}) || ! $self->{y_plot_values};
***************
*** 1050,1055 ****
--- 1048,1058 ----
{
my $self = shift;
+ # Get tick length - set to zero if greater than zero and using long ticks
+ # as the gridlines will overwrite the ticks
+ my $tick_length = $self->{y_tick_length};
+ $tick_length = 0 if $self->{y_long_ticks} && ($self->{y_tick_length} > 0);
+
for my $t (0 .. $self->{y_tick_number})
{
# XXX Ugh, why did I ever do it this way? How bloody obscure.
***************
*** 1059,1082 ****
my $label = $self->{y_labels}[$axis][$t];
my ($x, $y) = $self->val_to_pixel(0, $value, -$axis);
$x = ($axis == 1) ? $self->{left} : $self->{right};
!
! if ($self->{y_long_ticks})
{
! $self->{graph}->line(
! $x, $y,
! $x + $self->{right} - $self->{left}, $y,
! $self->{fgci}
! ) unless ($axis-1);
! }
! else
! {
! $self->{graph}->line(
! $x, $y,
! $x + (3 - 2 * $axis) * $self->{y_tick_length}, $y,
! $self->{fgci}
! );
}
next
if $t % ($self->{y_label_skip}) || ! $self->{y_plot_values};
--- 1062,1078 ----
my $label = $self->{y_labels}[$axis][$t];
my ($x, $y) = $self->val_to_pixel(0, $value, -$axis);
+ my $x1 = ($axis == 1) ? $self->{left} : $self->{right};
+ my $x2 = ($axis == 1) ? $self->{left} + $tick_length:
+ $self->{right} - $tick_length;
$x = ($axis == 1) ? $self->{left} : $self->{right};
!
! if ($self->{y_long_ticks} && $axis == 1) # draw the gridline
{
! $x1 += $tick_length;
! $x2 = $self->{right};
}
+ $self->{graph}->line($x1, $y, $x2, $y, $self->{fgci}) if $x1 != $x2;
next
if $t % ($self->{y_label_skip}) || ! $self->{y_plot_values};
***************
*** 1113,1118 ****
--- 1109,1119 ----
{
my $self = shift;
+ # Get tick length - set to zero if greater than zero and using long ticks
+ # 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);
+
for (my $i = 0; $i < $self->{_data}->num_points; $i++)
{
my ($x, $y) = $self->val_to_pixel($i + 1, 0, 1);
***************
*** 1127,1142 ****
if ($self->{x_ticks})
{
! if ($self->{x_long_ticks})
! {
! $self->{graph}->line($self->{left}, $y, $self->{right}, $y,
! $self->{fgci});
! }
! else
{
! $self->{graph}->line( $x, $y, $x + $self->{x_tick_length}, $y,
! $self->{fgci});
}
}
# CONTRIB Damon Brodie for x_tick_offset
--- 1128,1142 ----
if ($self->{x_ticks})
{
! my $x1 = $x;
! my $x2 = $x + $tick_length;
!
! if ($self->{x_long_ticks}) # draw the gridline
{
! $x1 = $self->{left} + $tick_length;
! $x2 = $self->{right};
}
+ $self->{graph}->line($x1, $y, $x2, $y, $self->{fgci}) if $x1 != $x2;
}
# CONTRIB Damon Brodie for x_tick_offset
***************
*** 1174,1179 ****
--- 1174,1184 ----
{
my $self = shift;
+ # Get tick length - set to zero if greater than zero and using long ticks
+ # 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);
+
for (my $i = 0; $i < $self->{_data}->num_points; $i++)
{
my ($x, $y) = $self->val_to_pixel($i + 1, 0, 1);
***************
*** 1188,1203 ****
if ($self->{x_ticks})
{
! if ($self->{x_long_ticks})
! {
! $self->{graph}->line($x, $self->{bottom}, $x, $self->{top},
! $self->{fgci});
! }
! else
{
! $self->{graph}->line($x, $y, $x, $y - $self->{x_tick_length},
! $self->{fgci});
}
}
# CONTRIB Damon Brodie for x_tick_offset
--- 1193,1207 ----
if ($self->{x_ticks})
{
! my $y1 = $y;
! my $y2 = $y - $tick_length;
!
! if ($self->{x_long_ticks}) # draw the gridline
{
! $y1 = $self->{bottom} - $tick_length;
! $y2 = $self->{top};
}
+ $self->{graph}->line($x, $y1, $x, $y2, $self->{fgci}) if $y1 != $y2;
}
# CONTRIB Damon Brodie for x_tick_offset
***************
*** 1274,1279 ****
--- 1278,1288 ----
{
my $self = shift;
+ # Get tick length - set to zero if greater than zero and using long ticks
+ # 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);
+
for my $i (0 .. $self->{x_tick_number})
{
my ($value, $x, $y);
***************
*** 1297,1323 ****
if ($self->{x_ticks})
{
! if ($self->{x_long_ticks})
! {
! # XXX This mod needs to be done everywhere ticks are
! # drawn
! if ( $self->{x_tick_length} >= 0 )
! {
! $self->{graph}->line($x, $self->{bottom},
! $x, $self->{top}, $self->{fgci});
! }
! else
! {
! $self->{graph}->line(
! $x, $self->{bottom} - $self->{x_tick_length},
! $x, $self->{top}, $self->{fgci});
! }
! }
! else
{
! $self->{graph}->line($x, $y,
! $x, $y - $self->{x_tick_length}, $self->{fgci} );
}
}
# If we have to skip labels, we'll do it here.
--- 1306,1320 ----
if ($self->{x_ticks})
{
! my $y1 = $y;
! my $y2 = $y - $tick_length;
!
! if ($self->{x_long_ticks}) # draw the gridline
{
! $y1 = $self->{bottom} - $tick_length;
! $y2 = $self->{top};
}
+ $self->{graph}->line($x, $y1, $x, $y2, $self->{fgci}) if $y1 != $y2;
}
# If we have to skip labels, we'll do it here.