diff --git a/CHANGES b/CHANGES index 6e8e548..732735c 100644 --- a/CHANGES +++ b/CHANGES @@ -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 diff --git a/lib/PDL/Graphics/Gnuplot.pm b/lib/PDL/Graphics/Gnuplot.pm index 1020c20..c625557 100644 --- a/lib/PDL/Graphics/Gnuplot.pm +++ b/lib/PDL/Graphics/Gnuplot.pm @@ -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}); diff --git a/t/plot.t b/t/plot.t index ba83f64..1d79367 100644 --- a/t/plot.t +++ b/t/plot.t @@ -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");