Skip to content

Commit

Permalink
polylines to also take single arg
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Sep 12, 2024
1 parent 6c4255b commit 337e4c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/PDL/Graphics/Simple.pm
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ $plot_options->synonyms( {
});
our $plot_types = {
points => { args=>[1,2], ndims=>[1] },
polylines => { args=>[2], ndims=>[1,2] },
polylines => { args=>[1,2], ndims=>[1,2] },
lines => { args=>[1,2], ndims=>[1] },
bins => { args=>[1,2], ndims=>[1] },
circles => { args=>[2,3], ndims=>[1] },
Expand Down Expand Up @@ -970,6 +970,10 @@ sub _translate_plot {
if ($ptn eq 'contours' and @args == 1) {
my $cntr_cnt = 9;
push @args, zeroes($cntr_cnt)->xlinvals($args[-1]->minmax);
} elsif ($ptn eq 'polylines' and @args == 1) {
barf "Single-arg form of '$ptn' must have dim 0 of 3"
if $args[0]->dim(0) != 3;
@args = ($args[0]->slice('0:1'), $args[0]->slice('(2)'));
} elsif (defined($pt->{args}[1])) { # Add an index variable if needed
barf "First arg to '$ptn' must have at least $pt->{ndims}[0] dims"
if $args[0]->ndims < $pt->{ndims}[0];
Expand Down
4 changes: 3 additions & 1 deletion t/simple.t
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ for my $bounds (5, {}, [1..3], [1,1]) {
{ my @w; local $SIG{__WARN__} = sub {push @w, @_};
eval { PDL::Graphics::Simple::_translate_plot(undef, undef, with=>'lines', pdl(1), pdl(1), pdl(1)) };
like $@, qr/requires 1 or 2 columns/;
eval { PDL::Graphics::Simple::_translate_plot(undef, undef, with=>'fits', pdl(1), pdl(1)) };
like $@, qr/requires 1 columns/;
eval { PDL::Graphics::Simple::_translate_plot(undef, undef, with=>'polylines', pdl(1)) };
like $@, qr/requires 2 columns/;
like $@, qr/Single-arg/;
is "@w", "", "no warnings";
}

Expand Down

0 comments on commit 337e4c5

Please sign in to comment.