Skip to content

Commit 86e9c16

Browse files
committed
tidy Gnuplot
1 parent 5d34b77 commit 86e9c16

File tree

1 file changed

+47
-57
lines changed

1 file changed

+47
-57
lines changed

lib/PDL/Graphics/Simple/Gnuplot.pm

+47-57
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ sub check {
6565
$mod->{msg} = $@;
6666
return 0;
6767
}
68-
if($PDL::Graphics::Gnuplot::VERSION < $required_PGG_version) {
68+
if ($PDL::Graphics::Gnuplot::VERSION < $required_PGG_version) {
6969
$mod->{msg} = sprintf("PDL::Graphics::Gnuplot was found, but is too old (v%s < v%s). Ignoring it.\n",
7070
$PDL::Graphics::Gnuplot::VERSION,
7171
$required_PGG_version
@@ -138,7 +138,7 @@ sub new {
138138
my $conv_tempfile = '';
139139

140140
# Do different things for interactive and file types
141-
if($opt->{type} =~ m/^i/i) {
141+
if ($opt->{type} =~ m/^i/i) {
142142
push(@params, title=>$opt->{output}) if defined $opt->{output};
143143
# Interactive - try known terminals unless PDL_SIMPLE_DEVICE given
144144
push @params, font=>"=16", dashed=>1;
@@ -156,7 +156,7 @@ sub new {
156156
eval { $gpw = gpwin($try, @params,
157157
($disp_opts->{$try} // {})->{persist} ? (persist=>0) : ()
158158
); };
159-
last attempt if($gpw);
159+
last attempt if $gpw;
160160
}
161161
}
162162
die "Couldn't start a gnuplot interactive window" unless($gpw);
@@ -168,7 +168,7 @@ sub new {
168168

169169
# Filename extension -- 2-4 characters
170170
my $ext;
171-
if($opt->{output} =~ m/\.(\w{2,4})$/) {
171+
if ($opt->{output} =~ m/\.(\w{2,4})$/) {
172172
$ext = $1;
173173
} else {
174174
$ext = '.png';
@@ -184,22 +184,22 @@ sub new {
184184
my $ft = $filetypes->{$ext};
185185
if (ref $ft eq 'ARRAY') {
186186
try:for my $try (@$ft) {
187-
if($mod->{valid_terms}->{$try}) {
187+
if ($mod->{valid_terms}{$try}) {
188188
$ft = $try;
189189
last try;
190190
}
191191
}
192192
if (ref($ft)) {
193193
$ft = undef;
194194
}
195-
} elsif (!defined($mod->{valid_terms}->{$ft})) {
195+
} elsif (!defined($mod->{valid_terms}{$ft})) {
196196
$ft = undef;
197197
}
198198

199199
# Now $ext has the file type - check if its a supported type. If not, make a
200200
# tempfilename to hold gnuplot's output.
201201
unless ( defined($ft) ) {
202-
unless ($mod->{valid_terms}->{'pscairo'} or $mod->{valid_terms}->{'postscript'}) {
202+
unless ($mod->{valid_terms}{pscairo} or $mod->{valid_terms}{postscript}) {
203203
die "PDL::Graphics::Simple: $ext isn't a valid output file type for your gnuplot,\n\tand it doesn't support .ps either. Sorry, I give up.\n";
204204
}
205205

@@ -209,20 +209,20 @@ sub new {
209209
close $fh;
210210
unlink($conv_tempfile); # just to be sure;
211211
$conv_tempfile .= ".ps";
212-
$ft = $mod->{valid_terms}->{'pscairo'} ? 'pscairo' : 'postscript';
212+
$ft = $mod->{valid_terms}{pscairo} ? 'pscairo' : 'postscript';
213213
}
214-
push(@params, "output" => ($conv_tempfile || $opt->{output}) );
215-
push(@params, "color" => 1 ) if( $PDL::Graphics::Gnuplot::termTab->{$ft}->{'color'} );
216-
push(@params, "dashed" => 1 ) if( $PDL::Graphics::Gnuplot::termTab->{$ft}->{'dashed'} );
214+
push @params, output => ($conv_tempfile || $opt->{output});
215+
push @params, color => 1 if $PDL::Graphics::Gnuplot::termTab->{$ft}{color};
216+
push @params, dashed => 1 if $PDL::Graphics::Gnuplot::termTab->{$ft}{dashed};
217217
$gpw = gpwin( $ft, @params );
218218
}
219219

220220

221221
my $me = { opt => $opt, conv_fn => $conv_tempfile, obj=>$gpw };
222222

223223
# Deal with multiplot setup...
224-
if(defined($opt->{multi})) {
225-
$me->{nplots} = $opt->{multi}->[0] * $opt->{multi}->[1];
224+
if (defined($opt->{multi})) {
225+
$me->{nplots} = $opt->{multi}[0] * $opt->{multi}[1];
226226
$me->{plot_no} = 0;
227227
} else {
228228
$me->{nplots} = 0;
@@ -265,19 +265,19 @@ our $curve_types = {
265265
for my $i(0..$data[0]->dim(0)-1) {
266266
my $j = "";
267267
my $s = $data[2]->[$i];
268-
if( $s =~ s/^([\<\>\| ])// ) {
268+
if ( $s =~ s/^([\<\>\| ])// ) {
269269
$j = $1;
270270
}
271271

272272
my @spec = ("$s", at=>[$data[0]->at($i), $data[1]->at($i)]);
273-
push(@spec,"left") if($j eq '<');
274-
push(@spec,"center") if($j eq '|');
275-
push(@spec,"right") if($j eq '>');
276-
push( @{$label_list}, \@spec );
273+
push @spec,"left" if $j eq '<';
274+
push @spec,"center" if $j eq '|';
275+
push @spec,"right" if $j eq '>';
276+
push @{$label_list}, \@spec;
277277
}
278278
$po->{label} = $label_list;
279279
$co->{with} = "labels";
280-
return [ $co, [$po->{xrange}->[0]], [$po->{yrange}->[0]], [""] ];
280+
return [ $co, [$po->{xrange}[0]], [$po->{yrange}[0]], [""] ];
281281
}
282282

283283
};
@@ -299,50 +299,49 @@ sub plot {
299299
clut => 'sepia',
300300
};
301301

302-
if( defined($ipo->{legend}) ) {
302+
if ( defined($ipo->{legend}) ) {
303303
my $legend = "";
304-
if( $ipo->{legend} =~ m/l/i ) {
304+
if ( $ipo->{legend} =~ m/l/i ) {
305305
$legend .= ' left ';
306-
} elsif($ipo->{legend} =~ m/r/i) {
306+
} elsif ($ipo->{legend} =~ m/r/i) {
307307
$legend .= ' right ';
308308
} else {
309309
$legend .= ' center ';
310310
}
311-
if( $ipo->{legend} =~ m/t/i) {
311+
if ( $ipo->{legend} =~ m/t/i) {
312312
$legend .= ' top ';
313-
} elsif( $ipo->{legend} =~ m/b/i) {
313+
} elsif ( $ipo->{legend} =~ m/b/i) {
314314
$legend .= ' bottom ';
315315
} else {
316316
$legend .= ' center ';
317317
}
318318
$po->{key} = $legend;
319319
}
320320

321-
$po->{logscale} = [$ipo->{logaxis}] if($ipo->{logaxis});
321+
$po->{logscale} = [$ipo->{logaxis}] if $ipo->{logaxis};
322322

323323
unless($ipo->{oplot}) {
324324
$me->{curvestyle} = 0;
325325
}
326326

327-
my @arglist = ($po);
327+
my @arglist = $po;
328328

329-
for my $block(@_) {
329+
for my $block (@_) {
330330
die "PDL::Graphics::Simple::Gnuplot: undefined curve type $block->[0]{with}"
331331
unless my $ct = $curve_types->{ $block->[0]{with} };
332-
if(ref($ct) eq 'CODE') {
332+
if (ref($ct) eq 'CODE') {
333333
$block = &$ct($me, $po, @$block);
334334
} else {
335-
$block->[0]->{with} = $ct;
335+
$block->[0]{with} = $ct;
336336
}
337337

338338
# Now parse out curve options and deal with line styles...
339339
my $co = shift @$block;
340-
my $gco = {};
341-
$gco->{with} = $co->{with};
340+
my $gco = { with => $co->{with} };
342341

343342
unless($co->{with} eq 'labels') {
344343

345-
if(defined($co->{style}) and $co->{style}) {
344+
if (defined $co->{style}) {
346345
$me->{curvestyle} = $co->{style};
347346
} else {
348347
$me->{curvestyle}++;
@@ -351,53 +350,44 @@ sub plot {
351350
$gco->{linetype} = $me->{curvestyle};
352351
}
353352

354-
if( defined($co->{width}) and $co->{width} and $co->{with} !~ m/^label/ ) {
355-
my $s;
356-
if($co->{with} =~ m/^points/) {
357-
$gco->{pointsize} = $co->{width};
358-
}
353+
if ( $co->{width} and $co->{with} !~ m/^label/ ) {
354+
$gco->{pointsize} = $co->{width} if $co->{with} =~ m/^points/;
359355
$gco->{linewidth} = $co->{width};
360356
}
361-
$gco->{legend} = $co->{key} if(defined($co->{key}));
357+
$gco->{legend} = $co->{key} if defined $co->{key};
362358

363-
push(@arglist, ($gco, @$block));
359+
push @arglist, $gco, @$block;
364360
}
365361

366-
if($me->{nplots}) {
362+
if ($me->{nplots}) {
367363
unless($me->{plot_no}) {
368-
$me->{obj}->multiplot( layout=>[$me->{opt}->{multi}->[0], $me->{opt}->{multi}->[1]] );
364+
$me->{obj}->multiplot( layout=>[@{$me->{opt}{multi}}[0,1]] );
369365
}
370366
}
371367

372-
if($ipo->{oplot}) {
373-
delete $po->{logaxis};
374-
delete $po->{xrange};
375-
delete $po->{yrange};
376-
delete $po->{cbrange};
377-
delete $po->{justify};
368+
if ($ipo->{oplot}) {
369+
delete @$po{qw(logaxis xrange yrange cbrange justify)};
378370
$me->{obj}->replot(@arglist);
379371
} else {
380372
$me->{obj}->plot(@arglist);
381373
}
382374

383375

384-
if($me->{nplots}) {
376+
if ($me->{nplots}) {
385377
$me->{plot_no}++;
386-
if($me->{plot_no} >= $me->{nplots}) {
387-
$me->{obj}->end_multi();
378+
if ($me->{plot_no} >= $me->{nplots}) {
379+
$me->{obj}->end_multi;
388380
$me->{plot_no} = 0;
389-
390-
$me->{obj}->close() if($me->{opt}->{type} =~ m/^f/i);
391-
381+
$me->{obj}->close if $me->{opt}{type} =~ m/^f/i;
392382
}
393383
} else {
394-
$me->{obj}->close() if($me->{opt}->{type} =~ m/^f/i);
384+
$me->{obj}->close if $me->{opt}{type} =~ m/^f/i;
395385
}
396386

397-
if($me->{opt}->{type} =~ m/^f/i and $me->{conv_fn}) {
398-
print "converting $me->{conv_fn} to $me->{opt}->{output}...";
387+
if ($me->{opt}{type} =~ m/^f/i and $me->{conv_fn}) {
388+
print "converting $me->{conv_fn} to $me->{opt}{output}...";
399389
$a = rim($me->{conv_fn});
400-
wim($a->slice('-1:0:-1')->mv(1,0), $me->{opt}->{output});
390+
wim($a->slice('-1:0:-1')->mv(1,0), $me->{opt}{output});
401391
unlink($me->{conv_fn});
402392
}
403393
}

0 commit comments

Comments
 (0)