Skip to content

Commit

Permalink
fix Prima able to have multiple "lines" in same plot
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed May 5, 2024
1 parent 713f334 commit c66e158
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
14 changes: 7 additions & 7 deletions lib/PDL/Graphics/Simple/Prima.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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/ ],

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}++;
Expand All @@ -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);
}
}
Expand Down
13 changes: 10 additions & 3 deletions t/simple.t
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -174,13 +176,18 @@ 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,
]
];
}
eval { $w->plot(with=>'line', $x10, $x10sqrt,
with=>'line', $x10, $x10_12,
with=>'bins', $sin10,
{title=>"PDL: $engine engine, line & bin plots"}),
};
Expand Down Expand Up @@ -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".
Expand Down

0 comments on commit c66e158

Please sign in to comment.