Skip to content

Commit

Permalink
fix array-ref arg handling logic - fix #86
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Apr 13, 2024
1 parent ffc111d commit 240b110
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- use terminal "dumb" if probing shows "unknown" (#66)
- fix numeric-only strings for legend (#100) - thanks @d-lamb for report
- fix plot3d array-ref handling (#87) - thanks @djerius for report
- fix gplot array-ref handling (#86) - thanks @djerius for report

2.024 2023-03-30
- Add Alien::Gnuplot as a configure-time dependency. Fixes #92 - thanks @zmughal
Expand Down
12 changes: 7 additions & 5 deletions lib/PDL/Graphics/Gnuplot.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3314,11 +3314,13 @@ sub parseArgs
# First, I find and parse the options in this chunk
# Array refs are allowed in some curve options, but only as values of key/value
# pairs -- so any array refs glommed in with a bunch of other refs are data.
my $nextDataIdx = first { (ref $args[$_] ) and
( (ref($args[$_]) =~ m/ARRAY/ and ref($args[$_-1])) or
$args[$_]->$_isa('PDL')
)
} $argIndex..$#args;
my $nextDataIdx = $argIndex;
while (1) {
$nextDataIdx = undef, last if $nextDataIdx > $#args;
$nextDataIdx += 2, next if !ref $args[$nextDataIdx]; # a key
last if ref $args[$nextDataIdx] ne 'HASH';
$nextDataIdx++;
}
last if !defined $nextDataIdx; # no more data. done.
my $lastWith = {};
$lastWith->{with} = $lastOptions->{with} if($lastOptions->{with});
Expand Down
6 changes: 6 additions & 0 deletions t/plot.t
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ is($@, '', "two arguments, both arrays, works OK");
eval { $w->plot3d([1,2,3,4,5],[6,7,8,9,10],[6,7,8,9,10]);};
is($@, '', "plot3d all arguments are arrays, works OK");

eval { $w->gplot(with => 'points', pdl(0..2), pdl(0..2));};
is($@, '', "gplot points all arguments are pdls, works OK");

eval { $w->gplot(with => 'points', [ 0, 1, 2 ], [ 0, 1, 2 ]);};
is($@, '', "gplot points all arguments are arrays, works OK");

eval { $w->plot(xmin=>3,xrange=>[4,5],xvals(10),[1,2,3])};
like($@, qr/mismatch/, "Mismatch detected in array size vs. PDL size");

Expand Down

0 comments on commit 240b110

Please sign in to comment.