Codebase list libpdl-graphics-gnuplot-perl / c16931e
Update upstream source from tag 'upstream/2.019' Update to upstream version '2.019' with Debian dir 80bd8787ac8c80705ed1fb97eac66b343771c008 Bas Couwenberg 2 years ago
7 changed file(s) with 286 addition(s) and 405 deletion(s). Raw diff Collapse all Expand all
0 2.019 2021-08-16
1 - end_multi only calls close if not a display
2 - when Qt and multiplot, need to send extra command to make window close
3
04 2.018 2021-08-11
15 - Fix for pdfcairo terminal not writing to file - thanks @zmughal
26
5353 "release_status" : "stable",
5454 "resources" : {
5555 "bugtracker" : {
56 "web" : "http://rt.cpan.org/Public/Dist/Display.html?Name=PDL-Graphics-Gnuplot"
56 "web" : "http://github.com/PDLPorters/PDL-Graphics-Gnuplot/issues"
5757 },
58 "homepage" : "http://github.com/drzowie/PDL-Graphics-Gnuplot",
58 "homepage" : "http://github.com/PDLPorters/PDL-Graphics-Gnuplot",
5959 "repository" : {
6060 "type" : "git",
61 "url" : "git://github.com/drzowie/PDL-Graphics-Gnuplot.git"
61 "url" : "git://github.com/PDLPorters/PDL-Graphics-Gnuplot.git"
6262 }
6363 },
64 "version" : "2.018",
64 "version" : "2.019",
6565 "x_serialization_backend" : "JSON::PP version 4.04"
6666 }
3030 Time::HiRes: '0'
3131 perl: '5.006'
3232 resources:
33 bugtracker: http://rt.cpan.org/Public/Dist/Display.html?Name=PDL-Graphics-Gnuplot
34 homepage: http://github.com/drzowie/PDL-Graphics-Gnuplot
35 repository: git://github.com/drzowie/PDL-Graphics-Gnuplot.git
36 version: '2.018'
33 bugtracker: http://github.com/PDLPorters/PDL-Graphics-Gnuplot/issues
34 homepage: http://github.com/PDLPorters/PDL-Graphics-Gnuplot
35 repository: git://github.com/PDLPorters/PDL-Graphics-Gnuplot.git
36 version: '2.019'
3737 x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
7373 },
7474 META_ADD => {
7575 resources => {
76 homepage => 'http://github.com/drzowie/PDL-Graphics-Gnuplot',
77 repository => 'git://github.com/drzowie/PDL-Graphics-Gnuplot.git',
78 bugtracker => 'http://rt.cpan.org/Public/Dist/Display.html?Name=PDL-Graphics-Gnuplot'
76 homepage => 'http://github.com/PDLPorters/PDL-Graphics-Gnuplot',
77 repository => 'git://github.com/PDLPorters/PDL-Graphics-Gnuplot.git',
78 bugtracker => 'http://github.com/PDLPorters/PDL-Graphics-Gnuplot/issues'
7979 }
8080 },
8181
8686 # reroute the main POD into a separate README.pod if requested. This is here
8787 # purely to generate a README.pod for the github front page
8888 my $POD_header = <<EOF;
89 =head1 OVERVIEW
89 =head1 OVERVIEW
9090
9191 This is a Gnuplot-based plotter for PDL. This repository stores the history for
9292 the PDL::Graphics::Gnuplot module on CPAN. Install the module via CPAN. CPAN
93 page at L<http://search.cpan.org/~zowie/PDL-Graphics-Gnuplot/lib/PDL/Graphics/Gnuplot.pm>.
93 page at L<http://metacpan.org/pod/PDL::Graphics::Gnuplot>.
9494
95 =cut
95 =cut
9696
9797 EOF
98
98 $POD_header =~ s{^ }{}gm;
9999
100100 if(exists $ARGV[0] && $ARGV[0] eq 'README.pod')
101101 {
109109 if (/^=/../^=cut/) { print README; }
110110 }
111111 }
112
11
22 This is a Gnuplot-based plotter for PDL. This repository stores the history for
33 the PDL::Graphics::Gnuplot module on CPAN. Install the module via CPAN. CPAN
4 page at L<http://search.cpan.org/~zowie/PDL-Graphics-Gnuplot/lib/PDL/Graphics/Gnuplot.pm>.
4 page at L<http://metacpan.org/pod/PDL::Graphics::Gnuplot>.
55
66 =cut
77
11411141
11421142 C<pseudocolor> (synonym C<pc>) gives access to the color tables built
11431143 in to the C<PDL::Transform::Color> package, if that package is
1144 available. It takes either a color table name or a list ref which
1145 is a collection of arguments that get sent to the
1144 available. It takes either a color table name or a list ref which
1145 is a collection of arguments that get sent to the
11461146 C<PDL::Transform::Color::t_pc> transform definition method. Sending
11471147 the empty string or undef will generate a list of allowable color
1148 table names. Many of the color tables are "photometric" and
1148 table names. Many of the color tables are "photometric" and
11491149 will render photometric data correctly without gamma correction.
11501150
1151 C<perceptual> (synonym C<pcp>) gives the same access to
1152 C<PDL::Transform::Color> as does C<pseudocolor>, but the
1151 C<perceptual> (synonym C<pcp>) gives the same access to
1152 C<PDL::Transform::Color> as does C<pseudocolor>, but the
11531153 "equal-perceptual-difference" scaling is used -- i.e. input
11541154 values are gamma-corrected by the module so that uniform
11551155 shifts in numeric value yield approximately uniform perceptual
15461546
15471547 =item dashtype (abbrev 'dt')
15481548
1549 This is can be either a numeric type selector (0 for no dashes) or
1549 This is can be either a numeric type selector (0 for no dashes) or
15501550 an ARRAY ref containing a list of up to 5 pairs of (dash length,
1551 space length). The C<dashtype> curve option is only supported for
1552 Gnuplot versions 5.0 and above.
1551 space length). The C<dashtype> curve option is only supported for
1552 Gnuplot versions 5.0 and above.
15531553
15541554 If you don't specify a C<dashtype> curve option, the default behavior
15551555 matches the behavior of earlier gnuplots: many terminals support a
15591559 a curve option for it; or to make all curves solid, use the constructor
15601560 or the C<output> method to set the terminal option C<dashed=>0>.
15611561
1562 If your gnuplot is older than v5.0, the dashtype curve option is
1562 If your gnuplot is older than v5.0, the dashtype curve option is
15631563 ignored (and causes a warning to be emitted).
15641564
15651565 =item linestyle (abbrev 'ls')
12041204
12051205 C<pseudocolor> (synonym C<pc>) gives access to the color tables built
12061206 in to the C<PDL::Transform::Color> package, if that package is
1207 available. It takes either a color table name or a list ref which
1208 is a collection of arguments that get sent to the
1207 available. It takes either a color table name or a list ref which
1208 is a collection of arguments that get sent to the
12091209 C<PDL::Transform::Color::t_pc> transform definition method. Sending
12101210 the empty string or undef will generate a list of allowable color
1211 table names. Many of the color tables are "photometric" and
1211 table names. Many of the color tables are "photometric" and
12121212 will render photometric data correctly without gamma correction.
12131213
1214 C<perceptual> (synonym C<pcp>) gives the same access to
1215 C<PDL::Transform::Color> as does C<pseudocolor>, but the
1214 C<perceptual> (synonym C<pcp>) gives the same access to
1215 C<PDL::Transform::Color> as does C<pseudocolor>, but the
12161216 "equal-perceptual-difference" scaling is used -- i.e. input
12171217 values are gamma-corrected by the module so that uniform
12181218 shifts in numeric value yield approximately uniform perceptual
16091609
16101610 =item dashtype (abbrev 'dt')
16111611
1612 This is can be either a numeric type selector (0 for no dashes) or
1612 This is can be either a numeric type selector (0 for no dashes) or
16131613 an ARRAY ref containing a list of up to 5 pairs of (dash length,
1614 space length). The C<dashtype> curve option is only supported for
1615 Gnuplot versions 5.0 and above.
1614 space length). The C<dashtype> curve option is only supported for
1615 Gnuplot versions 5.0 and above.
16161616
16171617 If you don't specify a C<dashtype> curve option, the default behavior
16181618 matches the behavior of earlier gnuplots: many terminals support a
16221622 a curve option for it; or to make all curves solid, use the constructor
16231623 or the C<output> method to set the terminal option C<dashed=>0>.
16241624
1625 If your gnuplot is older than v5.0, the dashtype curve option is
1625 If your gnuplot is older than v5.0, the dashtype curve option is
16261626 ignored (and causes a warning to be emitted).
16271627
16281628 =item linestyle (abbrev 'ls')
20182018 our $debug_echo = 0; # If set, mock up Losedows half-duplex pipes
20192019
20202020
2021 our $VERSION = '2.018';
2021 our $VERSION = '2.019';
20222022 $VERSION = eval $VERSION;
20232023
20242024 our $gp_version = undef; # eventually gets the extracted gnuplot(1) version number.
23652365
23662366 ### Deal with anti-aliasing scaling factors
23672367 if( defined $termOptions->{aa}) {
2368 $this->{aa} = $termOptions->{aa}
2368 $this->{aa} = $termOptions->{aa}
23692369 } else {
23702370 $this->{aa} = 1;
23712371 }
23842384 delete($this->{image_format});
23852385 }
23862386
2387
2387
23882388 delete $termOptions->{output};
23892389
23902390 ## Emit the terminal options line for this terminal.
24782478
24792479 =cut
24802480
2481 # reset - tops and restarts the underlying gnuplot process for an object
2481 # reset - stops and restarts the underlying gnuplot process for an object
24822482 *grestart = \&restart;
24832483 sub restart {
24842484 my $this = _obj_or_global(\@_);
25372537 if($check_syntax) {
25382538 # Send multiple newlines to avoid bugs in certain gnuplots, which
25392539 # appear to lose a character after reset.
2540 _printGnuplotPipe( $this, "syntax", "reset\n\n\n");
2540 _printGnuplotPipe( $this, "syntax", "reset\n\n\n");
25412541 $checkpointMessage = _checkpoint($this,"syntax");
25422542 }
25432543 _printGnuplotPipe($this, "main", "reset\n\n\n");
26512651 my $this = _obj_or_global(\@_);
26522652
26532653 delete $this->{last_dashtype}; # implement dashtype state function for gnuplot>=5.0
2654
2654
26552655 ##############################
26562656 # Parse optional plot options - must be an array or hash ref, if present.
26572657 # Cheesy but hopefully effective method (from Dima): parse as plot options
34543454 if($this->{aa} && $this->{aa} != 1) {
34553455 $this->{aa_ready} = 1;
34563456 }
3457
3457
34583458 # read and report any warnings that happened during the plot
34593459 return $plotWarnings;
34603460
35263526 );
35273527 ### As of Gnuplot 5.0, some curve options (dashtype) require a default value to maintain legacy
35283528 ### behavior in the default case. This is the place where curve options are parsed, so we
3529 ### hand-tweak a couple of default values here.
3529 ### hand-tweak a couple of default values here.
35303530
35313531 # dashtype doesn't have to have a defined value it only has to exist in the curve options hash,
35323532 # to trigger emission of a dashtype.
35343534
35353535 ## Even worse -- some plot types (notably "with labels") barf in newer gnuplots
35363536 ## if you feed them a "dt". So don't send a dashtype to those.
3537 my $with = (
3538 ( ref($chunk{options}{'with'}) =~ m/ARRAY/ ) ?
3539 $chunk{options}{'with'}->[0] :
3537 my $with = (
3538 ( ref($chunk{options}{'with'}) =~ m/ARRAY/ ) ?
3539 $chunk{options}{'with'}->[0] :
35403540 $chunk{options}{'with'}
3541 ) //
3541 ) //
35423542 $this->{options}->{'globalwith'} //
35433543 "";
35443544 if($with =~ m/^label/) {
43534353
43544354 sub end_multi {
43554355 my $this = _obj_or_global(\@_);
4356
43574356 unless($this->{options}->{multiplot}) {
43584357 barf("end_multi: you can't, you're not in multiplot mode\n");
43594358 }
43654364 barf("Gnuplot error: unset multiplot failed on syntax check!\n$checkpointMessage");
43664365 }
43674366 }
4368
43694367 _printGnuplotPipe($this, "main", "unset multiplot\n");
43704368 $checkpointMessage = _checkpoint($this, "main");
43714369 if($checkpointMessage) {
43764374 }
43774375 }
43784376 $this->{options}->{multiplot} = 0;
4379 $this->close;
4377 $this->close if !$termTab->{$this->{terminal}}{disp};
43804378 }
4381
4382
43834379
43844380 ######################################################################
43854381 ##
49954991 my $rgb = $grey->apply($t);
49964992
49974993 {
4998 no warnings;
4994 no warnings;
49994995 my @s = map {
50004996 sprintf(" %d '#%2.2X%2.2X%2.2X'", $_, $rgb->slice('x',[$_,,0])->list);
50014997 } (0..$grey->dim(0)-1);
50445040 my @s = ();
50455041 for(0..$grey->dim(0)-1) {
50465042 # Turn off warnings to prevent "redundant argument" warnings on certain sprintfs
5047 no warnings;
5043 no warnings;
50485044 my $this_str = sprintf("'#%2.2X%2.2X%2.2X'",$rgb->slice('x',[$_,,0])->list);
50495045 use warnings;
50505046 if($_ == $grey->dim(0)-1 or $this_str ne $last_str) {
50585054 },
50595055 ['clut'],undef,
50605056 '[pseudo] Use PDL::Transform::Color photometric palette: "pseudocolor=>\'heat\'"' ],
5061
5062
5057
5058
50635059 'clut' => [sub { my($old, $new, $this) = @_;
50645060 $new = ($new ? lc $new : "default");
50655061 if($palettesTab->{$new}) {
62016197 #### This differs from cq alone in that it parses font size,
62026198 #### scaling it for anti-aliasing as necessary.
62036199 #### the 'aa' parameter is passed in $h since this is called
6204 #### by the term option emitter in output().
6200 #### by the term option emitter in output().
62056201 'cqf' => sub { my($k,$v,$h) = @_;
62066202 return "" unless(defined($v));
62076203 if($h->{aa} && $v =~ m/(.*)\,(.*)/) {
62416237 }
62426238 return " $k $v ";
62436239 },
6244
6240
62456241
62466242 #### The dashtype curve option
62476243 #### Supports an INVALID value for "with" types that have to suppress dt emission.
69216917 'aqua' => { unit=>'pt', desc=> 'Aqua terminal program on MacOS X (MacOS default device)', int=>1, ok=>1, disp=>1,
69226918 opt=>[ qw/ output_ title size font enhanced / ]},
69236919 'be' => "BeOS/X11 (Ah, Be, how we miss thee) [NS: ancient]",
6924 'cairolatex'=> { unit=>'in', desc=>'Cairo support for .eps or .pdf output with LaTeX text rendering',
6920 'cairolatex'=> { unit=>'in', desc=>'Cairo support for .eps or .pdf output with LaTeX text rendering',
69256921 opt=> [
69266922 ['mode', 's', 'cv', 'terminal mode: set to "eps" or "pdf"'],
69276923 ['textmode', 's', 'cv', 'text mode: set to "black" or "color"'],
6928 ['header', 's', sub { $_[1] ? " header '$_[1]' " : " noheader " },
6924 ['header', 's', sub { $_[1] ? " header '$_[1]' " : " noheader " },
69296925 "LaTeX source for header text"
69306926 ],
69316927 "color",
71717167 'tikz' =>"TikZ package via Lua [NS: obsolete]",
71727168 'tkcanvas'=>"Tcl/Tk canvas widget design [NS: weird]",
71737169 'tpic' =>"Latex picture (use 'latex' or 'eepic') [NS: obsolete]",
7174 'unknown' =>"Unknown term (gnuplot final default) [NS: not a terminal]",
7170 'unknown' =>"Unknown term (gnuplot final default) [NS: not a terminal]",
71757171 'unixpc' =>"AT&T 3b1 and AT&T 7300 UNIX PC display [NS: ancient]",
71767172 'unixplot'=>"UNIX plot(1) language (non-GNU version)[NS: obsolete]",
71777173 'vgagl' =>"Output to a VGA screen under linux [NS: obsolete]",
72107206 $termTab = {};
72117207
72127208 for my $k(keys %$termTabSource) {
7213 next unless(ref($termTabSource->{$k})); # names aren't supported -- eliminate
7209 next unless(ref(my $v = $termTabSource->{$k})); # names aren't supported -- eliminate
72147210 my $terminalOpt = {}; #this will hold the _parseOptHash control structure we generate
72157211 my $i = 1; #this is a sort order counter
72167212
7217 for my $n(@{$termTabSource->{$k}->{opt}}) {
7213 for my $n(@{$v->{opt}}) {
72187214 my $name = $n;
72197215 my $line;
72207216 if(ref $name) {
72217217 $name = $n->[0];
7222 $line = [@{$n}[1..3]];
7218 $line = [@$n[1..3]];
72237219 } else {
72247220 $line = $termTab_types->{$name}
72257221 or die "Bug in parse table build! ('$name' inside terminal '$k')";
72267222 }
7227 $terminalOpt->{$name} = [ $line->[0], $line->[1], undef, $i++, $line->[2]];
7223 $terminalOpt->{$name} = [ @$line[0, 1], undef, $i++, $line->[2]];
72287224 }
72297225 $terminalOpt->{"wait"} = [ 's' , sub { return "" }, undef, $i++, "wait time before throwing an error (default 5s)" ];
7230 my $desc = $termTabSource->{$k}->{desc};
7231 $desc =~ s/\%u/$termTabSource->{$k}->{unit}/;
7226 my $desc = $v->{desc};
7227 $desc =~ s/\%u/$v->{unit}/;
72327228 $termTab->{$k} = { desc => $desc,
7233 unit => $termTabSource->{$k}->{unit},
7234 mouse => _def( $termTabSource->{$k}->{mouse}, 0),
7235 disp => _def( $termTabSource->{$k}->{disp}, 0),
7236 int => _def( $termTabSource->{$k}->{int}, 0),
7229 unit => $v->{unit},
7230 mouse => _def( $v->{mouse}, 0),
7231 disp => _def( $v->{disp}, 0),
7232 int => _def( $v->{int}, 0),
72377233 opt => [ $terminalOpt,
72387234 undef, # This gets filled in on first use in the constructor.
72397235 "$k terminal options"
72407236 ],
7241 default_output=> $termTabSource->{$k} ->{default_output}
7237 default_output=> $v->{default_output}
72427238 };
72437239 }
72447240
75787574 EOM
75797575 }
75807576 }
7581
7577
75827578 # On windows, gnuplot versions 4.6.5 and older echo back commands.
75837579 if ( $gp_numversion <= '4.006' && $gp_pl <= 5 ) {
75847580 $echo_eating = 1;
76507646 $z = waitpid($goner,0);
76517647
76527648 } else {
7649 _printGnuplotPipe($this,$suffix,"set term qt 0 close\n") if $this->{terminal} eq 'qt';
76537650 _printGnuplotPipe($this,$suffix,"exit\n");
76547651
76557652 # Give it 2 seconds to quit, then interrupt it again.
82488245 ##
82498246 # Debugging Gnuplot's horrible indexing problem
82508247 # $PDL::Graphics::Gnuplot::prefrobnicated = [$ndc->mv(0,-1)->dog, $d2];
8251
8248
82528249 if($d2->ndims == 2) {
82538250 $with->[0] = 'image';
82548251 $chunk->{options}->{with} = [@$with];
82878284 $s =~ s/\013/\\r/g;
82888285 return $s;
82898286 }
8290
8287
82918288
82928289 =head1 COMPATIBILITY
82938290
+211
-330
t/plot.t less more
0 use strict;
1 use warnings;
02 use Test::More;
13 use PDL::Graphics::Gnuplot qw(plot gpwin);
24 use File::Temp qw(tempfile);
810 # $PDL::Graphics::Gnuplot::MS_io_braindamage = 1;
911
1012 $ENV{GNUPLOT_DEPRECATED} = 1; # shut up deprecation warnings
11 eval { $w=gpwin() };
13 my $w=eval { gpwin() };
1214
1315 is $@, '';
1416 isa_ok($w, 'PDL::Graphics::Gnuplot', "Constructor created a plotting object");
1517
16 ok(length($PDL::Graphics::Gnuplot::gp_version), "Extracted a version string from gnuplot") or diag "Raw output: '$PDL::Graphics::Gnuplot::raw_output'";
18 isnt $PDL::Graphics::Gnuplot::gp_version, '', "Extracted a version string from gnuplot" or diag "Raw output: '$PDL::Graphics::Gnuplot::raw_output'";
1719
1820 diag( "\nP::G::G v$PDL::Graphics::Gnuplot::VERSION, gnuplot v$PDL::Graphics::Gnuplot::gp_version, Perl v$], $^X on $^O #\n" );
1921
2628 {
2729 # test basic plotting
2830 eval{ plot ( {terminal => 'dumb 79 24', output => $testoutput}, $x); };
29
30
31 is($@, '', 'basic plotting succeeded without error' )
32 or diag "plot() died with '$@'";
33
34 ok(-e $testoutput, 'basic plotting created an output file' )
35 or diag "plot() didn't create an output file";
36
31 is($@, '', 'basic plotting succeeded without error' );
32 ok(-e $testoutput, 'basic plotting created an output file' );
3733 # call the output good if it's at least 80% of the nominal size
3834 my @filestats = stat $testoutput;
39 ok($filestats[7] > 79*24*0.8, 'basic plotting created a reasonably-sized file')
40 or diag "resulting output file should be ascii 79x24, but only contains $filestats[7] bytes";
41
35 cmp_ok($filestats[7], '>', 79*24*0.8, 'basic plotting created a reasonably-sized file');
4236 PDL::Graphics::Gnuplot::restart();
43
44 unlink($testoutput) or warn "\$!: $!";
37 unlink($testoutput) or diag "\$!: $!";
4538 }
4639
4740 ok($PDL::Graphics::Gnuplot::gp_version, "gp_version is nonzero after first use of P::G::G");
4942 ##############################
5043 #
5144 {
52 # purposely fail. This one should fail by sensing that "bogus" is bogus, *before* sending
45 # purposely fail. This one should fail by sensing that "bogus" is bogus, *before* sending
5346 # anything to Gnuplot.
5447
5548 eval{ plot ( {terminal => 'dumb 79 24', output => $testoutput, silent=>1}, with => 'bogus', $x); };
6457 }
6558
6659 ##############################
67 #
68 my $w;
60 #
61 eval { $w = gpwin( 'dumb', size=>[79,24],output=>$testoutput, wait=>1) };
62 is($@, '', "constructor works");
63 isnt ref $w, '', "constructor works";
6964
7065 SKIP:{
7166 # Check timeout.
72 eval {
73 $w = gpwin( 'dumb', size=>[79,24],output=>$testoutput, wait=>1);
74 };
75 ok((!$@ and (ref $w)), "constructor works");
76
7767 skip "Skipping timeout test, which doesn't work under MS Windows", 1
7868 if($PDL::Graphics::Gnuplot::MS_io_braindamage);
79
80 eval {
81 $w->plot ( { topcmds=>'pause 2'}, with=>'line', $x); };
82
83 ok($@ && $@ =~ m/1 second/og, "gnuplot response timeout works" );
69 eval { $w->plot ( { topcmds=>'pause 2'}, with=>'line', $x) };
70 like($@, qr/1 second/, "gnuplot response timeout works");
8471 }
8572
8673 eval { $w->restart };
9380
9481 # Some working variables
9582 $x = xvals(51);
96 my $y = $x*$x;
83 my $y = $x*$x;
9784
9885 do {
9986 # Object options passed into plot are transient
10087 $w = gpwin('dumb',size=>[79,24,'ch'], output=>$testoutput);
10188 $w->options(xr=>[0,30]);
102 ok( (defined($w->{options}->{xrange}) and
103 ((ref $w->{options}->{xrange}) eq 'ARRAY') and
104 ($w->{options}->{xrange}->[0] == 0) and
105 ($w->{options}->{xrange}->[1] == 30))
106 ,
107 "xr sets xrange option properly in options call" );
89 is_deeply $w->{options}{xrange}, [0, 30],
90 "xr sets xrange option properly in options call";
10891 $w->plot($x);
92
93 open FOO, "<$testoutput";
94 my @lines = <FOO>;
95 is( 0+@lines, 24, "setting 79x24 character dumb output yields 24 lines of output");
96 like $lines[-2], qr/.*\s30\s*$/,
97 "xrange option generates proper X axis (and dumb terminal behaves as expected)";
98
99 $w->plot($x,{xr=>[0,5]});
109100
110101 open FOO, "<$testoutput";
111102 @lines = <FOO>;
112 ok( 0+@lines == 24, "setting 79x24 character dumb output yields 24 lines of output");
113 $s = $lines[$#lines - 1];
114 $s =~ s/\s*$//; # trim trailing whitespace
115 $s =~ s/.*\s//; # trim everything before the final X axis label
116 ok( $s == 30, "xrange option generates proper X axis (and dumb terminal behaves as expected)");
117
118 $w->plot($x,{xr=>[0,5]});
119
120 open FOO, "<$testoutput";
121 @lines = <FOO>;
122 $s = $lines[$#lines - 1];
123 $s =~ s/\s*$//; # trim trailing whitespace
124 $s =~ s/.*\s//; # trim everything before the final X axis label
125 ok( $s == 5, "inline xrange option overrides stored xrange option (and dumb terminal behaves as expected)");
126
127 ok( ((defined($w->{options}->{xrange}) and
128 (ref $w->{options}->{xrange}) eq 'ARRAY' and
129 $w->{options}->{xrange}->[0] == 0 and
130 $w->{options}->{xrange}->[1] == 30))
131 ,
132 "inline xrange does not change stored xrange option"
133 );
134
135 ok( (defined ($w->{last_plot}) and
136 (ref ($w->{last_plot}) eq 'HASH') and
137 defined ($w->{last_plot}->{options}) and
138 (ref ($w->{last_plot}->{options}) eq 'HASH') and
139 defined ($w->{last_plot}->{options}->{xrange}) and
140 (ref ($w->{last_plot}->{options}->{xrange}) eq 'ARRAY') and
141 $w->{last_plot}->{options}->{xrange}->[0] == 0 and
142 $w->{last_plot}->{options}->{xrange}->[1] == 5)
143 ,
144 "inline xrange is stored in last_plot options"
145 );
103 like $lines[-2], qr/.*\s5\s*$/,
104 "inline xrange option overrides stored xrange option (and dumb terminal behaves as expected)";
105
106 is_deeply $w->{options}{xrange}, [0, 30],
107 "inline xrange does not change stored xrange option";
108
109 is_deeply $w->{last_plot}{options}{xrange}, [0, 5],
110 "inline xrange is stored in last_plot options";
146111 };
147112
148113 unlink($testoutput) or warn "\$!: $!";
152117 #
153118 # Normally we issue a "reset" before sending options for each plot, to ensure that
154119 # gnuplot is in a known state -- but in multiplots we can't do that or we'd break the
155 # multiplot. We attempt to eradicate leftover state in gnuplot, so we have to test
120 # multiplot. We attempt to eradicate leftover state in gnuplot, so we have to test
156121 # that. The main thing is that labels should be cleared.
157122 {
158123 $w = gpwin('dumb',size=>[79,24,'ch'], output=>$testoutput);
159
160124 $w->multiplot(layout=>[1,2]);
161125 $w->line(xvals(5)**2,{xlabel=>"FOO BAR BAZ"});
162 $w->line(xvals(5)**2); # no xlabel -- should not print one
126 $w->line(xvals(5)**2); # no xlabel -- should not print one
163127 $w->end_multi;
164128 undef $w;
165129 open FOO,"<$testoutput";
166 @lines = grep m/FOO BAR BAZ/,(<FOO>);
167 ok(@lines==1, "xlabel gets reset on multiplots");
130 my @lines = grep m/FOO BAR BAZ/,(<FOO>);
131 is 0+@lines, 1, "xlabel gets reset on multiplots";
168132 }
169133
170134 ##############################
171135 # Test ascii data transfer (binary is tested by default on platforms where it works)
172136 eval {$w = gpwin('dumb', size=>[79,24,'ch'],output=>$testoutput);};
173 ok((!$@ && !!$w),"opened window for ascii transfer tests");
174
175 eval { $w->options( binary=>0 ); };
176 ok( !$@, "set binary mode to 0" );
137 is $@, '';
138 ok($w,"opened window for ascii transfer tests");
139
140 eval { $w->options( binary=>0 ); };
141 is $@, '', "set binary mode to 0";
177142
178143 eval { $w->plot( xvals(5), xvals(5)**2 ); };
179144 is($@, '', "ascii plot succeeded");
180145
181146 eval { $w->plot( xvals(10000), xvals(10000)->sqrt ); };
182 is($@, '', "looong ascii plot succeeded ".($@?"($@)":""));
183
147 is($@, '', "looong ascii plot succeeded ");
184148
185149 ##############################
186150 # Test replotting
187151
188152 eval {$w = gpwin('dumb',size=>[79,24,'ch'], output=>$testoutput)};
189 ok((!$@ && !!$w),"re-opened window");
153 is $@, '';
154 ok($w,"re-opened window");
190155
191156 eval { $w->plot({xr=>[0,30]},xvals(50),xvals(50)**2); };
192157 is($@, ''," plot works");
193158
194
195159 open FOO,"<$testoutput";
196 @lines = <FOO>;
160 my @lines = <FOO>;
197161 close FOO;
198 ok(@lines == 24, "test plot made 24 lines");
162 is(0+@lines, 24, "test plot made 24 lines");
199163
200164 eval { $w->restart(); };
201165 is($@, '',"restart succeeded");
203167 unlink($testoutput) or warn "\$!: $!";
204168 ok(!(-e $testoutput), "test file got deleted");
205169
206
207170 eval { $w->replot(); };
208171 is($@, '', "replot works");
209172
210173 open FOO,"<$testoutput";
211 @l2 = <FOO>;
174 my @l2 = <FOO>;
212175 close FOO;
213176 $w->restart;
214177 unlink($testoutput) or warn "\$!: $!";
215 ok(@l2 == 24, "test replot made 24 lines");
216
217 $same =1;
218 for $i(0..23) {
219 $same &= ($lines[$i] eq $l2[$i]);
220 }
221 ok($same, "replot reproduces output");
178 is(0+@l2, 24, "test replot made 24 lines");
179
180 is_deeply \@lines, \@l2, "replot reproduces output";
222181
223182 eval { $w->replot(xvals(50),40*xvals(50)) };
224183 is($@, '', "replotting and adding a line works");
226185 # lame test - just make sure the plots include at least two lines
227186 # and that one is higher than the other.
228187 open FOO,"<$testoutput";
229 @l3 = <FOO>;
188 my @l3 = <FOO>;
230189 close FOO;
231190 $w->restart;
232191 unlink($testoutput) or warn "\$!: $!";
233 ok(@l3==24,"test replot again made 24 lines");
192 is(0+@l3, 24, "test replot again made 24 lines");
234193
235194 if($w->{gp_version} == 5.0 && $Alien::Gnuplot::pl==0
236195 or
238197 ) {
239198 # gnuplot 5.0 patchlevel 0 uses plusses and hyphens to draw curves in ASCII
240199 # match whitespace / curve / whitespace / curve / whitespace on line 12
241 ok($l3[12] =~ m/\s+[\-\+]+\s+[\-\+]+\s+/, "test plot has two curves");
200 like($l3[12], qr/\s+[\-\+]+\s+[\-\+]+\s+/, "test plot has two curves");
242201 } else {
243202 # most gnuplots use #'s and *'s for the first two ASCII curves
244 ok($l3[12]=~ m/\#\s+\*/, "test plot has two curves and curve 2 is above curve 1");
203 like($l3[12], qr/\#\s+\*/, "test plot has two curves and curve 2 is above curve 1");
245204 }
246205
247206 # test that options updating modifies the replot
249208 is($@, '', "options set and replot don't crash");
250209
251210 open FOO,"<$testoutput";
252 @l4 = <FOO>;
211 my @l4 = <FOO>;
253212 close FOO;
254213 $w->restart;
255214 unlink($testoutput) or warn "\$!: $!";
256 ok(@l4 == 24, "replot made 24 lines after option set");
257
258 $same = 1;
259 for $i(0..23) {
260 $same &= ($l3[$i] eq $l4[$i]);
261 }
262 ok(!$same, "modifying plot option affects replot");
263
215 is 0+@l4, 24, "replot made 24 lines after option set";
216
217 my $diff = grep $l3[$_] ne $l4[$_], 0..23;
218 ok($diff, "modifying plot option affects replot");
264219
265220 ##############################
266221 # Test parsing of plot options when provided before curve options
270225 is($@, '', "plot() worked for x,y plot with unescaped plot option");
271226
272227 eval { $w->plot(ls=>4,xmin=>3,xvals(10),xvals(10)) };
273 ok($@=~m/No curve option found that matches \'xmin\'/, "xmin after a curve option fails (can't mix curve and plot options)");
228 like($@, qr/No curve option found that matches \'xmin\'/, "xmin after a curve option fails (can't mix curve and plot options)");
274229
275230 eval { $w->plot(xmin=>3,xrange=>[4,5],xvals(10),xvals(10)) };
276231 is($@, '', "plot works when curve options are given after plot options");
278233 do {
279234 open FOO,"<$testoutput";
280235 my @lines = <FOO>;
281 ok($lines[22]=~ m/^\s*4\s+.*\s+5\s+$/, "curve option range overrides plot option range");
236 like($lines[22], qr/^\s*4\s+.*\s+5\s+$/, "curve option range overrides plot option range");
282237 close FOO;
283238 };
284239
296251 is($@, '', "two arguments, both arrays, works OK");
297252
298253 eval { $w->plot(xmin=>3,xrange=>[4,5],xvals(10),[1,2,3])};
299 ok($@ =~ m/mismatch/, "Mismatch detected in array size vs. PDL size");
254 like($@, qr/mismatch/, "Mismatch detected in array size vs. PDL size");
300255
301256 ##############################
302257 # Test placement of topcmds, extracmds, and bottomcmds
303258 eval { $w->plot(xmin=>3,extracmds=>'reset',xrange=>[4,5],xvals(10),xvals(10)**2); };
304259 is($@, '', "extracmds does not cause an error");
305 ok( $PDL::Graphics::Gnuplot::last_plotcmd =~ m/\]\s+reset\s+plot/o, "extracmds inserts exactly one copy in the right place");
260 like($PDL::Graphics::Gnuplot::last_plotcmd, qr/\]\s+reset\s+plot/o, "extracmds inserts exactly one copy in the right place");
306261
307262 eval { $w->plot(xmin=>3,topcmds=>'reset',xrange=>[4,5],xvals(10),xvals(10)**2);};
308263 is($@, '', "topcmds does not cause an error");
309 ok( $PDL::Graphics::Gnuplot::last_plotcmd =~ m/set\s+output\s+\"[^\"]+\"\s+reset\s+set\s+palette/o, "topcmds inserts exactly one copy in the right place");
264 like($PDL::Graphics::Gnuplot::last_plotcmd, qr/set\s+output\s+\"[^\"]+\"\s+reset\s+set\s+palette/o, "topcmds inserts exactly one copy in the right place");
310265
311266 eval { $w->plot(xmin=>3,bottomcmds=>'reset',xrange=>[4,5],xvals(10),xvals(10)**2);};
312267 is($@, '', "bottomcmds does not cause an error");
313 ok( $PDL::Graphics::Gnuplot::last_plotcmd =~ m/\]\s+reset\s*$/o, "bottomcmds inserts exactly one copy in the right place");
268 like($PDL::Graphics::Gnuplot::last_plotcmd, qr/\]\s+reset\s*$/o, "bottomcmds inserts exactly one copy in the right place");
314269
315270 ##############################
316271 # Test tuple size determination: 2-D, 3-D, and variables (palette and variable)
323278 is($@, '', "2-D line plot accepts two PDLs");
324279
325280 eval { $w->plot(xvals(10),xvals(10),xvals(10));};
326 ok($@ =~ m/Found 3 PDLs for 2D plot type/, "2-D line plot rejects three PDLs");
281 like($@, qr/Found 3 PDLs for 2D plot type/, "2-D line plot rejects three PDLs");
327282
328283 eval { $w->plot(ps=>'variable',with=>'points',xvals(10),xvals(10),xvals(10)) };
329284 is($@, '', "2-D plot with one variable parameter takes three PDLs");
330285
331286 eval { $w->plot(ps=>'variable',with=>'points',xvals(10),xvals(10),xvals(10),xvals(10)) };
332 ok($@ =~ m/Found 4 PDLs for 2D/, "2-D plot with one variable parameter rejects four PDLs");
287 like($@, qr/Found 4 PDLs for 2D/, "2-D plot with one variable parameter rejects four PDLs");
333288
334289 SKIP: {
335 skip "Skipping unsupported mode for deprecated earlier gnuplot",1
290 skip "Skipping unsupported mode for deprecated earlier gnuplot",1
336291 if($PDL::Graphics::Gnuplot::gp_version < 4.4);
337292 eval { $w->plot3d(xvals(10,10))};
338293 is($@, '', "3-D plot accepts one PDL if it is an image");
339294 };
340295
341296 eval { $w->plot3d(xvals(10),xvals(10)); };
342 ok($@ =~ m/Found 2 PDLs for 3D/,"3-D plot rejects two PDLs");
297 like($@, qr/Found 2 PDLs for 3D/,"3-D plot rejects two PDLs");
343298
344299 eval { $w->plot3d(xvals(10),xvals(10),xvals(10)); };
345300 is($@, '', "3-D plot accepts three PDLs");
346301
347302 eval { $w->plot3d(xvals(10),xvals(10),xvals(10),xvals(10)); };
348 ok($@ =~ m/Found 4 PDLs for 3D/,"3-D plot rejects four PDLs");
303 like($@, qr/Found 4 PDLs for 3D/,"3-D plot rejects four PDLs");
349304
350305 eval { $w->plot3d(ps=>'variable',with=>'points',xvals(10),xvals(10),xvals(10),xvals(10));};
351306 is($@, '', "3-D plot accepts four PDLs with one variable element");
352307
353308 eval { $w->plot3d(with=>'points',ps=>'variable',palette=>1,xvals(10),xvals(10),xvals(10),xvals(10));};
354 ok($@ =~ m/Found 4 PDLs for 3D/,"3-D plot rejects four PDLs with two variable elements");
309 like($@, qr/Found 4 PDLs for 3D/,"3-D plot rejects four PDLs with two variable elements");
355310
356311 SKIP: {
357 skip "Skipping unsupported mode for deprecated earlier gnuplot",1
312 skip "Skipping unsupported mode for deprecated earlier gnuplot",1
358313 if($PDL::Graphics::Gnuplot::gp_version < 4.4);
359314 eval { $w->plot3d(with=>'points',ps=>'variable',palette=>1,xvals(10),xvals(10),xvals(10),xvals(10),xvals(10));};
360315 is($@, '', "3-D plot accepts five PDLs with one variable element");
361316 } ;
362317
363318 eval { $w->plot3d(with=>'points',ps=>'variable',palette=>1,xvals(10),xvals(10),xvals(10),xvals(10),xvals(10),xvals(10));};
364 ok($@ =~ m/Found 6 PDLs for 3D/,"3-D plot rejects six PDLs with two variable elements");
319 like($@, qr/Found 6 PDLs for 3D/,"3-D plot rejects six PDLs with two variable elements");
365320
366321
367322 ##############################
370325 is($@, '', "normal legend plotting works OK");
371326
372327 eval { $w->plot(legend=>['line 1', 'line 2'], pdl(2,3,4)); };
373 ok($@ =~ m/Legend has 2 entries; but 1 curve/, "Failure to thread crashes");
328 like($@, qr/Legend has 2 entries; but 1 curve/, "Failure to thread crashes");
374329
375330 eval { $w->plot(legend=>['line 1'], pdl([2,3,4],[1,2,3])); };
376 ok($@ =~ m/Legend has 1 entry; but 2 curve/, "Failure to thread crashes (other way)");
331 like($@, qr/Legend has 1 entry; but 2 curve/, "Failure to thread crashes (other way)");
377332
378333 eval { $w->plot(legend=>['line 1','line 2'], pdl([2,3,4],[1,2,3]),[3,4,5]) };
379 ok($@ =~ m/only 1-D PDLs are allowed to be mixed with array/, "Can't thread with array refs");
334 like($@, qr/only 1-D PDLs are allowed to be mixed with array/, "Can't thread with array refs");
380335
381336 eval { $w->plot(legend=>['line 1','line 2'], pdl([2,3,4],[1,2,3]),[3,4]) };
382 ok($@ =~ m/only 1-D PDLs/, "Mismatched arguments are rejected");
337 like($@, qr/only 1-D PDLs/, "Mismatched arguments are rejected");
383338
384339 ##############################
385340 # Test non-persistence of autoset options
386341 eval { $w->options(xrange=>[1,2]); };
387 ok((!$@ and $w->{options}->{xrange}->[0] == 1 and $w->{options}->{xrange}->[1] == 2), "xrange set ok\n");
342 is_deeply $w->{options}{xrange}, [1, 2], "xrange set ok\n";
388343
389344 eval { $w->reset; $w->restart; };
390345 is($@, '', "reset was ok\n");
391346
392 ok( !defined($w->{options}->{xrange}), "reset cleared xrange option" );
347 is $w->{options}{xrange}, undef, "reset cleared xrange option";
393348
394349 eval { $w->plot(with=>'lines', xvals(5)); };
395 ok( !defined($w->{options}->{xrange}), "plotting a line did not set xrange option" );
350 is $w->{options}{xrange}, undef, "plotting a line did not set xrange option";
396351
397352 eval { $w->plot(with=>'image', rvals(5,5)); };
398 ok( !defined($w->{options}->{xrange}), "plotting an image did not set xrange option" );
399
353 is $w->{options}{xrange}, undef, "plotting an image did not set xrange option";
400354
401355 ##############################
402356 # Test esoteric argument parsing
403357
404358 eval { $w->plot(with=>'lines',y2=>3,xvals(5)); };
405 ok($@ =~ m/No curve option found that matches \'y2\'/,"y2 gets rejected");
359 like($@, qr/No curve option found that matches \'y2\'/,"y2 gets rejected");
406360
407361 eval { $w->plot(with=>'lines',xvals(5),{lab2=>['foo',at=>[2,3]]}); };
408362 is($@, '', "label is accepted ($@)");
418372
419373 sub get_axis_testoutput {
420374 my $file = shift;
421 my $n = shift;
422375 open FOO,"<$file";
423376 my @lines = <FOO>;
424
425377 chomp for @lines;
426
427378 for my $i(0..$#lines) {
428379 last if( $lines[$#lines] =~ m/[^\s]/ );
429380 pop @lines;
430381 }
431
432 return @lines[-1..-$n];
382 my $line = $lines[-1];
383 $line =~ s/^\s+//;
384 $line;
433385 }
434386
435387 eval { $w->plot(xvals(50)->sqrt) };
436 ok( !$@, "plotting after reset worked ok with autotics" );
437
438
439 $line_nums = (get_axis_testoutput($testoutput, 1));
440 $line_nums =~ s/^\s+//;
441 $nums= pdl( split /\s+/,$line_nums);
442
443 ok( $nums->nelem==11 && all( $nums == pdl(0,5,10,15,20,25,30,35,40,45,50) ), "autogenerated tics work (case 1)" );
444
388 is $@, '', "plotting after reset worked ok with autotics";
389
390 my $line_nums = get_axis_testoutput($testoutput);
391 is_deeply [split /\s+/,$line_nums], [0,5,10,15,20,25,30,35,40,45,50], "autogenerated tics work (case 1)";
445392
446393 eval { $w->plot(xvals(50)->sqrt,{xtics=>0}) };
447394 is($@, '', "xvals plot (no xtics) succeeded");
448395
449 ok($w->{last_plotcmd} =~ m/unset xtics/o, "xtics=>0 generated an 'unset xtics' command");
450
451
452 $line_nums = (get_axis_testoutput($testoutput,1));
453 ok($line_nums =~ m/\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-/, "No labels with xtics=>0");
454
396 like($w->{last_plotcmd}, qr/unset xtics/, "xtics=>0 generated an 'unset xtics' command");
397
398 $line_nums = get_axis_testoutput($testoutput);
399 like $line_nums, qr/-------------------------------/, "No labels with xtics=>0";
455400
456401 eval { $w->plot(xvals(50)->sqrt,{"mxtics"=>{}})};
457402 is($@, '', "plot with mxtics set to a hash succeeded");
459404 eval { $w->plot(xvals(50)->sqrt,{xtics=>10})};
460405 is($@, '', "xvals plot(xtics=>10) succeeded");
461406
462 $line_nums = (get_axis_testoutput($testoutput,1));
463 $line_nums =~ s/^\s+//;
464 $nums= pdl( split /\s+/,$line_nums);
465 ok( $nums->nelem==6 && all( $nums == pdl(0,10,20,30,40,50) ), "tics with spacing 10 work");
407 $line_nums = get_axis_testoutput($testoutput);
408 is_deeply [split /\s+/,$line_nums], [0,10,20,30,40,50], "tics with spacing 10 work";
466409
467410 eval { $w->plot(xvals(50)->sqrt, {xtics=>[]}) };
468411 is($@, '', "xvals plot (xtics=>[]) succeeded");
469412
470 $line_nums = (get_axis_testoutput($testoutput, 1));
471 $line_nums =~ s/^\s+//;
472 $nums= pdl( split /\s+/,$line_nums);
473 ok( $nums->nelem==11 && all( $nums == pdl(0,5,10,15,20,25,30,35,40,45,50) ), "autogenerated tics work (case 2)" );
413 $line_nums = get_axis_testoutput($testoutput);
414 is_deeply [split /\s+/,$line_nums], [0,5,10,15,20,25,30,35,40,45,50], "autogenerated tics work (case 2)";
474415
475416 undef $w;
476417 unlink($testoutput) or warn "\$!: $!";
484425 eval { $w->plot(xvals(500)-10, xvals(500)+40, { autoscale=>{} }) };
485426 is($@, '', "autoscale accepts an empty hash ref");
486427
487 $ticks = (get_axis_testoutput($testoutput,1));
488 $ticks =~ s/^\s*//;
489 $ticks = pdl(split /\s+/,$ticks);
490 ok($ticks->nelem==12 && all($ticks == pdl(-50,0,50,100,150,200,250,300,350,400,450,500)),"autoscale=>{} gives correct scaling");
491
492 eval { $w->plot(xvals(500)-10,xvals(500)+40,{ autoscale=>{x=>fix}}); };
428 my $ticks = get_axis_testoutput($testoutput);
429 is_deeply [split /\s+/,$ticks], [-50,0,50,100,150,200,250,300,350,400,450,500], "autoscale=>{} gives correct scaling";
430
431 eval { $w->plot(xvals(500)-10,xvals(500)+40,{ autoscale=>{x=>'fix'}}); };
493432 is($@, '', "autoscale accepts a non-empty hash ref");
494433
495 $ticks = (get_axis_testoutput($testoutput,1));
496 $ticks=~ s/^\s*//;
497 $ticks = pdl(split /\s+/,$ticks);
498 ok($ticks->nelem==10 && all($ticks == pdl(0,50,100,150,200,250,300,350,400,450)),"autoscale=>{x=>fix} fixes the X axis scaling");
434 $ticks = get_axis_testoutput($testoutput);
435 is_deeply [split /\s+/,$ticks], [0,50,100,150,200,250,300,350,400,450], "autoscale=>{x=>fix} fixes the X axis scaling";
499436
500437 undef $w;
501438 unlink($testoutput) or warn "\$!: $!";
502439
503440
504441 ##############################
505 # Check default-location plotting
442 # Check default-location plotting
506443 if( -e 'Plot-1.txt' ) {
507444 unlink 'Plot-1.txt' or warn "Can't delete Plot-1.txt: $!";
508445 }
521458 # accepts both array ref and scalar parameters.
522459 eval {$w=gpwin('dumb',size=>[7,5]); $w->line(xvals(50)**2); $w->close;};
523460 is($@, '', "plotting to 42x30 text file worked");
524 eval {open FOO,"<Plot-1.txt"; @lines = <FOO>; close FOO;};
461 @lines = eval {open FOO,"<Plot-1.txt"; my @l = <FOO>; close FOO;@l};
525462 is($@, '', "read ASCII plot OK");
526463 eval { unlink 'Plot-1.txt';};
527464
528 ok(@lines+0 == 30, "'7x5 inch' ascii plot created 30 lines (created ".(0+@lines).")");
465 is(@lines+0, 30, "'7x5 inch' ascii plot created 30 lines (created ".(0+@lines).")");
529466
530467 eval {$w=gpwin('dumb',size=>5); $w->line(xvals(50)**2); $w->close;};
531468 is($@, '', "plotting to 30x30 text file worked");
533470 is($@, '', "Read ASCII plot #2 OK");
534471 eval { unlink 'Plot-1.txt';};
535472
536 ok(@lines+0==30,"'5x5 inch' ascii plot with scalar size param worked");
537
473 is(@lines+0, 30,"'5x5 inch' ascii plot with scalar size param worked");
538474
539475 ##############################
540476 # Interactive tests
477
478 sub ask_yn {
479 my ($msg, $label) = @_;
480 print STDERR "\n\n$msg (Y/n)";
481 my $a = <STDIN>;
482 unlike($a, qr/n/i, $label);
483 }
541484
542485 SKIP: {
543486 unless(exists($ENV{GNUPLOT_INTERACTIVE})) {
545488 skip "Skipping interactive tests - set env. variable GNUPLOT_INTERACTIVE to enable.",29;
546489 }
547490
548 eval { $w = gpwin('wxt'); };
549 if($@) {
550 $@ = undef;
551 eval { $w = gpwin('x11'); }
552 }
491 eval { $w = gpwin('wxt') };
492 eval { $w = gpwin('x11') } if $@;
553493 is($@, '', "created a wxt or x11 plot object");
554494
555 ok((ref($PDL::Graphics::Gnuplot::termTab->{$w->{terminal}}) eq 'HASH'), "Terminal is a known type");
556
495 isa_ok $PDL::Graphics::Gnuplot::termTab->{$w->{terminal}}, 'HASH', "Terminal is a known type";
496
557497 ok($PDL::Graphics::Gnuplot::termTab->{$w->{terminal}}->{disp}, "Default terminal is a display type");
558498 print STDERR "\n\nwindow is type ".$w->{terminal}."\n\n";
559 $x = sequence(101)-50;
499 my $x = sequence(101)-50;
560500
561501 eval { $w->plot($x**2); };
562502 is($@, '', "plot a parabola to a the display window");
563
564 print STDERR "\n\nIs there a display window and does it show a parabola? (Y/n)";
565 $a = <STDIN>;
566 ok($a !~ m/n/i, "parabola looks OK");
503 ask_yn "Is there a display window and does it show a parabola?", "parabola looks OK";
567504
568505 if($PDL::Graphics::Gnuplot::termTab->{$w->{terminal}}->{disp}>1) {
569 print STDERR "\n\nMouse over the plot window. Are there metrics at bottom that update? (Y/n)";
570 $a = <STDIN>;
571 ok($a !~ m/n/i, "parabola has metrics");
572
573
506 ask_yn "Mouse over the plot window. Are there metrics at bottom that update?", "parabola has metrics";
574507 if($PDL::Graphics::Gnuplot::gp_version < 4.6) {
575508 print STDERR "\n\nYou're running an older gnuplot ($PDL::Graphics::Gnuplot::gp_version) and \nwon't be able to scroll. You should upgrade. Skipping scroll test.\n\n";
576509 ok(1,"no scroll/zoom test");
577510 } else {
578 print STDERR "\n\nTry to scroll and zoom the parabola using the scrollbar or (mac) two-fingered\n scrolling in Y; use SHIFT to scroll in X, CTRL (command on mac) to zoom. Does it work? (Y/n)";
579 $a = <STDIN>;
580 ok($a !~ m/n/i, "parabola can be scrolled and zoomed");
511 ask_yn "Try to scroll and zoom the parabola using the scrollbar or (mac) two-fingered\n scrolling in Y; use SHIFT to scroll in X, CTRL (command on mac) to zoom. Does it work?", "parabola can be scrolled and zoomed";
581512 }
582
583
584513 } else {
585514 print STDERR "\n\nThe $w->{terminal} gnuplot terminal has no built-in metrics, skipping that test.\n\n";
586515 ok(1,"skipping metrics test");
587
588516 print STDERR "\n\nThe $w->{terminal} gnuplot terminal has no interactive zoom, skipping that test.\n\n";
589517 ok(1,"skipping interactive-zoom test");
590518 }
595523 {y2t=>[0,5e7,4e8],y2r=>[0,3.5e8]}
596524 );};
597525 print $PDL::Graphics::Gnuplot::last_plotcmd."\n";
598 print STDERR "\n\nAre there two curves labeled X^2 and X^5, with about the same vertical extent on the plot? (Y/n)";
599 $a = <STDIN>;
600 ok($a !~ m/n/i, "two curves are OK");
601
602 print STDERR "\n\nAre there appropriate tick marks in both Y1 and Y2 on opposite sides of the plot?\n";
603 print STDERR " (There should be no ghost ticks from Y1 on the Y2 axis, or vice versa). (Y/n)";
604 $a = <STDIN>;
605 ok($a !~ m/n/i, "ticks look OK");
526 ask_yn "Are there two curves labeled X^2 and X^5, with about the same vertical extent on the plot?", "two curves are OK";
527 ask_yn "Are there appropriate tick marks in both Y1 and Y2 on opposite sides of the plot?\n (There should be no ghost ticks from Y1 on the Y2 axis, or vice versa).", "ticks look OK";
606528
607529 eval { $w->reset; $w->options(binary=>0,tee=>1); $w->plot( {title => "Parabola with error bars"},
608530 with=>"xyerrorbars", legend=>"Parabola",
609531 $x**2 * 10, abs($x)/10, abs($x)*5 ); };
610532 print $PDL::Graphics::Gnuplot::last_plotcmd."\n";
611 print STDERR "\n\nAre there error bars in both X and Y, both increasing away from the vertex, wider in X than Y? (Y/n)";
612 $a = <STDIN>;
613 ok($a !~ m/n/i, "error bars are OK");
614
615 $xy = zeros(21,21)->ndcoords - pdl(10,10);
616 $z = inner($xy, $xy);
617 eval { $w->reset; $w->plot({title => 'Heat map',
533 ask_yn "Are there error bars in both X and Y, both increasing away from the vertex, wider in X than Y?", "error bars are OK";
534
535 my $xy = zeros(21,21)->ndcoords - pdl(10,10);
536 my $z = inner($xy, $xy);
537 eval { $w->reset; $w->plot({title => 'Heat map',
618538 '3d' => 1,
619539 view=>[50,30,1],
620540 zrange=>[-1,1]
621541 },
622 with => 'image', $z*2);
542 with => 'image', $z*2);
623543 };
624544 is($@, '', "3-d plot didn't crash");
625
626 print STDERR "\n\nDo you see a purple-yellow colormap image of a radial target, in 3-D? (Y/n)";
627 $a = <STDIN>;
628 ok($a !~ m/n/i, "3-D heat map plot works OK");
629
630 print STDERR "\n\nTry to rotate, pan, and zoom the 3-D image. Work OK? (Y/n)";
631 $a = <STDIN>;
632 ok($a !~ m/n/i, "Interact with 3-D image");
633
634 $pi = 3.14159;
635 $theta = zeros(200)->xlinvals(0, 6*$pi);
545 ask_yn "Do you see a purple-yellow colormap image of a radial target, in 3-D?", "3-D heat map plot works OK";
546 ask_yn "Try to rotate, pan, and zoom the 3-D image. Work OK?", "Interact with 3-D image";
547
548 my $pi = 3.14159;
549 my $theta = zeros(200)->xlinvals(0, 6*$pi);
636550 $z = zeros(200)->xlinvals(0, 5);
637551 eval { $w->reset; $w->plot3d(cos($theta), sin($theta), $z); };
638
639552 is($@, '', "plot3d works");
640
641 print STDERR "\n\nSee a nice 3-D plot of a spiral? (Y/n)";
642 $a = <STDIN>;
643 ok($a !~ m/n/i, "See a nice 3-D plot of a spiral?");
553 ask_yn "See a nice 3-D plot of a spiral?", "See a nice 3-D plot of a spiral?";
644554
645555 $x = xvals(5);
646556 $y = xvals(5)**2;
647 $labels = ['one','two','three','four','five'];
557 my $labels = ['one','two','three','four','five'];
648558 eval { $w->reset; $w->plot(xr=>[-1,6],yr=>[-1,26],with=>'labels',$x,$y,$labels); };
649 print STDERR "\n\nSee the labels with words 'one','two','three','four', and 'five'? (Y/n)";
650 $a = <STDIN>;
651 ok($a !~ m/n/i, "labels plot is OK");
652
559 ask_yn "See the labels with words 'one','two','three','four', and 'five'?", "labels plot is OK";
560
653561 $x = xvals(51)-25; $y = $x**2;
654562 eval { $w->reset; $w->plot({title=>"Parabolic fit"},
655563 with=>"yerrorbars", legend=>"data", $x, $y+(random($y)-0.5)*2*$y/20, pdl($y/20),
656564 with=>"lines", legend=>"fit", $x, $y); };
657565 is($@, '', "mocked-up fit plot works");
658 print STDERR "\n\nSee a green parabola with red error bar points on it? (Y/n)";
659 $a = <STDIN>;
660 ok($a !~ m/n/i, "parabolic plot is OK");
661
662 $pi = 3.14159;
566 ask_yn "See a green parabola with red error bar points on it?", "parabolic plot is OK";
567
663568 $theta = xvals(201) * 6 * $pi / 200;
664569 $z = xvals(201) * 5 / 200;
665
666570 eval { $w->reset; $w->plot( {'3d' => 1, title => 'double helix'},
667571 with => 'linespoints', pointsize=>'variable', pointtype=>2, palette=>1 ,
668572 legend => 'spiral 1',
672576 legend => 'spiral 2',
673577 -cos($theta), -sin($theta), $z, 0.5 + abs(cos($theta)*2),
674578 sin($theta/3)
675 );};
676
579 );};
677580 is($@, '', "double helix plot worked");
678
679 print STDERR "\n\nSee a double helix plot with variable point sizes and variable color? (Y/n)";
680 $a = <STDIN>;
681 ok($a !~ m/n/i, "double helix plot is OK");
581 ask_yn "See a double helix plot with variable point sizes and variable color?", "double helix plot is OK";
682582
683583 eval { $w->reset; $w->plot( with=>'image', rvals(9,9), {xr=>[undef,9]}) };
684584 is($@, '', "image plot succeeded");
685 print STDERR <<"FOO";
686
687
688 You should see a 9x9 rvals image, scaled from -0.5 to 9.0 in X and -0.5 to
689 8.5 in y. There should be a blank vertical bar 1/2 unit wide at the right
690 side of the image. The other sides of the plot should be flush. Ok? (Y/n)
691 FOO
692 $a =<STDIN>;
693
694 ok($a !~ m/n/i, "image initial ranging plot is OK");
695
696 eval { $w->plot(with=>'image',rvals(9,9),
585 ask_yn "You should see a 9x9 rvals image, scaled from -0.5 to 9.0 in X and -0.5 to
586 8.5 in y. There should be a blank vertical bar 1/2 unit wide at the right
587 side of the image. The other sides of the plot should be flush. Ok?",
588 "image initial ranging plot is OK";
589
590 eval { $w->plot(with=>'image',rvals(9,9),
697591 with=>'image', xvals(9,9)+7, yvals(9,9)+4, rvals(9,9),
698592 with=>'line', xvals(20)->sqrt
699593 );
700594 };
701595 is($@, '', "two-image range test plot succeeded");
702 print STDERR <<"FOO";
703
704
705 You should see two overlapping rvals images, with lower left pixels centered
706 on (0,0) and (7,4), respectively, and a square root curve superimposed.
707 The y range should be flush with the top and bottom of the two images. The
708 x range should be set by the image at left and the curve at right, running
709 from -0.5 to 20.0. The curve should end at 19.0. Ok? (Y/n)
710 FOO
711 $a = <STDIN>;
712 ok($a !~ m/n/i, "image/line ranging plot is OK");
596 ask_yn "You should see two overlapping rvals images, with lower left pixels centered
597 on (0,0) and (7,4), respectively, and a square root curve superimposed.
598 The y range should be flush with the top and bottom of the two images. The
599 x range should be set by the image at left and the curve at right, running
600 from -0.5 to 20.0. The curve should end at 19.0. Ok?",
601 "image/line ranging plot is OK";
713602
714603 if($PDL::Bad::Status) {
715 eval {
604 eval {
716605 $w = gpwin();
717606 $w->multiplot(layout=>[2,1]);
718 $a = xvals(11)**2;
607 $a = xvals(11)**2;
719608 $a->slice("(5)") .= asin(pdl(1.1));
720609 $b = (xvals(11)**2)->setbadif(xvals(11)==5);
721610 print "a=$a\n";
725614 $w->line($b, {title=>"Parabola with BAD at x=5"});
726615 $w->end_multi;
727616 };
728
729617 is($@, '', "bad value plot succeeded");
730 print STDERR <<"FOO";
731
732 The two panels should have the same plot with different titles: Y=X**2,
733 with a segment missing from X=4 to X=6. OK?
734 FOO
735 $a = <STDIN>;
736 ok($a !~ m/n/i, "bad value plot looks OK");
618 ask_yn "The two panels should have the same plot with different titles: Y=X**2,
619 with a segment missing from X=4 to X=6. OK?",
620 "bad value plot looks OK";
737621 } else {
738622 ok(1, "Skipping bad-value test since this PDL doesn't support badvals");
739623 ok(1, "Skipping bad-value test since this PDL doesn't support badvals");
745629 #
746630
747631 if( $ENV{DISPLAY} and $PDL::Graphics::Gnuplot::valid_terms->{x11} ) {
748 eval { $w=gpwin(x11); $w->image(rvals(9,9), {title=>"X11 window for mouse test"}) };
632 eval { $w=gpwin('x11'); $w->image(rvals(9,9), {title=>"X11 window for mouse test"}) };
749633 is($@, '', "plotting to x11 window worked.");
750634
751635 print STDERR "\n\nClick in the X11 window for mouse test.\n";
753637 is($@, '', "Mouse test read a click");
754638
755639 # Try with a new window
756 $w=gpwin($w->{terminal});
640 $w=gpwin($w->{terminal});
757641 eval { print $w->read_mouse(); };
758642 like $@, qr/no existing/,"Trying to read the mouse input on an empty window doesn't work";
759
643
760644 } else {
761645 ok(1,"Skipping x11 plot");
762646 ok(1,"Skipping click test for non-x11 device");
770654 is($@, '', "dumb terminal still works");
771655
772656 # Some date stamps
773 @dates = (-14552880, # Apollo 11 launch
657 my @dates = (-14552880, # Apollo 11 launch
774658 0, # UNIX epoch
775659 818410080, # SOHO launch
776660 946684799, # The banking system did not melt down.
777661 1054404000); # A happy moment in 2003
778 $dates = pdl(@dates);
662 my $dates = pdl(@dates);
779663
780664 eval { $w->plot( {xdata=>'time'}, with=>'points', $dates->clip(0), xvals($dates) ); };
781665 is($@, '', "time plotting didn't fail");
782666 open FOO,"<$testoutput";
783 $lines1 = join("",(<FOO>));
667 my $lines1 = join("",(<FOO>));
784668 close FOO;
785669
786670 eval { $w->plot( {xr=>[0,$dates->max],xdata=>'time'}, with=>'points', $dates, xvals($dates) ); };
787671 is($@, '', "time plotting with range didn't fail");
788672 open FOO,"<$testoutput";
789 $lines2 = join("",(<FOO>));
673 my $lines2 = join("",(<FOO>));
790674 close FOO;
791675
792676 eval { $w->plot( {xr=>[$dates->at(3),$dates->at(4)], xdata=>'time'}, with=>'points', $dates, xvals($dates));};
793677 is($@, '', "time plotting with a different range didn't fail");
794678 open FOO,"<$testoutput";
795 $lines3 = join("",(<FOO>));
679 my $lines3 = join("",(<FOO>));
796680 close FOO;
797681
798682 print "lines1:\n$lines1\n\nlines2:\n$lines2\n\nlines3:\n$lines3\n\n";
799683 SKIP: {
800684 skip "Skipping date ranging tests since Gnuplot itself doesn't work",2;
801 ok($lines1 eq $lines2, "Setting the time range to what it would be anyway duplicates the graph");
802 ok($lines2 cmp $lines3, "Modifying the time range modifies the graph");
685 is($lines1, $lines2, "Setting the time range to what it would be anyway duplicates the graph");
686 isnt($lines2, $lines3, "Modifying the time range modifies the graph");
803687 }
804688
805689
813697 close FOO;
814698
815699 SKIP:{
816 skip "Skipping title tests due to obsolete version of gnuplot (BSD uses 4.2, which fails these)",3
700 skip "Skipping title tests due to obsolete version of gnuplot (BSD uses 4.2, which fails these)",3
817701 if($w->{gp_version} < $PDL::Graphics::Gnuplot::gnuplot_req_v);
818702
819703 like("@lines[0..3]", qr/This is a plot title/, "Plot title gets placed on plot")
821705
822706 eval { $w->plot({title=>""},with=>'points',xvals(5));};
823707 is($@, '', "Non-title plotting works, no error");
824
708
825709 open FOO,"<$testoutput";
826710 @lines = <FOO>;
827711 close FOO;
828712 if($w->{gp_version} < 5.2) {
829 ok($lines[1] =~ m/^\s*$/, "Setting empty plot title sets an empty title");
713 like($lines[1], qr/^\s*$/, "Setting empty plot title sets an empty title");
830714 } else {
831715 # Late-model gnuplots use the top lines if there is no title
832 ok($lines[1] =~ m/\-{50,70}/);
716 like($lines[1], qr/\-{50,70}/);
833717 }
834718 }
835719
842726 eval { $w->plot({trid=>1,title=>""},with=>'lines',sequence(3,3)); };
843727 is($@, '', "3-d grid plot with single column succeeded");
844728 open FOO,"<$testoutput";
845 $lines = join("",<FOO>);
729 my $lines = join("",<FOO>);
846730 close FOO;
847
731
848732 eval { $w->plot({trid=>1,title=>"",yr=>[-1,1]},with=>'lines',cdim=>1,sequence(3,3));};
849733 is($@, '', "3-d threaded plot with single column succeeded");
850734 open FOO,"<$testoutput";
851 $lines2 = join("",<FOO>);
735 my $lines2 = join("",<FOO>);
852736 close FOO;
853
854 ok( $lines2 ne $lines, "the two 3-D plots differ");
737
738 isnt( $lines2, $lines, "the two 3-D plots differ");
855739
856740 if( $w->{gp_version} < 5.0 ) {
857 ok( ($lines2 =~ m/\#/) && ($lines !~ m/\#/) , "the threaded plot has traces the grid lacks");
741 like $lines2, qr/\#/;
742 unlike $lines, qr/\#/, "the threaded plot has traces the grid lacks";
858743 } else {
859744 # 5.0 no longer uses hashes and asterisks to distinguish the lines, so just check that the plot
860745 # changed.
861 skip "Skipping hash/asterisk test since gnuplot is 5.0 or newer",1;
746 skip "Skipping hash/asterisk test since gnuplot is 5.0 or newer", 2;
862747 }
863748 }
864749
883768
884769 eval { $w->options(xrange=>pdl(1,2)) };
885770 is($@, '', "xrange accepts a PDL option");
886
887 ok( (ref($w->{options}->{xrange}) eq 'ARRAY' and
888 $w->{options}->{xrange}->[0] == 1 and
889 $w->{options}->{xrange}->[1] == 2
890 ),
891 "xrange parses a 2-PDL into a list ref");
771 is_deeply $w->{options}{xrange}, [1, 2],
772 "xrange parses a 2-PDL into a list ref";
892773
893774 eval { $w->options(xrange=>pdl(1,2,3)) };
894 ok($@, "xrange rejects a PDL with more than 2 elements");
775 isnt($@, '', "xrange rejects a PDL with more than 2 elements");
895776
896777 eval {$w->options(xrange=>[21]);};
897778 is($@, '', "xrange accepts a single list element");
898
899 ok( ( ref($w->{options}->{xrange}) eq 'ARRAY' and
900 $w->{options}->{xrange}->[0] == 21 and
901 !defined($w->{options}->{xrange}->[1])
902 ), "xrange parses single list element correctly");
779 is_deeply $w->{options}{xrange}, [21],
780 "xrange parses single list element correctly";
903781
904782 eval { $w->options(justify=>"0") };
905783 is($@, '', "justify accepts quoted zero");
906784
907785 eval { $w->options(justify=>"-1") };
908 ok($@ =~ m/positive/, "justify rejects negative numbers");
786 like($@, qr/positive/, "justify rejects negative numbers");
909787 undef $@;
910788
911789 eval { $w->options(justify=>"1") };
923801 eval { $w->plot(with=>'lines',xvals(5)) };
924802 is($@, '', "ascii plot with implicit col succeeded");
925803
926 ok($PDL::Graphics::Gnuplot::last_plotcmd =~ m/plot +\'\-\' +using 0\:1 /,
804 like($PDL::Graphics::Gnuplot::last_plotcmd, qr/plot +\'\-\' +using 0\:1 /,
927805 "ascii plot with implicit col uses explicit reference to column 0");
928806
929807 eval { $w->plot(with=>'lines',xvals(5),xvals(5)) };
930808 is($@, '', "ascii plot with no implicit col succeeded");
931 ok($PDL::Graphics::Gnuplot::last_plotcmd =~ m/plot +\'\-\' +using 1\:2 /s,
809 like($PDL::Graphics::Gnuplot::last_plotcmd, qr/plot +\'\-\' +using 1\:2 /s,
932810 "ascii plot with no implicit cols uses columns 1 and 2");
933811
934812 eval { $w->plot(with=>'lines',xvals(5,5)) };
935813 is($@, '', "ascii plot with threaded data and implicit column succeeded");
936 ok($PDL::Graphics::Gnuplot::last_plotcmd =~ m/plot +\'-\' +using 0\:1 [^u]+using 0\:1 /s,
814 like($PDL::Graphics::Gnuplot::last_plotcmd, qr/plot +\'-\' +using 0\:1 [^u]+using 0\:1 /s,
937815 "threaded ascii plot with one implicit col does the Right Thing");
938816
939817
940818 eval { $w->plot(with=>'lines',xvals(5),{trid=>1}) };
941819 is($@, '', "ascii 3-d plot with 2 implicit cols succeeded");
942 ok($PDL::Graphics::Gnuplot::last_plotcmd =~ m/plot +\'-' +using 0\:\(\$0\*0\)\:1 /s,
820 like($PDL::Graphics::Gnuplot::last_plotcmd, qr/plot +\'-' +using 0\:\(\$0\*0\)\:1 /s,
943821 "ascii plot with two implicit cols uses column 0 and zeroed-out column 0");
944822
945823 eval { $w->plot(with=>'lines',xvals(5),xvals(5),{trid=>1})};
946 ok($@, "ascii 3-d plot with 1 implicit col fails (0 or 2 only)");
824 isnt($@, '', "ascii 3-d plot with 1 implicit col fails (0 or 2 only)");
947825
948826 eval { $w->plot(with=>'lines',xvals(5),xvals(5),xvals(5),{trid=>1}) };
949827 is($@, '', "ascii 3-d plot with no implicit cols succeeds");
950 ok($PDL::Graphics::Gnuplot::last_plotcmd=~ m/plot +\'-\' +using 1\:2\:3 /s,
828 like($PDL::Graphics::Gnuplot::last_plotcmd, qr/plot +\'-\' +using 1\:2\:3 /s,
951829 "ascii 3-d plot with no implicit cols does the Right Thing");
952830
953831 eval { $w->plot(with=>'lines',xvals(5,5),{trid=>1}) };
954832 is($@, '', "ascii 3-d plot with 2-D data and 2 implicit cols succeeded");
955 ok($PDL::Graphics::Gnuplot::last_plotcmd =~ m/splot +\"-\" binary array\=\(5,5\) /s,
833 like($PDL::Graphics::Gnuplot::last_plotcmd, qr/splot +\"-\" binary array\=\(5,5\) /s,
956834 "ascii plot with 2-D data and 2 implicit cols uses binary ARRAY mode");
957835
958836 eval { $w->plot(with=>'lines',xvals(5,5),xvals(5,5),{trid=>1}) };
959 ok($@, "ascii 3-d plot with 2-D data and 1 implicit col fails (0 or 2 only)");
837 isnt($@, '', "ascii 3-d plot with 2-D data and 1 implicit col fails (0 or 2 only)");
960838
961839 eval { $w->plot(with=>'lines',xvals(5,5),xvals(5,5),xvals(5,5),{trid=>1}) };
962840 is($@, '', "ascii 3-d plot with 2-D data and no implicit cols succeeded");
963 ok($PDL::Graphics::Gnuplot::last_plotcmd =~ m/splot +\"-\" binary record\=\(5,5\) /s,
841 like($PDL::Graphics::Gnuplot::last_plotcmd, qr/splot +\"-\" binary record\=\(5,5\) /s,
964842 "ascii plot with 2-D data and no implicit cols uses binary RECORD mode");
965843
966844 eval { $w->plot(with=>'yerrorbars', (xvals(50)-25)**2, pdl(0.5),{binary=>0}) };
978856
979857 open FOO, "<$testoutput";
980858 @lines = <FOO>;
981 ok( ( (length($lines[12]) != 0) and (substr($lines[12],20,40) =~ m/^\s+$/) ), "NaN makes a blank in a plot");
859 isnt $lines[12], '';
860 like substr($lines[12],20,40), qr/^\s+$/, "NaN makes a blank in a plot";
982861
983862 $w->restart;
984863 $w->plot(with=>'lines',$b,{binary=>1});
985864 $w->close;
986865 open FOO, "<$testoutput";
987866 @lines = <FOO>;
988 ok( ( (length($lines[12]) != 0) and !(substr($lines[12],20,40) =~ m/^\s+$/) ), "No NaN makes a nonblank in a plot");
867 isnt $lines[12], '';
868 unlike substr($lines[12],20,40), qr/^\s+$/, "No NaN makes a nonblank in a plot";
989869
990870 $w->restart;
991871 $w->plot(with=>'lines',$b,{binary=>0});
992872 $w->close;
993873 open FOO, "<$testoutput";
994874 @lines = <FOO>;
995 ok( ( (length($lines[12]) != 0) and !(substr($lines[12],20,40) =~ m/^\s+$/) ), "No NaN makes a nonblank in a plot even with ASCII");
875 isnt $lines[12], '';
876 unlike substr($lines[12],20,40), qr/^\s+$/, "No NaN makes a nonblank in a plot even with ASCII";
996877
997878 $w->restart;
998879 $w->plot(with=>'lines',$a,{binary=>0});
999880 $w->close;
1000881 open FOO, "<$testoutput";
1001882 @lines = <FOO>;
1002 ok( ( (length($lines[12]) != 0) and (substr($lines[12],20,40) =~ m/^\s+$/) ), "NaN makes a blank in a plot even with ASCII");
883 isnt $lines[12], '';
884 like substr($lines[12],20,40), qr/^\s+$/, "NaN makes a blank in a plot even with ASCII";
1003885
1004886 # Test plotting of PDL subclasses
1005887 @MyPackage::ISA = qw/PDL/;
1008890 eval { $w->plot( $a ); };
1009891 is $@, '', "subclass of PDL plots OK";
1010892
1011 # Test terminal defaulting
893 # Test terminal defaulting
1012894 eval { $w=PDL::Graphics::Gnuplot::new(size=>[9,9]); undef($w);};
1013895 is $@, '', "default terminal is selected OK";
1014896
1024906 print STDERR "\n***********\nSkipping default-plot-output tests: files 'Plot-1.txt' and/or 'Plot-2.txt' exist.\n***********\n";
1025907 skip "Plot-1.txt and/or Plot-2.txt exist, can't check default plotting", 4;
1026908 }
1027
1028 $w=gpwin(dumb);
909 $w=gpwin('dumb');
1029910 eval { $w->line(xvals(20)**3); };
1030 ok( !$@, "default-output plot succeeded" );
911 is( $@, '', "default-output plot succeeded" );
1031912 ok( -e "Plot-1.txt", "Plot got made" );
1032913 eval { $w->line(xvals(10)**4); };
1033 ok (!$@, "default-output plot succeeded again");
914 is($@, '', "default-output plot succeeded again");
1034915 ok( -e "Plot-2.txt", "Second plot got made" );
1035916 unlink "Plot-1.txt";
1036917 unlink "Plot-2.txt";