From c66e158bb3dabf934860e7d3e0c36636c9d47b68 Mon Sep 17 00:00:00 2001 From: Ed J Date: Sun, 5 May 2024 03:08:59 +0100 Subject: [PATCH] fix Prima able to have multiple "lines" in same plot --- lib/PDL/Graphics/Simple/Prima.pm | 14 +++++++------- t/simple.t | 13 ++++++++++--- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/PDL/Graphics/Simple/Prima.pm b/lib/PDL/Graphics/Simple/Prima.pm index 82319a9..0ef8f94 100644 --- a/lib/PDL/Graphics/Simple/Prima.pm +++ b/lib/PDL/Graphics/Simple/Prima.pm @@ -269,7 +269,7 @@ sub PDL::Graphics::Simple::Prima::Sepia_Palette::apply { # the plot type in terms of others. sub _load_types { $types = { - lines => [ppair::Lines()], + lines => 'Lines', points => [ map ppair->can($_)->(), qw/Blobs Triangles Squares Crosses Xs Asterisks/ ], @@ -457,10 +457,10 @@ sub plot { $plot->x->scaling(sc::Log()) if($ipo->{logaxis}=~ m/x/i); $plot->y->scaling(sc::Log()) if($ipo->{logaxis}=~ m/y/i); - $plot->x->min($ipo->{xrange}->[0]) if(defined($ipo->{xrange}) and defined($ipo->{xrange}->[0])); - $plot->x->max($ipo->{xrange}->[1]) if(defined($ipo->{xrange}) and defined($ipo->{xrange}->[1])); - $plot->y->min($ipo->{yrange}->[0]) if(defined($ipo->{yrange}) and defined($ipo->{yrange}->[0])); - $plot->y->max($ipo->{yrange}->[1]) if(defined($ipo->{yrange}) and defined($ipo->{yrange}->[1])); + $plot->x->min($ipo->{xrange}[0]) if(defined($ipo->{xrange}) and defined($ipo->{xrange}[0])); + $plot->x->max($ipo->{xrange}[1]) if(defined($ipo->{xrange}) and defined($ipo->{xrange}[1])); + $plot->y->min($ipo->{yrange}[0]) if(defined($ipo->{yrange}) and defined($ipo->{yrange}[0])); + $plot->y->max($ipo->{yrange}[1]) if(defined($ipo->{yrange}) and defined($ipo->{yrange}[1])); ############################## # I couldn't find a way to scale the plot to make the plot area justified, so @@ -506,7 +506,7 @@ sub plot { my $co = shift @$block; # Parse out curve style (for points type selection) - if(defined($co->{style}) and $co->{style}) { + if ($co->{style}) { $me->{curvestyle} = $co->{style}; } else { $me->{curvestyle}++; @@ -524,7 +524,7 @@ sub plot { if( ref($type) eq 'CODE' ) { $type->($me, $plot, $block, $cprops, $co, $ipo); } else { - my $pt = ref($type) eq 'ARRAY' ? $type->[ ($me->{curvestyle}-1) % (0+@{$type}) ] : eval $type; + my $pt = ref($type) eq 'ARRAY' ? $type->[ ($me->{curvestyle}-1) % (0+@{$type}) ] : ppair->can($type)->(); $plot->dataSets()->{ 1+keys(%{$plot->dataSets()}) } = ds::Pair(@$block, plotType => $pt, @$cprops); } } diff --git a/t/simple.t b/t/simple.t index d0f9cad..4d206dc 100644 --- a/t/simple.t +++ b/t/simple.t @@ -98,6 +98,7 @@ ok( ( defined($mods) and ref $mods eq 'HASH' ) , # line & bin my $x10 = xvals(10); my $x10sqrt = $x10->sqrt * sqrt(10); +my $x10_12 = $x10 * 0.5; my $sin10 = sin($x10)*10; # errorbars my $x37 = xvals(37); @@ -156,12 +157,13 @@ for my $engine (@engines) { { my @args = PDL::Graphics::Simple::_translate_plot(@$w{qw(held keys)}, with=>'line', $x10, $x10sqrt, + with=>'line', $x10, $x10_12, with=>'bins', $x10, $sin10, {title=>"PDL: $engine engine, line & bin plots"} ); delete $args[1]{yrange}; # so different sin can't cause spurious fails is_deeply \@args, [ - [ 'line 1', 'bin 2' ], + [ 'line 1', 'line 2', 'bin 3' ], { 'bounds' => undef, 'crange' => undef, 'justify' => 0, 'legend' => undef, @@ -174,6 +176,10 @@ is_deeply \@args, [ { 'key' => undef, 'style' => undef, 'width' => undef, 'with' => 'lines' }, $x10, $x10sqrt, ], + [ + { 'key' => undef, 'style' => undef, 'width' => undef, 'with' => 'lines' }, + $x10, $x10_12, + ], [ { 'key' => undef, 'style' => undef, 'width' => undef, 'with' => 'bins' }, $x10, $sin10, @@ -181,6 +187,7 @@ is_deeply \@args, [ ]; } eval { $w->plot(with=>'line', $x10, $x10sqrt, + with=>'line', $x10, $x10_12, with=>'bins', $sin10, {title=>"PDL: $engine engine, line & bin plots"}), }; @@ -357,8 +364,8 @@ is_deeply \@args, [ ask_yn qq{ Testing $engine engine: You should see in a 3x2 grid: -1) a superposed line plot and bin plot, with x range from 0 to 9 and -yrange from 0 to 9. The two plots should have different line styles. +1) 2 superposed line plots and a bin plot, with x range from 0 to 9 and +yrange from 0 to 9. The three plots should have different line styles. 2) error bars (symmetric relative to each plotted point) and limit bars (asymmetric about each plotted point). 3) a radial 11x11 "target" image and some superimposed "circles".