@@ -425,16 +425,16 @@ sub plot {
425
425
426
426
my $plot ;
427
427
428
- if ($ipo -> {oplot } and defined ($me -> {last_plot })) {
428
+ if ($ipo -> {oplot } and defined ($me -> {last_plot })) {
429
429
$plot = $me -> {last_plot };
430
430
} else {
431
431
$me -> {curvestyle } = 0;
432
432
433
- if ( $me -> {multi } ) {
433
+ if ( $me -> {multi }) {
434
434
# Multiplot - handle logic and plot placement
435
435
436
436
# Advance to the next plot position. Erase the window if necessary.
437
- if ($me -> {next_plotno } and $me -> {next_plotno } >= $me -> {multi }-> [0] * $me -> {multi }-> [1]) {
437
+ if ($me -> {next_plotno } and $me -> {next_plotno } >= $me -> {multi }-> [0] * $me -> {multi }-> [1]) {
438
438
map {$_ -> destroy} @{$me -> {widgets }};
439
439
$me -> {widgets } = [];
440
440
$me -> {next_plotno } = 0;
@@ -474,87 +474,88 @@ sub plot {
474
474
}
475
475
}
476
476
477
- # # Set global plot options: titles, axis labels, and ranges.
478
- $plot -> hide;
479
- $plot -> lock;
480
- $plot -> title( $ipo -> {title } ) if (defined ($ipo -> {title }));
481
- $plot -> x-> label( $ipo -> {xlabel } ) if (defined ($ipo -> {xlabel }));
482
- $plot -> y - >label( $ipo- >{ylabel} ) if(defined($ipo- >{ylabel }));
483
-
484
- $plot -> x-> scaling(sc::Log()) if ($ipo -> {logaxis }=~ m / x/ i );
485
- $plot -> y -> scaling(sc::Log()) if ($ipo -> {logaxis }=~ m / y/ i );
486
-
487
- $plot -> x-> min($ipo -> {xrange }[0]) if (defined ($ipo -> {xrange }) and defined ($ipo -> {xrange }[0]));
488
- $plot -> x-> max($ipo -> {xrange }[1]) if (defined ($ipo -> {xrange }) and defined ($ipo -> {xrange }[1]));
489
- $plot -> y - >min($ipo- >{yrange}[0]) if(defined($ipo- >{yrange }) and defined ($ipo -> {yrange }[0]));
490
- $plot -> y - >max($ipo- >{yrange}[1]) if(defined($ipo- >{yrange }) and defined ($ipo -> {yrange }[1]));
491
-
492
- # #############################
493
- # I couldn't find a way to scale the plot to make the plot area justified, so
494
- # we cheat and adjust the axis values instead.
495
- # This is a total hack, but at least it produces justified plots.
496
- if ( !!($ipo -> {justify }) ) {
497
- my ($dmin ,$pmin ,$dmax ,$pmax ,$xscale ,$yscale );
498
-
499
- ($dmin ,$dmax ) = $plot -> x-> minmax;
500
- $pmin = $plot -> x-> reals_to_pixels($dmin );
501
- $pmax = $plot -> x-> reals_to_pixels($dmax );
502
- $xscale = ($pmax -$pmin )/($dmax -$dmin );
503
-
504
- ($dmin ,$dmax ) = $plot -> y -> minmax;
505
- $pmin = $plot -> y -> reals_to_pixels($dmin );
506
- $pmax = $plot -> y -> reals_to_pixels($dmax );
507
- $yscale = ($pmax -$pmin )/($dmax -$dmin );
508
-
509
- my $ratio = $yscale / $xscale ;
510
- if ($ratio > 1) {
511
- # More Y pixels per datavalue than X pixels. Hence we expand the Y range.
512
- my $ycen = ($dmax +$dmin )/2;
513
- my $yof = ($dmax -$dmin )/2;
514
- my $new_yof = $yof * $yscale /$xscale ;
515
- $plot -> y -> min($ycen -$new_yof );
516
- $plot -> y -> max($ycen +$new_yof );
517
- } elsif ($ratio < 1) {
518
- # More X pixels per datavalue than Y pixels. Hence we expand the X range.
519
- ($dmin ,$dmax ) = $plot -> x-> minmax;
520
- my $xcen = ($dmax +$dmin )/2;
521
- my $xof = ($dmax -$dmin )/2;
522
- my $new_xof = $xof * $xscale /$yscale ;
523
- $plot -> x-> min($xcen -$new_xof );
524
- $plot -> x-> max($xcen +$new_xof );
525
- }
477
+ if (!$ipo -> {oplot }) {
478
+ # # Set global plot options: titles, axis labels, and ranges.
479
+ $plot -> hide;
480
+ $plot -> lock;
481
+ $plot -> title( $ipo -> {title } ) if (defined ($ipo -> {title }));
482
+ $plot -> x-> label( $ipo -> {xlabel } ) if (defined ($ipo -> {xlabel }));
483
+ $plot -> y - >label( $ipo- >{ylabel} ) if(defined($ipo- >{ylabel }));
484
+
485
+ $plot -> x-> scaling(sc::Log()) if ($ipo -> {logaxis }=~ m / x/ i );
486
+ $plot -> y -> scaling(sc::Log()) if ($ipo -> {logaxis }=~ m / y/ i );
487
+
488
+ $plot -> x-> min($ipo -> {xrange }[0]) if (defined ($ipo -> {xrange }) and defined ($ipo -> {xrange }[0]));
489
+ $plot -> x-> max($ipo -> {xrange }[1]) if (defined ($ipo -> {xrange }) and defined ($ipo -> {xrange }[1]));
490
+ $plot -> y - >min($ipo- >{yrange}[0]) if(defined($ipo- >{yrange }) and defined ($ipo -> {yrange }[0]));
491
+ $plot -> y - >max($ipo- >{yrange}[1]) if(defined($ipo- >{yrange }) and defined ($ipo -> {yrange }[1]));
492
+
493
+ # #############################
494
+ # I couldn't find a way to scale the plot to make the plot area justified, so
495
+ # we cheat and adjust the axis values instead.
496
+ # This is a total hack, but at least it produces justified plots.
497
+ if ($ipo -> {justify }) {
498
+ my ($dmin ,$pmin ,$dmax ,$pmax ,$xscale ,$yscale );
499
+
500
+ ($dmin ,$dmax ) = $plot -> x-> minmax;
501
+ $pmin = $plot -> x-> reals_to_pixels($dmin );
502
+ $pmax = $plot -> x-> reals_to_pixels($dmax );
503
+ $xscale = ($pmax -$pmin )/($dmax -$dmin );
504
+
505
+ ($dmin ,$dmax ) = $plot -> y -> minmax;
506
+ $pmin = $plot -> y -> reals_to_pixels($dmin );
507
+ $pmax = $plot -> y -> reals_to_pixels($dmax );
508
+ $yscale = ($pmax -$pmin )/($dmax -$dmin );
509
+
510
+ my $ratio = $yscale / $xscale ;
511
+ if ($ratio > 1) {
512
+ # More Y pixels per datavalue than X pixels. Hence we expand the Y range.
513
+ my $ycen = ($dmax +$dmin )/2;
514
+ my $yof = ($dmax -$dmin )/2;
515
+ my $new_yof = $yof * $yscale /$xscale ;
516
+ $plot -> y -> min($ycen -$new_yof );
517
+ $plot -> y -> max($ycen +$new_yof );
518
+ } elsif ($ratio < 1) {
519
+ # More X pixels per datavalue than Y pixels. Hence we expand the X range.
520
+ ($dmin ,$dmax ) = $plot -> x-> minmax;
521
+ my $xcen = ($dmax +$dmin )/2;
522
+ my $xof = ($dmax -$dmin )/2;
523
+ my $new_xof = $xof * $xscale /$yscale ;
524
+ $plot -> x-> min($xcen -$new_xof );
525
+ $plot -> x-> max($xcen +$new_xof );
526
+ }
527
+ }
526
528
}
527
529
528
-
529
530
# #############################
530
531
# Rubber meets the road -- loop over data blocks and
531
532
# ship out each curve to the appropriate dispatcher in the $types table
532
533
for my $block (@_ ) {
533
- my $co = shift @$block ;
534
+ my ( $co , @rest ) = @$block ;
534
535
535
- # Parse out curve style (for points type selection)
536
- if (defined $co -> {style }) {
537
- $me -> {curvestyle } = $co -> {style };
538
- } else {
539
- $me -> {curvestyle }++;
540
- }
536
+ # Parse out curve style (for points type selection)
537
+ if (defined $co -> {style }) {
538
+ $me -> {curvestyle } = $co -> {style };
539
+ } else {
540
+ $me -> {curvestyle }++;
541
+ }
541
542
542
- my $cprops = [
543
- color => $colors [ ($me -> {curvestyle }-1) % @colors ],
544
- linePattern => $patterns [ ($me -> {curvestyle }-1) % @patterns ],
545
- lineWidth => $co -> {width } || 1
546
- ];
547
-
548
- my $with = $co -> {with };
549
- my $type = $types -> {$with };
550
- die " $with is not yet implemented in PDL::Graphics::Simple for Prima.\n "
551
- if !defined $type ;
552
- if ( ref ($type ) eq ' CODE' ) {
553
- $type -> ($me , $plot , $block , $cprops , $co , $ipo );
554
- } else {
555
- my $pt = ref ($type ) eq ' ARRAY' ? $type -> [ ($me -> {curvestyle }-1) % (0+@{$type }) ] : ppair-> can($type )-> ();
556
- $plot -> dataSets()-> { 1+keys (%{$plot -> dataSets()}) } = ds::Pair(@$block , plotType => $pt , @$cprops );
557
- }
543
+ my $cprops = [
544
+ color => $colors [ ($me -> {curvestyle }-1) % @colors ],
545
+ linePattern => $patterns [ ($me -> {curvestyle }-1) % @patterns ],
546
+ lineWidth => $co -> {width } || 1
547
+ ];
548
+
549
+ my $with = $co -> {with };
550
+ my $type = $types -> {$with };
551
+ die " $with is not yet implemented in PDL::Graphics::Simple for Prima.\n "
552
+ if !defined $type ;
553
+ if ( ref ($type ) eq ' CODE' ) {
554
+ $type -> ($me , $plot , \ @rest , $cprops , $co , $ipo );
555
+ } else {
556
+ my $pt = ref ($type ) eq ' ARRAY' ? $type -> [ ($me -> {curvestyle }-1) % (0+@{$type }) ] : ppair-> can($type )-> ();
557
+ $plot -> dataSets()-> { 1+keys (%{$plot -> dataSets()}) } = ds::Pair(@rest , plotType => $pt , @$cprops );
558
+ }
558
559
}
559
560
560
561
if ($me -> {type } !~ m / f/ i ) {
0 commit comments