Subject: | line_width does not accept an array reference |
When using lines and linespoints graphs, all the lines in the graph must
have the same width. I've found it useful to be able to independently
specify the width of each line in the graph.
I've attached a patch which allows for code like this
$graph->set( line_width => [1, 5, 10] )
which would make the first (fourth, seventh) line 1 pixel wide, the
second line (fifth, eighth) 5 pixels wide and the third (sixth, ninth)
10 pixels wide.
Of course, the current behavior is still supported. The patch also
includes a sample graph.
Subject: | line_width-multiple.patch |
=== Graph/lines.pm
==================================================================
--- Graph/lines.pm (revision 5)
+++ Graph/lines.pm (patch - level 1)
@@ -70,7 +70,7 @@
if (defined $xb)
{
- $self->draw_line($xb, $yb, $xe, $ye, $type, $dsci)
+ $self->draw_line($xb, $yb, $xe, $ye, $type, $dsci, $ds)
if defined $dsci;
$self->{_hotspots}->[$ds]->[$i] =
['line', $xb, $yb, $xe, $ye, $self->{line_width}];
@@ -91,12 +91,22 @@
$num % 4 ? $num % 4 : 4
}
-sub draw_line # ($xs, $ys, $xe, $ye, $type, $colour_index)
+sub pick_line_width
{
my $self = shift;
- my ($xs, $ys, $xe, $ye, $type, $clr) = @_;
+ my $num = shift;
my $lw = $self->{line_width};
+ return $lw if !ref $lw;
+ return $lw->[ $num % ( 1 + $#$lw ) - 1 ];
+}
+
+sub draw_line # ($xs, $ys, $xe, $ye, $type, $colour_index, $ds)
+{
+ my $self = shift;
+ my ($xs, $ys, $xe, $ye, $type, $clr, $ds) = @_;
+
+ my $lw = $self->pick_line_width($ds);
my $lts = $self->{line_type_scale};
my $style = gdStyled;
=== samples/sample52-t.pl
==================================================================
--- samples/sample52-t.pl (revision 5)
+++ samples/sample52-t.pl (patch - level 1)
@@ -0,0 +1,39 @@
+use GD::Graph::lines;
+require 'save.pl';
+
+print STDERR "Processing sample52-t\n";
+
+@data = (
+ [ qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) ],
+ [ reverse(4, 3, 5, 6, 3, 1.5, -1, -3, -4, -6, -7, -8)],
+ [ (4, 3, 5, 6, 3, 1.5, -1, -3, -4, -6, -7, -8)],
+ [ (2, 2, 2, 5, 5, 4.5,1.5, 2, 3, 5, 4, 3)],
+);
+
+$my_graph = new GD::Graph::lines();
+
+$my_graph->set(
+ x_label => 'Month',
+ y_label => 'Measure of success',
+ title => 'A Line Graph with Varying Line Widths',
+
+ y_max_value => 8,
+ y_min_value => -8,
+ y_tick_number => 16,
+ y_label_skip => 2,
+ box_axis => 0,
+ line_width => [ 1, 5, 3 ],
+ zero_axis_only => 1,
+ x_label_position => 1,
+ y_label_position => 1,
+
+ x_label_skip => 3,
+ x_tick_offset => 2,
+
+ transparent => 0,
+);
+
+$my_graph->set_legend("Us", "Them", "Others");
+$my_graph->plot(\@data);
+save_chart($my_graph, 'sample52-t');
+
=== samples/Makefile
==================================================================
--- samples/Makefile (revision 5)
+++ samples/Makefile (patch - level 1)
@@ -30,7 +30,7 @@
sample21 sample22 sample23 \
sample31 \
sample41 sample42\
- sample51 sample52 sample53 sample54 sample55 sample56 \
+ sample51 sample52 sample52-t sample53 sample54 sample55 sample56 \
sample57 \
sample61 sample62 sample63 sample64 \
sample71 \
Property changes on: samples
___________________________________________________________________
Name: svn:ignore
+*.png
+
=== Graph.pm
==================================================================
--- Graph.pm (revision 5)
+++ Graph.pm (patch - level 1)
@@ -1306,8 +1306,16 @@
=item line_width
The width of the line used in I<lines> and I<linespoints> graphs, in pixels.
-Default: 1.
+If C<line_width> is a scalar value, that width will be used for all lines. If
+C<line_width> is a reference to an array, the contents of the array specify
+the line widths for each line. If there are too few values in the array
+reference, the values are "recycled". For example, to alternate between lines
+one pixel wide and lines five pixels wide, one might do something like
+ $graph->set( line_width => [1, 5] );
+
+Default: 1 (make all lines 1 pixel wide)
+
=item skip_undef
For all other axes graph types, the default behaviour is (by their