Graphics/Gnuplot.pm

filter: Statementstmt 59.5% 1300 / 2183 Branchbran 42.0% 599 / 1426 Conditioncond 40.9% 274 / 670 MC/DCmcdc 19.1% 72 / 376 Subroutinesub 51.5% 114 / 221 Podpod 89.6% 26 / 29 totaltotal 48.6% 2385 / 4905 CC 991 SCAR 53.1
CC
991
Cov
51%
terminfo
1406.0
_plot_generate
681.5
read_mouse
650.0
CRAP 201.4
↑ Summary Demos/Gnuplot.pm »
1 ##############################
2 #
3 # PDL::Graphics::Gnuplot
4 #
5 # This glue module is complicated because it connects a complicated
6 # syntax (Perl) to another complicated syntax (Gnuplot). Here is a
7 # quick internal overview to get your bearings, above the usual POD.
8 #
9 # PDL::Graphics::Gnuplot (P:G:G) objects generally are associated with
10 # an external gnuplot process, and data are passed to the process
11 # through a pipe. It is possible to intercept the data going through
12 # the pipe, either by diverting (dumping) data to stdout instead of
13 # gnuplot, or by teeing the data to stdout as well as gnuplot.
14 # Further, you can turn on syntax checking to validate P:G:G itself.
15 # Syntax checking is performed in a second P:G:G process, since
16 # screwing up the synchronization between Gnuplot and the P:G:G state
17 # is hazardous in the event of syntax error.
18 #
19 # The perl P:G:G object attempts to store and manage essentially
20 # all of the state that is also held inside the gnuplot program.
21 # This takes the form of:
22 # - Terminal options - setup for a given terminal output
23 # - Plot options - setup per-plot
24 # - Curve options - setup per-curve within a plot
25 #
26 # Option handling uses branch tables. Plot and curve options are
27 # parsed using the $pOptionsTable and $cOptionsTable respectively -
28 # these are big global hashes that describe the gnuplot syntax.
29 # Terminal options are "worser" - the options that are accepted depend
30 # on the terminal device, so the table $termTab contains a
31 # description of which terminal options are allowed for each of the
32 # supported gnuplot terminals.
33 #
34 # All options handling is performed through parsing and emitter
35 # routines that are pointed to from those three tables. That is
36 # handled with _parseOptHash(), which accepts an input parameter and a
37 # particular option description table, and parses the input according
38 # to the table. The opposite (used for command generation) is
39 # _emitOpts(), which takes a parsed hash and emits an appropriate
40 # (sub)command into its returned string.
41 #
42 # There are some plot modes that we want to support, and that gnuplot
43 # itself does not yet support. These are "mocked up" using data
44 # prefrobnicators. Currently there is only one of those - FITS
45 # imagery.
46 #
47 # The gnuplot syntax is more than a little byzantine, and this is
48 # reflected in the code - specifically, in the code in plot(), which
49 # is the main workhorse.
50 #
51 # plot() pulls plot arguments off the front and back of the argument
52 # list. It relies on its subroutine parseArgs to break the remaining
53 # parameters into chunks of parameters, each of which represents a
54 # single curve (including curve options and actual data to be
55 # plotted). Because we allow threading, a given batch of curve option
56 # arguments and data can yield many chunks. Those chunks are then
57 # passed through a number of steps back in the main plot() routine,
58 # and turned into a colllection of gnuplot commands suitable for plot
59 # generation.
60 #
61 # Because option parsing and handling is slightly more complicated
62 # than simply interpreting values and assigning defaults, we do not
63 # use a pre-existing package (such as PDL::Options) for option parsing
64 # - we use a dual parse table scheme. Each option set has an "abbrev"
65 # table that is generated at compile time and resolves unique
66 # abbreviations; and a "parse" table that indicates what to do with
67 # each option. Since this mechanism is near at hand, we use it even
68 # for routines (such as read_polygon) that could and would use
69 # PDL::Options in other circumstances.
70  
71 =encoding UTF-8
72  
73 =head1 NAME
74  
75 PDL::Graphics::Gnuplot - Gnuplot-based plotting for PDL
76  
77 =head1 SYNOPSIS
78  
79 pdl> use PDL::Graphics::Gnuplot;
80  
81 pdl> $x = sequence(101) - 50;
82 pdl> gplot($x**2);
83 pdl> gplot($x**2,{xr=>[0,50]});
84  
85 pdl> gplot( {title => 'Parabola with error bars'},
86 with => 'xyerrorbars', legend => 'Parabola',
87 $x**2 * 10, abs($x)/10, abs($x)*5 );
88  
89 pdl> $xy = zeroes(21,21)->ndcoords - pdl(10,10);
90 pdl> $z = inner($xy, $xy);
91 pdl> gplot({title => 'Heat map',
92 trid => 1,
93 view => [0,0]
94 },
95 with => 'image', xvals($z),yvals($z),zeroes($z),$z*2
96 );
97  
98 pdl> $w = gpwin(); # constructor
99 pdl> $pi = 3.14159;
100 pdl> $theta = zeroes(200)->xlinvals(0, 6*$pi);
101 pdl> $z = zeroes(200)->xlinvals(0, 5);
102 pdl> $w->plot3d(cos($theta), sin($theta), $z);
103 pdl> $w->terminfo(); # get information
104  
105  
106 =head1 DESCRIPTION
107  
108 This module allows PDL data to be plotted using Gnuplot as a backend
109 for 2D and 3D plotting and image display. Gnuplot (not affiliated
110 with the GNU project) is a venerable, open-source program that
111 produces both interactive and publication-quality plots on many
112 different output devices. It is available through most Linux
113 repositories, on MacOS, and from its website
114 L<http://www.gnuplot.info>.
115  
116 It is not necessary to understand the gnuplot syntax to generate
117 basic, or even complex, plots - though the full syntax is available
118 for advanced users who want the full flexibility of the Gnuplot
119 backend.
120  
121 For a very quick demonstration of the power of this module, see
122 L<this YouTube demo video|https://www.youtube.com/watch?v=hUXDQL3rZ_0>,
123 and others on visualisation of
124 L<tesseract assembly|https://www.youtube.com/watch?v=ykQmNrSKqGQ> and
125 L<rotation|https://www.youtube.com/watch?v=6tpsPYBrHy0>.
126  
127 Gnuplot recognizes both hard-copy and interactive plotting devices,
128 and on interactive devices (like X11) it is possible to pan, scale,
129 and rotate both 2-D and 3-D plots interactively. You can also enter
130 graphical data through mouse clicks on the device window. On some
131 hardcopy devices (e.g. "PDF") that support multipage output, it is
132 necessary to close the device after plotting to ensure a valid file is
133 written out.
134  
135 C<PDL::Graphics::Gnuplot> exports two routines by default: a
136 constructor, C<gpwin()> and a general purpose plot routine,
137 C<gplot()>. Depending on options, C<gplot()> can produce line plots,
138 scatterplots, error boxes, "candlesticks", images, or any overlain
139 combination of these elements; or perspective views of 3-D renderings
140 such as surface plots.
141  
142 A call to C<gplot()> looks like:
143  
144 gplot({temp_plot_options}, # optional hash ref
145 curve_options, data, data, ... ,
146 curve_options, data, data, ... );
147  
148 The data entries are columns to be plotted. They are normally
149 an optional ordinate and a required abscissa, but some plot modes
150 can use more columns than that. The collection of columns is called
151 a "tuple". Each column must be a separate PDL or an ARRAY ref. If
152 all the columns are PDLs, you can add extra dimensions to make threaded
153 collections of curves.
154  
155 PDL::Graphics::Gnuplot also implements an object oriented
156 interface. Plot objects track individual gnuplot subprocesses. Direct
157 calls to C<gplot()> are tracked through a global object that stores
158 globally set configuration variables.
159  
160 The C<gplot()> sub (or the C<plot()> method) collects two kinds of
161 options hash: B<plot options>, which describe the overall structure of
162 the plot being produced (e.g. axis specifications, window size, and
163 title), and B<curve options>, which describe the behavior of
164 individual traces or collections of points being plotted. In
165 addition, the module itself supports options that allow direct
166 pass-through of plotting commands to the underlying gnuplot process.
167  
168 =head2 Basic plotting
169  
170 Gnuplot generates many kinds of plot, from basic line plots and histograms
171 to scaled labels. Individual plots can be 2-D or 3-D, and different sets
172 of plot styles are supported in each mode. Plots can be sent to a variety
173 of devices; see the description of plot options, below.
174  
175 You can specify what type of graphics output you want, but in most cases
176 doing nothing will cause a plot to be rendered on your screen: with
177 X windows on UNIX or Linux systems, with an XQuartz window on MacOS,
178 or with a native window on Microsoft Windows.
179  
180 You select a plot style with the "with" curve option, and feed in columns
181 of data (usually ordinate followed by abscissa). The collection of columns
182 is called a "tuple". These plots have two columns in their tuples:
183  
184 $x = xvals(51)-25; $y = $x**2;
185 gplot(with=>'points', $x, $y); # Draw points on a parabola
186 gplot(with=>'lines', $x, $y); # Draw a parabola
187 gplot({title=>"Parabolic fit"},
188 with=>"yerrorbars", legend=>"data", $x, $y+(random($y)-0.5)*2*$y/20, pdl($y/20),
189 with=>"lines", legend=>"fit", $x, $y);
190  
191 Normal threading rules apply across the arguments to a given plot.
192  
193 All data are required to be supplied as either PDLs or array refs.
194 If you use an array ref as a data column, then normal
195 threading is disabled. For example:
196  
197 $x = xvals(5);
198 $y = xvals(5)**2;
199 $labels = ['one','two','three','four','five'];
200 gplot(with=>'labels',$x,$y,$labels);
201  
202 See below for supported curve styles.
203  
204 =head3 Modifying plots
205  
206 Gnuplot is built around a monolithic plot model - it is not possible to
207 add new data directly to a plot without redrawing the entire plot. To support
208 replotting, PDL::Graphics::Gnuplot stores the data you plot in the plot object,
209 so that you can add new data with the "replot" command:
210  
211 $w=gpwin(x11);
212 $x=xvals(101)/100;
213 $y=$x;
214 $w->plot($x,$y);
215 $w->replot($x,$y*$y);
216  
217 For speed, the data are *not* disconnected from their original variables - so
218 this will plot X vs. sqrt(X):
219  
220 $x = xvals(101)/100;
221 $y = xvals(101)/100;
222 $w->plot($x,$y);
223 $y->inplace->sqrt;
224 $w->replot();
225  
226 =head3 Plotting to an image file or device
227  
228 PDL:Graphics::Gnuplot can plot to most of the devices supported by
229 gnuplot itself. You can specify the file type with the "output"
230 method or the object constructor "gplot". Either one will allow you
231 to name a type of file to produce, and a collection of options speciic to
232 that type of output file.
233  
234 =head3 Image plotting
235  
236 Several of the plot styles accept image data. The tuple parameters work the
237 same way as for basic plots, but each "column" is a 2-D PDL rather than a 1-D PDL.
238 As a special case, the "with image" plot style accepts either a 2-D or a 3-D PDL.
239 If you pass in 3-D PDL, the extra dimension can have size 1, 3, or 4. It is interpreted
240 as running across (R,G,B,A) color planes.
241  
242 =head3 3-D plotting
243  
244 You can plot in 3-D by setting the plot option C<trid> to a true value. Three
245 dimensional plots accept either 1-D or 2-D PDLs as data columns. If you feed
246 in 2-D "columns", many of the common plot styles will generalize appropriately
247 to 3-D. For example, to plot a 2-D surface as a line grid, you can use the "lines"
248 style and feed in 2-D columns instead of 1-D columns.
249  
250 =head2 Enhanced text
251  
252 Most gnuplot output devices include the option to markup "enhanced text". That means
253 text is interpreted so that you can change its font and size, and insert superscripts
254 and subscripts into labels. Codes are:
255  
256 =over 3
257  
258 =item {}
259  
260 Text grouping - enclose text in braces to group characters, as in LaTeX.
261  
262 =item ^
263  
264 Superscript the next character or group (shrinks it slightly too where that is supported).
265  
266 =item _
267  
268 Subscript the next character or group (shrinks it slightly too where that is supported).
269  
270 =item @
271  
272 Phantom box (occupies no width; controls height for super- and subscripting)
273  
274 =item &
275  
276 Controllable-width space, e.g. &amp;{template-string}
277  
278 =item ~
279  
280 overstrike -- e.g. ~a{0.8-} overprints '-' on 'a', raised by 0.8xfontsize.
281  
282 =item {/[fontname][=fontsize | *fontscale] text}
283  
284 Change font to (optional) fontname, and optional absolute font size or relative font scale ("fontsize" and "fontscale" are numbers). The space after the size parameter is not rendered.
285  
286 =item \
287  
288 Backslash escapes control characters to render them as themselves.
289  
290 =back
291  
292 =head2 Unicode text
293  
294 Separately to "enhanced" text above, if you wish to include text that
295 is not ASCII, then you will need to pass data that has been UTF-8
296 encoded. Sample code to achieve this:
297  
298 use utf8;
299 use Encode;
300 use PDL;
301 use PDL::Graphics::Gnuplot;
302 use PDL::Constants qw(PI);
303  
304 sub plot_sin {
305 my ($w, $coeff) = @_;
306 my $xrange = [ -2*PI, 2*PI ];
307 my $x = zeroes(1e3)->xlinvals(@$xrange); my $y = sin($coeff * 2 * PI * $x);
308 my $title = "y = sin( $coeff * 2Ï€ * x )";
309 # to get around sending text through syswrite()
310 my $title_octets = encode('UTF-8', $title);
311 $w->plot(with=>'lines', $x, $y, {
312 xrange => $xrange,
313 title => $title_octets, # can not pass $title as-is
314 });
315 }
316  
317 =head2 Color specification
318  
319 There are several contexts where you can specify color of plot elements. In those
320 places, you can specify colors exactly as in the Gnuplot manual, or more tersely.
321 In general, a color spec can be any one of the following:
322  
323 =over 3
324  
325 =item - an integer
326  
327 This specifies a recognizable unique color in the same order as used by the plotting engine.
328  
329 =item - the name of a color
330  
331 (e.g. "blue"). Supported color names are listed in the variable C<@Alien::Gnuplot::colors>.
332  
333 =item - an RGB value string
334  
335 Strings have the form C<#RRGGBB>, where the C<#> is literal and the RR, GG, and BB are hexadecimal bytes.
336  
337 =item - the word "palette"
338  
339 "palette" indicates that color is to be drawn from the scaled colorbar
340 palette (which you can set with the "clut" plot option), by lookup
341 using an additional column in the associated data tuple.
342  
343 =item - the word "variable"
344  
345 "variable" indicates that color is to be drawn from the integer
346 plotting colors used by the plotting engine, indexed by an additional
347 column in the associated data tuple.
348  
349 =item - the phrase "rgb variable"
350  
351 "rgb variable" indicates that color is to be directly specified by a
352 24 bit integer specifying 8-bit values for (from most significant byte
353 to least significant byte) R, G, and B in the output color. The
354 integer is drawn from an additional column in the associated data tuple.
355  
356 =back
357  
358  
359 =head2 Plot styles supported
360  
361 Gnuplot itself supports a wide range of plot styles, and all are supported by
362 PDL::Graphics::Gnuplot. Most of the basic plot styles collect tuples of 1-D columns
363 in 2-D mode (for ordinary plots), or either 1-D or 2-D "columns" in 3-D mode (for
364 grid surface plots and such). Image modes always collect tuples made of 2-D "columns".
365  
366 You can pass in 1-D columns as either PDLs or ARRAY refs. That is important for
367 plot types (such as "labels") that require a collection of strings rather than
368 numeric data.
369  
370 Each plot style can by modified to support particular colors or line
371 style options. These modifications get passed in as curve options (see
372 below). For example, to plot a blue line you can use
373 C<with=E<gt>'lines',lc=E<gt>'blue'>. To match the autogenerated style of a
374 particular line you can use the C<ls> curve option.
375  
376 The GNuplot plot styles supported are:
377  
378 =over 3
379  
380 =item * C<boxerrorbars> - combo of C<boxes> and C<yerrorbars>, below (2D)
381  
382 =item * C<boxes> - simple boxes around regions on the plot (2D)
383  
384 =item * C<boxxyerrorbars> - Render X and Y error bars as boxes (2D)
385  
386 =item * C<candlesticks> - Y error bars with inner and outer limits (2D)
387  
388 =item * C<circles> - circles with variable radius at each point: X/Y/radius (2D)
389  
390 =item * C<dots> - tiny points ("dots") at each point, e.g. for scatterplots (2D/3D)
391  
392 =item * C<ellipses> - ellipses. Accepts X/Y/major/minor/angle (2D)
393  
394 =item * C<filledcurves> - closed polygons or axis-to-line filled shapes (2D)
395  
396 =item * C<financebars> - financial style plot. Accepts date/open/low/high/close (2D)
397  
398 =item * C<fsteps> - square bin plot; delta-Y, then delta-X (see C<steps>, C<histeps>) (2D)
399  
400 =item * C<histeps> - square bin plot; plateaus centered on X coords (see C<fsteps>, C<steps>) (2D)
401  
402 =item * C<histogram> - binned histogram of dataset (not direct plot; see C<newhistogram>) (2D)
403  
404 =item * C<fits> - (PDL-specific) renders FITS image files in scientific coordinates
405  
406 =item * C<image> - Takes (i), (x,y,i), or (x,y,z,i). See C<rgbimage>, C<rgbalpha>, C<fits>. (2D/3D)
407  
408 =item * C<impulses> - vertical line from axis to the plotted point (2D/3D)
409  
410 =item * C<labels> - Text labels at specified locations all over the plot (2D/3D)
411  
412 =item * C<lines> - regular line plot (2D/3D)
413  
414 =item * C<linespoints> - line plot with symbols at plotted points (2D/3D)
415  
416 =item * C<newhistogram> - multiple-histogram-friendly histogram style (see C<histogram>) (2D)
417  
418 =item * C<points> - symbols at plotted points (2D/3D)
419  
420 =item * C<rgbalpha> - R/G/B color image with variable transparency (2D/3D)
421  
422 =item * C<rgbimage> - R/G/B color image (2D/3D)
423  
424 =item * C<steps> - square bin plot; delta-X, then delta-Y (see C<fsteps>, C<histeps>) (2D)
425  
426 =item * C<vectors> - Small arrows: (x,y,[z]) -> (x+dx,y+dy,[z+dz]) (2D/3D)
427  
428 =item * C<xerrorbars> - points with X error bars ("T" form) (2D)
429  
430 =item * C<xyerrorbars> - points with both X and Y error bars ("T" form) (2D)
431  
432 =item * C<yerrorbars> - points with Y error bars ("T" form) (2D)
433  
434 =item * C<xerrorlines> - line plot with X errorbars at each point. (2D)
435  
436 =item * C<xyerrorlines> - line plot with XY errorbars at each point. (2D)
437  
438 =item * C<yerrorlines> - line plot with Y error limits at each point. (2D)
439  
440 =item * C<pm3d> - three-dimensional variable-position surface plot
441  
442 =back
443  
444 =head2 Options arguments
445  
446 The plot options are parameters that affect the whole plot, like the title of
447 the plot, the axis labels, the extents, 2d/3d selection, etc. All the plot
448 options are described below in L<"Plot Options"|/"PLOT OPTIONS">. Plot options can be set
449 in the plot object, or passed to the plotting methods directly. Plot options can
450 be passed in as a leading interpolated hash, as a leading hash ref, or as a trailing
451 hash ref in the argument list to any of the main plotting routines (C<gplot>, C<plot>,
452 C<image>, etc.).
453  
454 The curve options are parameters that affect only one curve in particular. Each
455 call to C<plot()> can contain many curves, and options for a particular curve
456 I<precede> the data for that curve in the argument list. The actual type of curve
457 (the "with" option) is persistent, but all other curve options and modifiers
458 are not. An example:
459  
460 gplot( with => 'points', $x, $a,
461 {axes=> x1y2}, $x, $b,
462 with => 'lines', $x, $c );
463  
464 This plots 3 curves: $a vs. $x plotted with points on the main y-axis (this is
465 the default), $b vs. $x plotted with points on the secondary y axis, and $c
466 vs. $x plotted with lines on the main y-axis (the default). Note that the curve
467 options can be supplied as either an inline hash or a hash ref.
468  
469 All the curve options are described below in L<"Curve Options"|/"CURVE OPTIONS">.
470  
471 If you want to plot multiple curves of the same type without setting
472 any curve options explicitly, you must include an empty hash ref
473 between the tuples for subsequent lines, as in:
474  
475 gplot( $x, $a, {}, $x, $b, {}, $x, $c );
476  
477 =head2 Data arguments
478  
479 Following the curve options in the C<plot()> argument list is the
480 actual data being plotted. Each output data point is a "tuple" whose
481 size varies depending on what is being plotted. For example if we're
482 making a simple 2D x-y plot, each tuple has 2 values; if we're making
483 a 3d plot with each point having variable size and color, each tuple
484 has 5 values (x,y,z,size,color). Each tuple element must be passed
485 separately. For ordinary 2-D plots, the 0 dim of the tuple elements
486 runs across plotted point. PDL threading is active, so you can plot
487 multiple curves with similar curve options on a normal 2-D plot, just
488 by stacking data inside the passed-in PDLs. (An exception is that
489 threading is disabled if one or more of the data elements is a list
490 ref).
491  
492 =head3 PDLs vs array refs
493  
494 The usual way to pass in data is as a PDL -- one PDL per column of data
495 in the tuple. But strings, in particular, cannot easily be hammered into
496 PDLs. Therefore any column in each tuple can be an array ref containing
497 values (either numeric or string). The column is interpreted using the
498 usual polymorphous cast-behind-your-back behavior of Perl. For the sake
499 of sanity, if even one array ref is present in a tuple, then threading is
500 disabled in that tuple: everything has to have a nice 1-D shape.
501  
502  
503 =head3 Implicit domains
504  
505 When making a simple 2D plot, if exactly 1 dimension is missing,
506 PDL::Graphics::Gnuplot will use C<sequence(N)> as the domain. This is
507 why code like C<plot(pdl(1,5,3,4,4) )> works. Only one PDL is given
508 here, but the plot type ("lines" by default) requires 2 elements per
509 tuple. We are thus exactly 1 ndarray short; C<sequence(5)> is used as
510 the missing domain PDL. This is thus equivalent to
511 C<plot(sequence(5), pdl(1,5,3,4,4) )>.
512  
513 If plotting in 3d or displaying an image, an implicit domain will be
514 used if we are exactly 2 ndarrays short. In this case,
515 PDL::Graphics::Gnuplot will use a 2D grid as a domain. Example:
516  
517 my $xy = zeros(21,21)->ndcoords - pdl(10,10);
518 gplot({'3d' => 1},
519 with => 'points', inner($xy, $xy));
520 gplot( with => 'image', sin(rvals(51,51)) );
521  
522 Here the only given ndarray has dimensions (21,21). This is a 3D plot, so we are
523 exactly 2 ndarrays short. Thus, PDL::Graphics::Gnuplot generates an implicit
524 domain, corresponding to a 21-by-21 grid.
525  
526 C<PDL::Graphics::Gnuplot> requires explicit separators between tuples
527 for different plots, so it is always clear from the arguments you pass
528 in just how many columns you are supplying. For example,
529 C<plot($a,$b)> will plot C<$b> vs. C<$a>. If you actually want to
530 plot an overlay of both C<$a> and C<$b> against array index, you want
531 C<plot($a,{},$b)> instead. The C<{}> is a hash ref containing a
532 collection of all the curve options that you are changing between
533 the two curves -- in this case, zero of them.
534  
535 =head2 Images
536  
537 PDL::Graphics::Gnuplot supports four styles of image plot, via the "with" curve option.
538  
539 The "image" style accepts a single image plane and displays it using
540 the palette (pseudocolor map) that is specified in the plot options
541 for that plot. As a special case, if you supply as data a (3xWxH) or
542 (WxHx3) PDL it is treated as an RGB image and displayed with the
543 "rgbimage" style (below), provided there are at least 5 pixels in each of the
544 other two dimensions (just to be sure). For quick image display there
545 is also an "image" method:
546  
547 use PDL::Graphics::Gnuplot qw/image gplot/;
548 $im = sin(rvals(51,51)/2);
549 image( $im ); # display the image
550 gplot( with=>'image', $im ); # display the image (longer form)
551  
552 The colors are autoscaled in both cases. To set a particular color range, use
553 the 'cbrange' plot option:
554  
555 image( {cbrange=>[0,1]}, $im );
556  
557 You can plot rgb images directly with the image style, just by including a
558 3rd dimension of size 3 on your image:
559  
560 $rgbim = pdl( xvals($im), yvals($im),rvals($im)/sqrt(2));
561 image( $rgbim ); # display an RGB image
562 gplot( with=>'image', $rgbim ); # display an RGB image (longer form)
563  
564 Some additional plot styles exist to specify RGB and RGB transparent forms
565 directly. These are the "with" styles "rgbimage" and "rgbalpha". For each
566 of them you must specify the channels as separate PDLs:
567  
568 gplot( with=>'rgbimage', $rgbim->dog ); # RGB the long way
569 gplot( with=>'rgbalpha', $rgbim->dog, 255*($im>0) ); # RGBA the long way
570  
571 According to the gnuplot specification you can also give X and Y
572 values for each pixel, as in
573  
574 gplot( with=>'image', xvals($im), yvals($im), $im )
575  
576 but this appears not to work properly for anything more complicated
577 than a trivial matrix of X and Y values.
578  
579 PDL::Graphics::Gnuplot provides a "fits" plot style that interprets
580 World Coordinate System (WCS) information supplied in the header of
581 the scientific image format FITS. The image is displayed in rectified
582 scientific coordinates, rather than in pixel coordinates. You can plot
583 FITS images in scientific coordinates with
584  
585 gplot( with=>'fits', $fitsdata );
586  
587 The fits plot style accepts a curve option "resample" (which may be
588 abbreviated), that allows you to downsample and/or rectify the image
589 before it is passed to the Gnuplot back-end. This is useful either to
590 cut down on the burden of transferring large blocks of image data or
591 to rectify images with nonlinear WCS transformations in their headers.
592 (gnuplot itself has a bug that prevents direct rendering of images in
593 nonlinear coordinates).
594  
595 gplot( with=>'fits', res=>1, $fitsdata );
596 gplot( with=>'fits', res=>[200], $fitsdata );
597 gplot( with=>'fits', res=>[100,400],$fitsdata );
598  
599 to specify that the output are to be resampled onto a square 1024x1024 grid,
600 a 200x200 grid, or a 100x400 grid, respectively. The resample sizes must be
601 positive integers.
602 A true non-ref value will be treated as 1024x1024.
603  
604 =head2 Interactivity
605  
606 Several of the graphical backends of Gnuplot are interactive, allowing
607 you to pan, zoom, rotate and measure the data interactively in the plot
608 window. See the Gnuplot documentation for details about how to do
609 this. Some terminals (such as C<wxt>) are persistently interactive. Other
610 terminals (such as C<x11>) maintain their interactivity only while the
611 underlying gnuplot process is active -- i.e. until another plot is
612 created with the same PDL::Graphics::Gnuplot object, or until the perl
613 process exits (whichever comes first). Still others (the hardcopy
614 devices) aren't interactive at all.
615  
616 Some interactive devices (notably C<wxt> and C<x11>) also support
617 mouse input: you can write PDL scripts that accept and manipulate
618 graphical input from the plotted window.
619  
620 =head1 PLOT OPTIONS
621  
622 Gnuplot controls plot style with "plot options" that configure and
623 specify virtually all aspects of the plot to be produced. Plot
624 options are tracked as stored state in the PDL::Graphics::Gnuplot
625 object. You can set them by passing them in to the constructor, to an
626 C<options> method, or to the C<plot> method itself.
627  
628 Nearly all the underlying Gnuplot plot options are supported, as well
629 as some additional options that are parsed by the module itself for
630 convenience.
631  
632 There are many, many plot options. For convenience, we've grouped
633 them by general category below. Each group has a heading "POs for E<lt>fooE<gt>",
634 describing the category. You can skip below them all if you want to
635 read about curve options or other aspects of PDL::Graphics::Gnuplot.
636  
637 =head2 POs for Output: terminal, termoption, output, device, hardcopy
638  
639 You can send plots to a variety of different devices; Gnuplot calls
640 devices "terminals". With the object-oriented interface, you must set
641 the output device with the constructor C<PDL::Graphics::Gnuplot::new>
642 (or the exported constructor C<gpwin>) or the C<output> method. If you
643 use the simple non-object interface, you can set the output with the
644 C<terminal>, C<termoption>, and C<output> plot options.
645  
646 C<terminal> sets the output device type for Gnuplot, and C<output> sets the
647 actual output file or window number.
648  
649 C<device> and C<hardcopy> are for convenience. C<device> offers a
650 PGPLOT-style device specifier in "filename/device" format (the "filename"
651 gets sent to the "output" option, the "device" gets sent to the "terminal"
652 option). C<hardcopy> takes an output file name, attempts to parse out a
653 file suffix and infer a device type. C<hardcopy> also uses a common set of
654 terminal options needed to fill an entire letter page with a plot.
655  
656 For finer grained control of the plotting environment, you can send
657 "terminal options" to Gnuplot. If you set the terminal directly with
658 plot options, you can include terminal options by interpolating them
659 into a string, as in C<terminal jpeg interlace butt crop>, or you can
660 use the constructor C<new> (also exported as C<gpwin>), which parses
661 terminal options as an argument list.
662  
663 The routine C<PDL::Graphics::Gnuplot::terminfo> prints a list of all
664 available terminals or, if you pass in a terminal name, options accepted
665 by that terminal.
666  
667  
668 =head2 POs for Titles
669  
670 The options described here are
671  
672 =over
673  
674 =item title
675  
676 =item xlabel
677  
678 =item x2label
679  
680 =item ylabel
681  
682 =item y2label
683  
684 =item zlabel
685  
686 =item cblabel
687  
688 =item key
689  
690 =back
691  
692 Gnuplot supports "enhanced" text escapes on most terminals; see "text",
693 below.
694  
695 The C<title> option lets you set a title for the whole plot.
696  
697 Individual plot components are labeled with the C<label> options.
698 C<xlabel>, C<x2label>, C<ylabel>, and C<y2label> specify axis titles
699 for 2-D plots. The C<zlabel> works for 3-D plots. The C<cblabel> option
700 sets the label for the color box, in plot types that have one (e.g.
701 image display).
702  
703 (Don't be confused by C<clabel>, which doesn't set a label at all, rather
704 specifies the printf format used by contour labels in contour plots.)
705  
706 C<key> controls where the plot key (that relates line/symbol style to label)
707 is placed on the plot. It takes a scalar boolean indicating whether to turn the
708 key on (with default values) or off, or an array ref containing any of the following
709 arguments (all are optional) in the order listed:
710  
711 =over 3
712  
713 =item * ( on | off ) - turn the key on or off
714  
715 =item * ( inside | outside | lmargin | rmargin | tmargin | bmargin | at <pos> )
716  
717 These keywords set the location of the key -- "inside/outside" is
718 relative to the plot border; the margin keywords indicate location in
719 the margins of the plot; and at <pos> (where <pos> is a comma-delimited string
720 containing (x,y): C<key=E<gt>[at=E<gt>"0.5,0.5"]>) is an exact location to place the key.
721  
722 =item * ( left | right | center ) ( top | bottom | center ) - horiz./vert. alignment
723  
724 =item * ( vertical | horizontal ) - stacking direction within the key
725  
726 =item * ( Left | Right ) - justification of plot labels within the key (note case)
727  
728 =item * [no]reverse - switch order of label and sample line
729  
730 =item * [no]invert - invert the stack order of the labels
731  
732 =item * samplen <length> - set the length of the sample lines
733  
734 =item * spacing <dist> - set the spacing between adjacent labels in the list
735  
736 =item * [no]autotitle - control whether labels are generated when not specified
737  
738 =item * title "<text>" - set a title for the key
739  
740 =item * [no]enhanced - override terminal settings for enhanced text interpretation
741  
742 =item * font "<face>,<size>" - set font for the labels
743  
744 =item * textcolor <colorspec>
745  
746 =item * [no]box linestyle <ls> linetype <lt> linewidth <lw> - control box around the key
747  
748 =back
749  
750 =head2 POs for axes, grids, & borders
751  
752 The options described here are
753  
754 =over
755  
756 =item grid
757  
758 =item xzeroaxis
759  
760 =item x2zeroaxis
761  
762 =item yzeroaxis
763  
764 =item y2zeroaxis
765  
766 =item zzeroaxis
767  
768 =item border
769  
770 =back
771  
772 Normally, tick marks and their labels are applied to the border of a plot,
773 and no extra axes (e.g. the y=0 line) nor coordinate grids are shown. You can
774 specify which (if any) zero axes should be drawn, and which (if any)
775 borders should be drawn.
776  
777 The C<border> option controls whether the plot itself has a border
778 drawn around it. You can feed it a scalar boolean value to indicate
779 whether borders should be drawn around the plot -- or you can feed in a list
780 ref containing options. The options are all optional but must be supplied
781 in the order given.
782  
783 =over 3
784  
785 =item * <integer> - packed bit flags for which border lines to draw
786  
787  
788 The default if you set a true value for C<border> is to draw all border lines.
789 You can feed in a single integer value containing a bit mask, to draw only some
790 border lines. From LSB to MSB, the coded lines are bottom, left, top, right for
791 2D plots -- e.g. 5 will draw bottom and top borders but neither left nor right.
792  
793 In three dimensions, 12 bits are used to describe the twelve edges of
794 a cube surrounding the plot. In groups of three, the first four
795 control the bottom (xy) plane edges in the same order as in the 2-D
796 plots; the middle four control the vertical edges that rise from the
797 clockwise end of the bottom plane edges; and the last four control the
798 top plane edges.
799  
800 =item * ( back | front ) - draw borders first or last (controls hidden line appearance)
801  
802 =item * linewidth <lw>, linestyle <ls>, linetype <lt>
803  
804 These are Gnuplot's usual three options for line control.
805  
806 =back
807  
808 The C<grid> option indicates whether gridlines should be drawn on
809 each axis. It takes an array ref of arguments, each of which is either "no" or "m" or "",
810 followed by an axis name and "tics" --
811 e.g. C<< grid=>["noxtics","ymtics"] >> draws no X gridlines and draws
812 (horizontal) Y gridlines on Y axis major and minor tics, while
813 C<< grid=>["xtics","ytics"] >> or C<< grid=>["xtics ytics"] >> will draw both
814 vertical (X) and horizontal (Y) grid lines on major tics.
815  
816 To draw a coordinate grid with default values, set C<< grid=>1 >>. For more
817 control, feed in an array ref with zero or more of the following parameters, in order:
818  
819 The C<zeroaxis> keyword indicates whether to actually draw each axis
820 line at the corresponding zero along its indicated dimension. For
821 example, to draw the X axis (y=0), use C<< xzeroaxis=>1 >>. If you just
822 want the axis turned on with default values, you can feed in a Boolean
823 scalar; if you want to set its parameters, you can feed in an array ref
824 containing linewidth, linestyle, and linetype (with appropriate
825 parameters for each), e.g. C<< xzeroaxis=>[linewidth=>2] >>.
826  
827 =head2 POs for axis range and mode
828  
829 The options described here are
830  
831 =over
832  
833 =item xrange
834  
835 =item x2range
836  
837 =item yrange
838  
839 =item y2range
840  
841 =item zrange
842  
843 =item rrange
844  
845 =item cbrange
846  
847 =item trange
848  
849 =item urange
850  
851 =item vrange
852  
853 =item autoscale
854  
855 =item logscale
856  
857 =back
858  
859 Gnuplot accepts explicit ranges as plot options for all axes. Each option
860 accepts an array ref with (min, max). If either min or max is missing, then
861 the opposite limit is autoscaled. The x and y ranges refer to the usual
862 ordinate and abscissa of the plot; x2 and y2 refer to alternate ordinate and
863 abscissa; z if for 3-D plots; r is for polar plots; t, u, and v are for parametric
864 plots. cb is for the color box on plots that include it (see "color", below).
865  
866 C<rrange> is used for radial coordinates (which
867 are accessible using the C<mapping> plot option, below).
868  
869 C<cbrange> (for 'color box range') sets the range of values over which
870 palette colors (either gray or pseudocolor) are matched. It is valid
871 in any color-mapped plot (including images or palette-mapped lines or
872 points), even if no color box is being displayed for this plot.
873  
874 C<trange>, C<urange>, and C<vrange> set ranges for the parametric coordinates
875 if you are plotting a parametric curve.
876  
877 By default all axes are autoscaled unless you specify a range on that
878 axis, and partially (min or max) autoscaled if you specify a partial
879 range on that axis. C<autoscale> allows more explicit control of how
880 autoscaling is performed, on an axis-by-axis basis. It accepts a hash
881 ref, each element of which specifies how a single axis should be
882 autoscaled. Each keyword contains an axis name followed by one of
883 "fix", "min", "max", "fixmin", or "fixmax". You can set all the axes at
884 once by setting the keyword name to ' '. Examples:
885  
886 autoscale=>{x=>'max',y=>'fix'};
887  
888 There is an older array ref syntax which is deprecated but still accepted.
889  
890 To not autoscale an axis at all, specify a range for it. The fix style of
891 autoscaling forces the autoscaler to use the actual min/max of the data as
892 the limit for the corresponding axis -- by default the axis gets extended
893 to the next minor tic (as set by the autoticker or by a tic specification, see
894 below).
895  
896 C<logscale> allows you to turn on logarithmic scaling for any or all
897 axes, and to set the base of the logarithm. It takes an array ref, the
898 first element of which is a string mushing together the names of all
899 the axes to scale logarithmically, and the second of which is the base
900 of the logarithm: C<< logscale=>[xy=>10] >>. You can also leave off the
901 base if you want base-10 logs: C<< logscale=>['xy'] >>.
902  
903 =head2 POs for Axis tick marks
904  
905 The options described here are
906  
907 =over
908  
909 =item xtics
910  
911 =item x2tics
912  
913 =item ytics
914  
915 =item y2tics
916  
917 =item ztics
918  
919 =item cbtics
920  
921 =item mxtics
922  
923 =item mx2tics
924  
925 =item mytics
926  
927 =item my2tics
928  
929 =item mztics
930  
931 =item mcbtics
932  
933 =back
934  
935 Axis tick marks are called "tics" within Gnuplot, and they are extensively
936 controllable via the "{axis}tics" options. In particular, major and minor
937 ticks are supported, as are arbitrarily variable length ticks, non-equally
938 spaced ticks, and arbitrarily labelled ticks. Support exists for time formatted
939 ticks (see C<POs for time data values> below).
940  
941 By default, gnuplot will automatically place major and minor ticks.
942 You can turn off ticks on an axis by setting the appropriate {foo}tics
943 option to a defined, false scalar value (e.g. C<< xtics=>0 >>). If you
944 want to set major tics to happen at a regular specified intervals, you can set the
945 appropriate tics option to a nonzero scalar value (e.g. C<< xtics=>2 >> to
946 specify a tic every 2 units on the X axis). To use default values for the
947 tick positioning, specify an empty hash or array ref (e.g. C<< xtics=>{} >>), or
948 a string containing only whitespace (e.g. C<< xtics=>' ' >>).
949  
950 If you prepend an 'm' to any tics option, it affects minor tics instead of
951 major tics (major tics typically show units; minor tics typically show fractions
952 of a unit).
953  
954 Each tics option can accept a hash ref containing options to pass to
955 Gnuplot. You can also pass in a snippet of gnuplot command, as either
956 a string or an array ref -- but those techniques are deprecated and may
957 disappear in a future version of C<PDL:Graphics::Gnuplot>.
958  
959 The keywords are case-insensitive and may be abbreviated, just as with
960 other option types. They are:
961  
962 =over 2
963  
964 =item * axis - set to 1 to place tics on the axis (the default)
965  
966 =item * border - set to 1 to place tics on the border (not the default)
967  
968 =item * mirror - set to 1 to place mirrored tics on the opposite axis/border (the default, unless an alternate axis interferes -- e.g. y2)
969  
970 =item * in - set to 1 to draw tics inward from the axis/border
971  
972 =item * out - set to 1 to draw tics outward from the axis/border
973  
974 =item * scale - multiplier on tic length compared to the default
975  
976 If you pass in undef, tics get the default length. If you pass in a scalar, major tics get scaled. You can pass in an array ref to scale minor tics too.
977  
978 =item * rotate - turn label text by the given angle (in degrees) on the drawing plane
979  
980 =item * offset - offset label text from default position, (units: characters; requires array ref containing x,y)
981  
982 =item * locations - sets tic locations. Gets an array ref: [incr], [start, incr], or [start, incr, stop].
983  
984 =item * labels - sets tic locations explicitly, with text labels for each. If you specify both C<locations> and C<labels>, you get both sets of tics on the same axis.
985  
986 The labels should be a nested array ref that is a collection of duals
987 or triplets. Each dual or triplet should contain [label, position, minorflag],
988 as in C<< labels=>[["one",1,0],["three-halves",1.5,1],["two",2,0]] >>.
989  
990 =item * format - printf-style format string for tic labels. There are
991 some extensions to the gnuplot format tags -- see the gnuplot manual.
992 Gnuplot 4.8 and higher have C<%h>, which works like C<%g> but uses
993 extended text formatting if it is available.
994  
995 =item * font - set font name and size (system font name)
996  
997 =item * rangelimited - set to 1 to limit tics to the range of values actually present in the plot
998  
999 =item * textcolor - set the color of the tick labels (see L</"Color specification">)
1000  
1001 =back
1002  
1003 For example, to turn on inward mirrored X axis ticks with diagonal Arial 9 text, use:
1004  
1005 xtics => {axis=>1,mirror=>1,in=>1,rotate=>45,font=>'Arial,9'}
1006  
1007 or
1008  
1009 xtics => ['axis','mirror','in','rotate by 45','font "Arial,9"']
1010  
1011 =head2 POs for time data values
1012  
1013 The options described here are
1014  
1015 =over
1016  
1017 =item xmtics
1018  
1019 =item x2mtics
1020  
1021 =item ymtics
1022  
1023 =item y2mtics
1024  
1025 =item zmtics
1026  
1027 =item cbmtics
1028  
1029 =item xdtics
1030  
1031 =item x2dtics
1032  
1033 =item ydtics
1034  
1035 =item y2dtics
1036  
1037 =item zdtics
1038  
1039 =item cbdtics
1040  
1041 =item xdata
1042  
1043 =item x2data
1044  
1045 =item ydata
1046  
1047 =item y2data
1048  
1049 =item zdata
1050  
1051 =item cbdata
1052  
1053 =back
1054  
1055 Gnuplot contains support for plotting absolute time and date on any of its axes,
1056 with conventional formatting. There are three main methods, which are mutually exclusive
1057 (i.e. you should not attempt to use two at once on the same axis).
1058  
1059 =over 3
1060  
1061 =item B<Plotting timestamps using UNIX times>
1062  
1063 You can set any axis to plot timestamps rather than numeric values by
1064 setting the corresponding "data" plot option to "time",
1065 e.g. C<< xdata=>"time" >>. If you do so, then numeric values in the
1066 corresponding data are interpreted as UNIX time (seconds since the
1067 UNIX epoch, neglecting leap seconds). No provision is made for
1068 UTC<->TAI conversion. You can format how the times are plotted with
1069 the "format" option in the various "tics" options(above). Output
1070 specifiers should be in UNIX strftime(3) format -- for example,
1071 C<< xdata=>"time",xtics=>{format=>"%Y-%b-%dT%H:%M:%S"} >>
1072 will plot UNIX times as ISO timestamps in the ordinate.
1073  
1074 Due to limitations within gnuplot, the time resolution in this mode is
1075 limited to 1 second - if you want fractional seconds, you must use numerically
1076 formatted times (and/or create your own tick labels using the C<labels> suboption
1077 to the C<?tics> option.
1078  
1079 B<Timestamp format specifiers>
1080  
1081 Time format specifiers use the following printf-like codes:
1082  
1083 =over 3
1084  
1085 =item * B<Year A.D.>: C<%Y> is 4-digit year; C<%y> is 2-digit year (1969-2068)
1086  
1087 =item * B<Month of year>: C<%m>: 01-12; C<%b> or C<%h>: abrev. name; C<%B>: full name
1088  
1089 =item * B<Week of year>: C<%W> (week starting Monday); C<%U> (week starting Sunday)
1090  
1091 =item * B<Day of year>: C<%j> (1-366; boundary is midnight)
1092  
1093 =item * B<Day of month>: C<%d> (01-31)
1094  
1095 =item * B<Day of week>: C<%w> (0-6, Sunday=0), %a (abrev. name), %A (full name)
1096  
1097 =item * B<Hour of day>: C<%k> (0-23); C<%H> (00-23); C<%l> (1-12); C<%I> (01-12)
1098  
1099 =item * B<Am/pm>: C<%p> ("am" or "pm")
1100  
1101 =item * B<Minute of hour>: C<%M> (00-60)
1102  
1103 =item * B<Second of minute>: C<%S> (0-60)
1104  
1105 =item * B<Total seconds since start of 2000 A.D.>: C<%s>
1106  
1107 =item * B<Timestamps>: C<%T> (same as C<%H:%M:%S>); C<%R> (same as C<%H:%M>); C<%r> (same as C<%I:%M:%S %p>)
1108  
1109 =item * B<Datestamps>: C<%D> (same as C<%m/%d/%y>); C<%F> (same as C<%Y-%m-%d>)
1110  
1111 =item * B<ISO timestamps>: use C<%DT%T>.
1112  
1113 =back
1114  
1115 =item B<day-of-week plotting>
1116  
1117 If you just want to plot named days of the week, you can instead use
1118 the C<dtics> options set plotting to day of week, where 0 is Sunday and 6
1119 is Saturday; values are interpreted modulo 7. For example, C<<
1120 xmtics=>1,xrange=>[-4,9] >> will plot two weeks from Wednesday to
1121 Wednesday. As far as output format goes, this is exactly equivalent to
1122 using the C<%w> option with full formatting - but you can treat the
1123 numeric range in terms of weeks rather than seconds.
1124  
1125 =item B<month-of-year plotting>
1126  
1127 The C<mtics> options set plotting to months of the year, where 1 is January and 12 is
1128 December, so C<< xdtics=>1, xrange=>[0,4] >> will include Christmas through Easter.
1129 This is exactly equivalent to using the C<%d> option with full formatting - but you
1130 can treat the numeric range in terms of months rather than seconds.
1131  
1132 =back
1133  
1134 =head2 POs for location/size
1135  
1136 The options described here are
1137  
1138 =over
1139  
1140 =item tmargin
1141  
1142 =item bmargin
1143  
1144 =item lmargin
1145  
1146 =item rmargin
1147  
1148 =item offsets
1149  
1150 =item origin
1151  
1152 =item size
1153  
1154 =item justify
1155  
1156 =item clip
1157  
1158 =back
1159  
1160 Adjusting the size, location, and margins of the plot on the plotting
1161 surface is something of a null operation for most single plots -- but
1162 you can tweak the placement and size of the plot with these options.
1163 That is particularly useful for multiplots, where you might like to
1164 make an inset plot or to lay out a set of plots in a custom way.
1165  
1166 The margin options accept scalar values -- either a positive number of
1167 character heights or widths of margin around the plot compared to the
1168 edge of the device window, or a string that starts with "at screen "
1169 and interpolates a number containing the fraction of the plot window
1170 offset. The "at screen" technique allows exact plot placement and is
1171 an alternative to the C<origin> and C<size> options below.
1172  
1173 The C<offsets> option allows you to put an empty boundary around the
1174 data, inside the plot borders, in an autosacaled graph. The offsets
1175 only affect the x1 and y1 axes, and only in 2D plot commands.
1176 C<offsets> accepts an array ref with four values for the offsets, which
1177 are given in scientific (plotted) axis units.
1178  
1179 The C<origin> option lets you specify the origin (lower left corner)
1180 of an individual plot on the plotting window. The coordinates are
1181 screen coordinates -- i.e. fraction of the total plotting window.
1182  
1183 The size option lets you adjust the size and aspect ratio of the plot,
1184 as an absolute fraction of the plot window size. You feed in fractional
1185 ratios, as in C<< size=>[$xfrac, $yfrac] >>. You can also feed in some keywords
1186 to adjust the aspect ratio of the plot. The size option overrides any
1187 autoscaling that is done by the auto-layout in multiplot mode, so use
1188 with caution -- particularly if you are multiplotting. You can use
1189 "size" to adjust the aspect ratio of a plot, but this is deprecated
1190 in favor of the pseudo-option C<justify>.
1191  
1192 C<justify> sets the scientific aspect ratio of a 2-D plot. Unity
1193 yields a plot with a square scientific aspect ratio. Larger
1194 numbers yield taller plots.
1195  
1196 C<clip> controls the border between the plotted data and the border of the plot.
1197 There are three clip types supported: points, one, and two. You can set them
1198 independently by passing in booleans with their names: C<< clip=>[points=>1,two=>0] >>.
1199  
1200 =head2 POs for Color: colorbox, palette, clut, pseudocolor, pc, perceptual, pcp
1201  
1202 Color plots are supported via RGB and pseudocolor. Plots that use pseudcolor or
1203 grayscale can have a "color box" that shows the photometric meaning of the color.
1204  
1205 The colorbox generally appears when necessary but can be controlled manually
1206 with the C<colorbox> option. C<colorbox> accepts a scalar boolean value indicating
1207 whether or no to draw a color box, or an array ref containing additional options.
1208 The options are all, well, optional but must appear in the order given:
1209  
1210 =over 3
1211  
1212 =item ( vertical | horizontal ) - indicates direction of the gradient in the box
1213  
1214 =item ( default | user ) - indicates user origin and size
1215  
1216 If you specify C<default> the colorbox will be placed on the right-hand side of the plot; if you specify C<user>, you give the location and size in subsequent arguments:
1217  
1218 colorbox => [ 'user', 'origin'=>"$x,$y", 'size' => "$x,$y" ]
1219  
1220 =item ( front | back ) - draws the colorbox before or after the plot
1221  
1222 =item ( noborder | bdefault | border <line style> ) - specify border
1223  
1224 The line style is a numeric type as described in the gnuplot manual.
1225  
1226 =back
1227  
1228 The C<palette> option offers many arguments that are not fully
1229 documented in this version but are explained in the gnuplot manual.
1230 It offers complete control over the pseudocolor mapping function.
1231  
1232 For simple color maps, C<clut> gives access to a set of named color
1233 maps. (from "Color Look Up Table"). A few existing color maps are:
1234 "default", "gray", "sepia", "ocean", "rainbow", "heat1", "heat2", and
1235 "wheel". To see a complete list, specify an invalid table,
1236 e.g. C<< clut=>'xxx' >>. C<clut> is maintained but is superseded
1237 by C<pc> and C<pcp> (below), which give access to a better variety
1238 of color tables, and have better support for scientific images.
1239  
1240 C<pseudocolor> (synonym C<pc>) gives access to the color tables built
1241 in to the C<PDL::Transform::Color> package, if that package is
1242 available. It takes either a color table name or an array ref which
1243 is a collection of arguments that get sent to the
1244 C<PDL::Transform::Color::t_pc> transform definition method. Sending
1245 the empty string or undef will generate a list of allowable color
1246 table names. Many of the color tables are "photometric" and
1247 will render photometric data correctly without gamma correction.
1248  
1249 C<perceptual> (synonym C<pcp>) gives the same access to
1250 C<PDL::Transform::Color> as does C<pseudocolor>, but the
1251 "equal-perceptual-difference" scaling is used -- i.e. input
1252 values are gamma-corrected by the module so that uniform
1253 shifts in numeric value yield approximately uniform perceptual
1254 shifts.
1255  
1256 If you use C<pseudocolor> or C<perceptual>, and if
1257 C<PDL::Transform::Color> can be loaded, then the external module
1258 is used to define a custom Gnuplot palette by linear interpolation
1259 across 256 values. That palette is then used to translate your
1260 monochrome data to a color image. The Gnuplot output is assumed
1261 to be sRGB. This is probably OK for most output devices.
1262  
1263 =head2 POs for 3D: trid, view, pm3d, hidden3d, dgrid3d, surface, xyplane, mapping
1264  
1265 If C<trid> or its synonym C<3d> is true, Gnuplot renders a 3-D plot.
1266 This changes the default tuple size from 2 to 3. This
1267 option is used to switch between the Gnuplot "plot" and "splot"
1268 command, but it is tracked with persistent state just as any other
1269 option.
1270  
1271 The C<view> option controls the viewpoint of the 3-D plot. It takes a
1272 list of numbers: C<< view=>[$rot_x, $rot_z, $scale, $scale_z] >>. After
1273 each number, you can omit the subsequent ones. Alternatively,
1274 C<< view=>['map'] >> represents the drawing as a map (e.g. for contour
1275 plots) and C<< view=>[equal=>'xy'] >> forces equal length scales on the X
1276 and Y axes regardless of perspective, while C<< view=>[equal=>'xyz'] >>
1277 sets equal length scales on all three axes.
1278  
1279 The C<pm3d> option accepts several parameters to control the pm3d plot style,
1280 which is a palette-mapped 3d surface. They are not documented here in this
1281 version of the module but are explained in the gnuplot manual.
1282  
1283 C<hidden3d> accepts a list of parameters to control how hidden surfaces are
1284 plotted (or not) in 3D. It accepts a boolean argument indicating whether to hide
1285 "hidden" surfaces and lines; or an array ref containing parameters that control how
1286 hidden surfaces and lines are handled. For details see the gnuplot manual.
1287  
1288 C<xyplane> sets the location of that plane (which is drawn) relative
1289 to the rest of the plot in 3-space. It takes a single string: "at" or
1290 "relative", and a number. C<< xyplane=>[at=>$z] >> places the XY plane at the
1291 stated Z value (in scientific units) on the plot. C<< xyplane=>[relative=>$frac] >>
1292 places the XY plane $frac times the length of the scaled Z axis *below* the Z
1293 axis (i.e. 0 places it at the bottom of the plotted Z axis; and -1 places it
1294 at the top of the plotted Z axis).
1295  
1296 C<mapping> takes a single string: "cartesian", "spherical", or
1297 "cylindrical". It determines the interpretation of data coordinates
1298 in 3-space. (Compare to the C<polar> option in 2-D).
1299  
1300 =head2 POs for Contour plots - contour, cntrparam
1301  
1302 Contour plots are only implemented in 3D. To make a normal 2D contour
1303 plot, use 3-D mode, but set the view to "map" - which projects the 3-D
1304 plot onto its 2-D XY plane. (This is convoluted, for sure -- future
1305 versions of this module may have a cleaner way to do it).
1306  
1307 C<contour> enables contour drawing on surfaces in 3D. It takes a
1308 single string, which should be "base", "surface", or "both".
1309  
1310 C<cntrparam> manages how contours are generated and smoothed. It
1311 accepts an array ref with a collection of Gnuplot parameters that are
1312 issued one per line; refer to the Gnuplot manual for how to operate
1313 it.
1314  
1315 =head2 POs for Polar plots - polar, angles, mapping
1316  
1317 You can make 2-D polar plots by setting C<polar> to a true value. The
1318 ordinate is then plotted as angle, and the abscissa is radius on the plot.
1319 The ordinate can be in either radians or degrees, depending on the
1320 C<angles> parameter
1321  
1322 C<angles> takes either "degrees" or "radians" (default is radians).
1323  
1324 C<mapping> is used to set 3-D polar plots, either cylindrical or spherical
1325 (see the section on 3-D plotting, above).
1326  
1327 =head2 POs for Markup - label, arrow, object
1328  
1329 You specify plot markup in advance of the plot command, with plot
1330 options (or add it later with the C<replot> method). The options give
1331 you access to a collection of (separately) numbered descriptions that
1332 are accumulated into the plot object. To add a markup object to the
1333 next plot, supply the appropriate options as an array ref or as a single
1334 string. To specify all markup objects at once, supply the appropriate
1335 options for all of them as a nested list-of-lists.
1336  
1337 To modify an object, you can specify it by number, either by appending
1338 the number to the plot option name (e.g. C<arrow3>) or by supplying it
1339 as the first element of the option list for that object.
1340  
1341 To remove all objects of a given type, supply undef (e.g. C<< arrow=>undef >>).
1342  
1343 For example, to place two labels, use the plot option:
1344  
1345 label => [["Upper left",at=>"10,10"],["lower right",at=>"20,5"]];
1346  
1347 To add a label to an existing plot object, if you don't care about what
1348 index number it gets, do this:
1349  
1350 $w->options( label=>["my new label",at=>[10,20]] );
1351  
1352 If you do care what index number it gets (or want to replace an existing label),
1353 do this:
1354  
1355 $w->options( label=>[$n, "my replacement label", at=>"10,20"] );
1356  
1357 where C<$w> is a Gnuplot object and C<$n> contains the label number
1358 you care about.
1359  
1360  
1361 =head3 label - add a text label to the plot.
1362  
1363 The C<label> option allows adding small bits of text at arbitrary
1364 locations on the plot.
1365  
1366 Each label specifier array ref accepts the following suboptions, in
1367 order. All of them are optional -- if no options other than the index
1368 tag are given, then any existing label with that index is deleted.
1369  
1370 For examples, please refer to the Gnuplot 4.4 manual, p. 117.
1371  
1372 =over 3
1373  
1374 =item <tag> - optional index number (integer)
1375  
1376 =item <label text> - text to place on the plot.
1377  
1378 You may supply double-quotes inside the string, but it is not
1379 necessary in most cases (only if the string contains just an integer
1380 and you are not specifying a <tag>.
1381  
1382 =item at <position> - where to place the text (sci. coordinates)
1383  
1384 The <position> should be a string containing a gnuplot position specifier.
1385 At its simplest, the position is just two numbers separated by
1386 a comma, as in C<< label2=>["foo",at=>"5,3"] >>, to specify (X,Y) location
1387 on the plot in scientific coordinates. Each number can be preceded
1388 by a coordinate system specifier; see the Gnuplot 4.4 manual (page 20)
1389 for details.
1390  
1391 =item ( left | center | right ) - text placement rel. to position
1392  
1393 =item rotate [ by <degrees> ] - text rotation
1394  
1395 If "rotate" appears in the list alone, then the label is rotated 90 degrees
1396 CCW (bottom-to-top instead of left-to-right). The following "by" clause is
1397 optional.
1398  
1399 =item font "<name>,<size>" - font specifier
1400  
1401 The <name>,<size> must be double quoted in the string (this may be fixed
1402 in a future version), as in
1403  
1404 label3=>["foo",at=>"3,4",font=>'"Helvetica,18"']
1405  
1406 =item noenhanced - turn off gnuplot enhanced text processing (if enabled)
1407  
1408 =item ( front | back ) - rendering order (last or first)
1409  
1410 =item textcolor <colorspec>
1411  
1412 =item (point <pointstyle> | nopoint ) - control whether the exact position is marked
1413  
1414 =item offset <offset> - offfset from position (in points).
1415  
1416 =back
1417  
1418 =head3 arrow - place an arrow or callout line on the plot
1419  
1420 Works similarly to the C<label> option, but with an arrow instead of text.
1421  
1422 The arguments, all of which are optional but which must be given in the order listed,
1423 are:
1424  
1425 =over 3
1426  
1427 =item from <position> - start of arrow line
1428  
1429 The <position> should be a string containing a gnuplot position specifier.
1430 At its simplest, the position is just two numbers separated by
1431 a comma, as in C<< arrow2=>["foo",at=>"5,3"] >>, to specify (X,Y) location
1432 on the plot in scientific coordinates. Each number can be preceded
1433 by a coordinate system specifier; see the Gnuplot 4.4 manual (page 20)
1434 for details.
1435  
1436 =item ( to | rto ) <position> - end of arrow line
1437  
1438 These work like C<from>. For absolute placement, use "to". For placement
1439 relative to the C<from> position, use "rto".
1440  
1441 =item (arrowstyle | as) <arrow_style>
1442  
1443 This specifies that the arrow be drawn in a particular predeclared numerical
1444 style. If you give this parameter, you should omit all the following ones.
1445  
1446 =item ( nohead | head | backhead | heads ) - specify arrowhead placement
1447  
1448 =item size <length>,<angle>,<backangle> - specify arrowhead geometry
1449  
1450 =item ( filled | empty | nofilled ) - specify arrowhead fill
1451  
1452 =item ( front | back ) - specify drawing order ( last | first )
1453  
1454 =item linestyle <line_style> - specify a numeric linestyle
1455  
1456 =item linetype <line_type> - specify numeric line type
1457  
1458 =item linewidth <line_width> - multiplier on the width of the line
1459  
1460 =back
1461  
1462 =head3 object - place a shape on the graph
1463  
1464 C<object>s are rectangles, ellipses, circles, or polygons that can be placed
1465 arbitrarily on the plotting plane.
1466  
1467 The arguments, all of which are optional but which must be given in the order listed, are:
1468  
1469 =over 3
1470  
1471 =item <object-type> <object-properties> - type name of the shape and its type-specific properties
1472  
1473 The <object-type> is one of four words: "rectangle", "ellipse", "circle", or "polygon".
1474  
1475 You can specify a rectangle with C<< from=>$pos1, [r]to=>$pos2 >>, with C<< center=>$pos1, size=>"$w,$h" >>,
1476 or with C<< at=>$pos1,size=>"$w,$h" >>.
1477  
1478 You can specify an ellipse with C<< at=>$pos, size=>"$w,$h" >> or C<< center=>$pos, size=>"$w,$h" >>, followed
1479 by C<< angle=>$a >>.
1480  
1481 You can specify a circle with C<< at=>$pos, >> or C<< center=>$pos, >>, followed
1482 by C<< size=>$radius >> and (optionally) C<< arc=>"[$begin:$end]" >>.
1483  
1484 You can specify a polygon with C<< from=>$pos1,to=>$pos2,to=>$pos3,...to=>$posn >> or with
1485 C<< from=>$pos1,rto=>$diff1,rto=>$diff2,...rto=>$diffn >>.
1486  
1487 =item ( front | back | behind ) - draw the object last | first | really-first.
1488  
1489 =item fc <colorspec> - specify fill color
1490  
1491 =item fs <fillstyle> - specify fill style
1492  
1493 =item lw <width> - multiplier on line width
1494  
1495 =back
1496  
1497 =head2 POs for appearance tweaks - bars, boxwidth, isosamples, pointsize, style
1498  
1499 B<C<bars>> sets the width and behavior of the tick marks at the ends of error bars.
1500 It takes a list containing at most two elements, both of which are optional:
1501  
1502 =over 3
1503  
1504 =item * A width specifier, which should be a numeric size multiplier times the usual
1505 width (which is about one character width in the default font size), or the word
1506 C<fullwidth> to make the ticks the same width as their associated boxes in boxplots
1507 and histograms.
1508  
1509 =item * the word "front" or "back" to indicate drawing order in plots that might contain
1510 filled rectangles (e.g. boxes, candlesticks, or histograms).
1511  
1512 =back
1513  
1514 If you pass in the undefined value you get no ticks on errorbars; if you pass in the
1515 empty array ref you get default ticks.
1516  
1517 B<C<boxwidth>> sets the width of drawn boxes in boxplots, candlesticks, and histograms. It
1518 takes a list containing at most two elements:
1519  
1520 =over 3
1521  
1522 =item * a numeric width
1523  
1524 =item * one of the words C<absolute> or C<relative>.
1525  
1526 =back
1527  
1528 Unless you set C<relative>, the numeric width sets the width of boxes
1529 in X-axis scientific units (on log scales, this is measured at x=1 and
1530 the same width is used throughout the plot plane). If C<relative> is
1531 included, the numeric width is taken to be a multiplier on the default
1532 width.
1533  
1534 B<C<isosamples>> sets isoline density for plotting functions as
1535 surfaces. You supply one or two numbers. The first is the number of
1536 iso-u lines and the second is the number of iso-v lines. If you only
1537 specify one, then the two are taken to be the same. From the gnuplot
1538 manual: "An isoline is a curve parameterized by one of the surface
1539 parameters while the other surface parameter is fixed. Isolines
1540 provide a simple means to display a surface. By fixing the u
1541 parameter of surface s(u,v), the iso-u lines of the form c(v) =
1542 s(u0,v) are produced, and by fixing the v parameter, the iso-v lines
1543 of the form c(u)=s(u,v0) are produced".
1544  
1545 B<C<pointsize>> accepts a single number and scales the size of points used in plots.
1546  
1547 B<C<style>> provides a great deal of customization for individual plot styles.
1548 It is not (yet) fully parsed by PDL::Graphics::Gnuplot; please refer to the Gnuplot
1549 manual for details (it is pp. 145ff in the Gnuplot 4.6.1 manual). C<style> accepts
1550 a hash ref whose keys are plot styles (such as you would feed to the C<with> curve option),
1551 and whose values are array refs containing keywords and other parameters to modify how each
1552 plot style should be displayed.
1553  
1554 =head2 POs for locale/internationalization - locale, decimalsign
1555  
1556 C<locale> is used to control date stamp creation. See the gnuplot manual.
1557  
1558 C<decimalsign> accepts a character to use in lieu of a "." for the decimalsign.
1559 (e.g. in European countries use C<< decimalsign=>',' >>).
1560  
1561 C<globalwith> is used as a default plot style if no valid 'with' curve option is present for
1562 a given curve.
1563  
1564 If set to a nonzero value, C<timestamp> causes a time stamp to be
1565 placed on the side of the plot, e.g. for keeping track of drafts.
1566  
1567 C<zero> sets the approximation threshold for zero values within gnuplot. Its default is 1e-8.
1568  
1569 C<fontpath> sets a font search path for gnuplot. It accepts a collection of file names as an array ref.
1570  
1571 =head2 POs for advanced Gnuplot tweaks: topcmds, extracmds, bottomcmds, binary, dump, tee
1572  
1573 Plotting is carried out by sending a collection of commands to an underlying
1574 gnuplot process. In general, the plot options cause "set" commands to be
1575 sent, configuring gnuplot to make the plot; these are followed by a "plot" or
1576 "splot" command and by any cleanup that is necessary to keep gnuplot in a known state.
1577  
1578 Provisions exist for sending commands directly to Gnuplot as part of a plot. You
1579 can send commands at the top of the configuration but just under the initial
1580 "set terminal" and "set output" commands (with the C<topcmds> option), at the bottom
1581 of the configuration and just before the "plot" command (with the C<extracmds> option),
1582 or after the plot command (with the C<bottomcmds> option). Each of these plot
1583 options takes an array ref, each element of which should be one command line for
1584 gnuplot.
1585  
1586 Most plotting is done with binary data transfer to Gnuplot; however, due to
1587 some bugs in Gnuplot binary handling, certain types of plot data are sent in ASCII.
1588 In particular, time series and label data require transmission in ASCII (as of Gnuplot 4.4).
1589 You can force ASCII transmission of all but image data by explicitly setting the
1590 C<< binary=>0 >> option.
1591  
1592 C<dump> is used for debugging. If true, it writes out the gnuplot commands to
1593 STDOUT I<instead> of writing to a gnuplot process. Useful to see what commands
1594 would be sent to gnuplot. This is a dry run. Note that if the 'binary' option is
1595 given (see below), then this dump will contain binary data. If this binary data
1596 should be suppressed from the dump, set C<< dump => 'nobinary' >>.
1597  
1598 C<tee> is used for debugging. If true, writes out the gnuplot commands to STDERR
1599 I<in addition> to writing to a gnuplot process. This is I<not> a dry run: data
1600 is sent to gnuplot I<and> to the log. Useful for debugging I/O issues. Note that
1601 if the 'binary' option is given (see below), then this log will contain binary
1602 data. If this binary data should be suppressed from the log, set C<< tee =>
1603 'nobinary' >>.
1604  
1605 =head1 CURVE OPTIONS
1606  
1607 The curve options describe details of specific curves within a plot.
1608 They are in a hash, whose keys are as follows:
1609  
1610 =over 2
1611  
1612 =item legend
1613  
1614 Specifies the legend label for this curve
1615  
1616 =item axes
1617  
1618 Lets you specify which X and/or Y axes to plot on. Gnuplot supports
1619 a main and alternate X and Y axis. You specify them as a packed string
1620 with the x and y axes indicated: for example, C<x1y1> to plot on the main
1621 axes, or C<x1y2> to plot using an alternate Y axis (normally gridded on
1622 the right side of the plot).
1623  
1624 =item with
1625  
1626 Specifies the plot style for this curve. The value is passed to gnuplot
1627 using its 'with' keyword, so valid values are whatever gnuplot
1628 supports. See above ("Plot styles supported") for a list of supported
1629 curve styles.
1630  
1631 The following curve options in this list modify the plot style further.
1632 Not all of them are applicable to all plot styles -- for example, it makes
1633 no sense to specify a fill style for C<< with=>lines >>.
1634  
1635 For historical reasons, you can supply the with modifier curve options
1636 as a single string in the "with" curve option. That usage is deprecated
1637 and will disappear in a future version of PDL::Graphics::Gnuplot.
1638  
1639 =item linetype (abbrev 'lt')
1640  
1641 This is a numeric selector from the default collection of line styles.
1642 It includes automagic selection of dash style, color, and width from the
1643 default set of linetypes for your current output terminal.
1644  
1645 =item dashtype (abbrev 'dt')
1646  
1647 This is can be either a numeric type selector (0 for no dashes) or
1648 an ARRAY ref containing a list of up to 5 pairs of (dash length,
1649 space length). The C<dashtype> curve option is only supported for
1650 Gnuplot versions 5.0 and above.
1651  
1652 If you don't specify a C<dashtype> curve option, the default behavior
1653 matches the behavior of earlier gnuplots: many terminals support a
1654 "dashed" terminal/output option, and if you have set that option (with
1655 the constructor or with the C<output> method) then lines are uniquely
1656 dashed by default. To make a single curve solid, specify C<< dt=>0 >> as
1657 a curve option for it; or to make all curves solid, use the constructor
1658 or the C<output> method to set the terminal option C<< dashed=>0 >>.
1659  
1660 If your gnuplot is older than v5.0, the dashtype curve option is
1661 ignored (and causes a warning to be emitted).
1662  
1663 =item linestyle (abbrev 'ls')
1664  
1665 This works exactly like C<< linetype >> above, except that you can modify
1666 individual line styles by setting the C<< style line <num> >> plot option.
1667 That is handy for a custom style you might use across several curves either
1668 a single plot or several plots.
1669  
1670 =item linewidth (abbrev 'lw')
1671  
1672 This is a numeric multiplier on the usual default line width in your current
1673 terminal.
1674  
1675 =item linecolor (abbrev 'lc')
1676  
1677 This is a color specifier for the color of the line. See L</"Color specification">.
1678 You can feed in a standard color name (they're listed in the
1679 package-global variable C<@PDL::Graphics::Gnuplot::colornames>), a
1680 small integer to index the standard linetype colors, the word
1681 "variable" to indicate that the line color is a standard linetype
1682 color to be drawn from an additional column of data, a string of the
1683 form #RRGGBB, where the # is literal and the RR, GG, and BB are
1684 hexadecimal bytes, the words "rgbcolor variable" to specify an
1685 additional column of data containing 24-bit packed integers with RGB
1686 color values, C<< [palette=>'frac',<val>] >> to specify a single
1687 fractional position (scaled 0-1) in the current palette, or C<<
1688 [palette=>'cb',<val>] >> to specify a single value in the scaled
1689 cbrange.
1690  
1691 There is no C<< linecolor=>[palette=>variable] >> due to Gnuplot's
1692 non-orthogonal syntax. To draw line color from the palette, via an
1693 additional data column, see the separate "palette" curve option
1694 (below).
1695  
1696 =item textcolor (abbrev 'tc')
1697  
1698 For plot styles like C<labels> that specify text, this sets the color
1699 of the text. It has the same format as C<linecolor> (above).
1700  
1701 =item pointtype (abbrev 'pt')
1702  
1703 Selects a point glyph shape from the built-in list for your terminal,
1704 for plots that render points as small glyphs (like C<points> and
1705 C<linespoints>).
1706  
1707 =item pointsize (abbrev 'ps')
1708  
1709 Selects a fractional size for point glyphs, relative to the default size
1710 on your terminal, for plots that render points as small glyphs.
1711  
1712 =item fillcolor (abbrev 'fc')
1713  
1714 Fills an area plot like C<filledcurves> with a color.
1715 It has the same format as C<linecolor>. This will fill the whole plot with
1716 the same color. To fill above a threshold or below a threshold, you need to
1717 use C<above> and C<below> options.
1718  
1719 An example to plot data in a single function call is below:
1720  
1721 plot({ with => 'filledcurves', fillcolor => 'green', above => 'y=0' },
1722 x, y,
1723 { with => 'filledcurves', fillcolor => 'red', below => 'y=0' },
1724 x, y);
1725  
1726  
1727 =item below
1728  
1729 This is used for C<filledcurves> to set a C<fillcolor> below a threshold.
1730 You can set the value like "y=0" if you want to color below the Y-axis value of 0.
1731  
1732 =item above
1733  
1734 This is used for C<filledcurves> to set a C<fillcolor> above a threshold.
1735 You can set the value like "y=0" if you want to color above the Y-axis value of 0.
1736  
1737 =item fillstyle (abbrev 'fs')
1738  
1739 Specify the way that filled regions should be colored, in plots that
1740 have fillable areas (like C<boxes>). Unlike C<linestyle> above,
1741 C<fillstyle> accepts a full specification rather than an index into a
1742 set of predefined styles. You can feed in: C<< 'empty' >> for no fill;
1743 C<< 'transparent solid <density>' >> for a solid fill with optional
1744 <density> from 0.0 to 1.0 (default 1.0); C<< 'transparent pattern <n>'
1745 >> for a pattern fill--plotting multiple datasets causes the pattern
1746 to cycle through all available pattern types, starting from pattern
1747 <n> (be aware that the default <n>=0 may be equivalent to 'empty');
1748 The 'transparent' portions of the strings are optional, and are only
1749 effective on terminals that support transparency. Be aware that the
1750 quality of the visual output may depend on terminal type and rendering
1751 software.
1752  
1753 Any of those fill style specification strings can have a border
1754 specification string appended to it. To specify a border, append
1755 C<'border'>, and then optionally either C<< 'lt=><type>' >> or C<<
1756 'lc=><colorspec>' >> to the string. To specify no border, append
1757 C<'noborder'>.
1758  
1759 =item nohidden3d
1760  
1761 If you are making a 3D plot and have used the plot option C<hidden3d> to get
1762 hidden line removal, you can override that for a particular curve by setting
1763 the C<nohidden3d> option to a true value. Only the single curve with C<nohidden3d>
1764 set will have its hidden points rendered.
1765  
1766 =item nocontours
1767  
1768 If you are making a contour 3D plot, you can inhibit rendering of
1769 contours for a particular curve by setting C<nocontours> to a true
1770 value.
1771  
1772 =item nosurface
1773  
1774 If you are making a surface 3D plot, you can inhibit rendering of the
1775 surface associated with a particular curve, by setting C<nosurface> to
1776 a true value.
1777  
1778 =item palette
1779  
1780 Setting C<< palette => 1 >> causes line color to be drawn from an additional
1781 column in the data tuple. This column is always the very last column in the
1782 tuple, in case of conflict (e.g. if you set both C<< pointsize=>variable >> and
1783 C<< palette=>1 >>, then the palette column is the last column and the pointsize
1784 column is second-to-last).
1785  
1786 =item tuplesize
1787  
1788 Specifies how many values represent each data point. Normally you
1789 don't need to set this as individual C<with> styles implicitly set a
1790 tuple size (which is automatically extended if you specify additional
1791 modifiers such as C<palette> that require more data); this option
1792 lets you override PDL::Graphics::Gnuplot's parsing in case of irregularity.
1793  
1794 =item cdims
1795  
1796 Specifies the dimensions of of each column in this curve's tuple. It must
1797 be 0, 1, or 2. Normally you don't need to set this for most plots; the
1798 main use is to specify that a 2-D data PDL is to be interpreted as a collection
1799 of 1-D columns rather than a single 2-D grid (which would be the default
1800 in a 3-D plot). For example:
1801  
1802 $w=gpwin();
1803 $r2 = rvals(21,21)**2;
1804 $w->plot3d( wi=>'lines', xvals($r2), yvals($r2), $r2 );
1805  
1806 will produce a grid of values on a paraboloid. To instead plot a collection
1807 of lines using the threaded syntax, try
1808  
1809 $w->plot3d( wi=>'lines', cd=>1, xvals($r2), yvals($r2), $r2 );
1810  
1811 which will plot 21 separate curves in a threaded manner.
1812  
1813 =item resample
1814  
1815 For C<< with=>'fits' >>. See L</Images>.
1816  
1817 =back
1818  
1819 =head1 RECIPES
1820  
1821 Most of these come directly from Gnuplot commands. See the Gnuplot docs for
1822 details.
1823  
1824 =head2 2D plotting
1825  
1826 If we're plotting an ndarray $y of y-values to be plotted sequentially (implicit
1827 domain), all you need is
1828  
1829 gplot($y);
1830  
1831 If we also have a corresponding $x domain, we can plot $y vs. $x with
1832  
1833 gplot($x, $y);
1834  
1835 =head3 Simple style control
1836  
1837 To change line thickness:
1838  
1839 gplot(with => 'lines',linewidth=>4, $x, $y);
1840 gplot(with => 'lines', lw=>4, $x, $y);
1841  
1842 To change point size and point type:
1843  
1844 gplot(with => 'points',pointtype=>8, $x, $y);
1845 gplot(with => 'points',pt=>8, $x, $y);
1846  
1847 =head3 Errorbars
1848  
1849 To plot errorbars that show $y +- 1, plotted with an implicit domain
1850  
1851 gplot(with => 'yerrorbars', $y, $y->ones);
1852  
1853 Same with an explicit $x domain:
1854  
1855 gplot(with => 'yerrorbars', $x, $y, $y->ones);
1856  
1857 Symmetric errorbars on both x and y. $x +- 1, $y +- 2:
1858  
1859 gplot(with => 'xyerrorbars', $x, $y, $x->ones, 2*$y->ones);
1860  
1861 To plot asymmetric errorbars that show the range $y-1 to $y+2 (note that here
1862 you must specify the actual errorbar-end positions, NOT just their deviations
1863 from the center; this is how Gnuplot does it)
1864  
1865 gplot(with => 'yerrorbars', $y, $y - $y->ones, $y + 2*$y->ones);
1866  
1867 =head3 More multi-value styles
1868  
1869 Plotting with variable-size circles (size given in plot units, requires Gnuplot >= 4.4)
1870  
1871 gplot(with => 'circles', $x, $y, $radii);
1872  
1873 Plotting with a variably-sized arbitrary point type (size given in multiples of
1874 the "default" point size)
1875  
1876 gplot(with => 'points', pointtype=>7, pointsize=>'variable',
1877 $x, $y, $sizes);
1878  
1879 Color-coded points
1880  
1881 gplot(with => 'points', palette=>1,
1882 $x, $y, $colors);
1883  
1884 Variable-size AND color-coded circles. A Gnuplot (4.4.0) bug make it necessary to
1885 specify the color range here
1886  
1887 gplot(cbmin => $mincolor, cbmax => $maxcolor,
1888 with => 'circles', palette=>1,
1889 $x, $y, $radii, $colors);
1890  
1891 =head2 3D plotting
1892  
1893 General style control works identically for 3D plots as in 2D plots.
1894  
1895 To plot a set of 3d points, with a square aspect ratio (squareness requires
1896 Gnuplot >= 4.4):
1897  
1898 splot(square => 1, $x, $y, $z);
1899  
1900 If $xy is a 2D ndarray, we can plot it as a height map on an implicit domain
1901  
1902 splot($xy);
1903  
1904 Complicated 3D plot with fancy styling:
1905  
1906 my $pi = 3.14159;
1907 my $theta = zeros(200)->xlinvals(0, 6*$pi);
1908 my $z = zeros(200)->xlinvals(0, 5);
1909  
1910 splot(title => 'double helix',
1911  
1912 { with => 'linespoints',
1913 pointsize=>'variable',
1914 pointtype=>7,
1915 palette=>1,
1916 legend => 'spiral 1' },
1917 { legend => 'spiral 2' },
1918  
1919 # 2 sets of x, 2 sets of y, single z
1920 PDL::cat( cos($theta), -cos($theta)),
1921 PDL::cat( sin($theta), -sin($theta)),
1922 $z,
1923  
1924 # pointsize, color
1925 0.5 + abs(cos($theta)), sin(2*$theta) );
1926  
1927 3D plots can be plotted as a heat map.
1928  
1929 splot( extracmds => 'set view 0,0',
1930 with => 'image',
1931 $xy );
1932  
1933 =head2 Hardcopies
1934  
1935 To send any plot to a file, instead of to the screen, one can simply do
1936  
1937 gplot(hardcopy => 'output.pdf',
1938 $x, $y);
1939  
1940 The C<hardcopy> option is a shorthand for the C<terminal> and
1941 C<output> options. The output device is chosen from the file name
1942 suffix.
1943  
1944 If you want more (any) control over the output options (e.g. page
1945 size, font, etc.) then you can specify the output device using the
1946 C<output> method or the constructor itself -- or the corresponding plot
1947 options in the non-object mode. For example, to generate a PDF of a
1948 particular size with a particular font size for the text, one can do
1949  
1950 gplot(terminal => 'pdfcairo solid color font ",10" size 11in,8.5in',
1951 output => 'output.pdf',
1952 $x, $y);
1953  
1954 This command is equivalent to the C<hardcopy> shorthand used previously, but the
1955 fonts and sizes can be changed.
1956  
1957 Using the object oriented mode, you could instead say:
1958  
1959 $w = gpwin();
1960 $w->plot( $x, $y );
1961 $w->output( pdfcairo, solid=>1, color=>1,font=>',10',size=>[11,8.5,'in'] );
1962 $w->replot();
1963 $w->close();
1964  
1965 Many hardcopy output terminals (such as C<pdf> and C<svg>) will not
1966 dump their plot to the file unless the file is explicitly closed with a
1967 change of output device or a call to C<reset>, C<restart>, or C<close>.
1968 This is because those devices support multipage output and also require
1969 an end-of-file marker to close the file.
1970  
1971 =head1 Plotting examples
1972  
1973 =head2 A simple example
1974  
1975 my $win = gpwin('x11');
1976 $win->plot( sin(xvals(45)) * 3.14159/10 );
1977  
1978 Here we just plot a simple function. The default plot style is a
1979 line. Line plots take a 2-tuple (X and Y values). Since we have
1980 supplied only one element, C<plot()> understands it to be the Y value
1981 (abscissa) of the plot, and supplies value indices as X values -- so
1982 we get a plot of just over 2 cycles of the sine wave over an X range
1983 across X values from 0 to 44.
1984  
1985 =head2 A not-so-simple example
1986  
1987 $win = gpwin('x11');
1988 $pi = 3.14159;
1989 $win->plot( {with => line}, xvals(10)**2, xvals(10),
1990 {with => circles}, 2 * xvals(50), 2 * sin(xvals(50) * $pi / 10), xvals(50)/20
1991 );
1992  
1993 This plots sqrt(x) in an interesting way, and overplots some circles of varying size.
1994 The line plot accepts a 2-tuple, and we supply both X and Y. The circles plot accepts
1995 a 3-tuple: X, Y, and R.
1996  
1997 =head2 A complicated example:
1998  
1999 $pi = 3.14159;
2000 $theta = xvals(201) * 6 * $pi / 200;
2001 $z = xvals(201) * 5 / 200;
2002  
2003 gplot( {trid => 1, title => 'double helix',cbr=>[0,1]},
2004 {with => 'linespoints',
2005 pointsize=>'variable',
2006 pointtype=>2,
2007 palette=>1,
2008 legend => ['spiral 1','spiral 2'],
2009 cdim=>1},
2010 pdl( cos($theta), -cos($theta) ), # x
2011 pdl( sin($theta), -sin($theta) ), # y
2012 $z, # z
2013 (0.5 + abs(cos($theta))), # pointsize
2014 sin($theta/3), # color
2015 { with=>'points',
2016 pointsize=>'variable',
2017 pointtype=>5,
2018 palette=>0
2019 },
2020 zeroes(6), # x
2021 zeroes(6), # y
2022 xvals(6), # z
2023 xvals(6)+1 # point size
2024 );
2025  
2026 This is a 3d plot with variable size and color. There are 5 values in
2027 the tuple. The first 2 ndarrays have dimensions (N,2); all the other
2028 ndarrays have a single dimension. The "cdim=>1" specifies that each column
2029 of data should be one-dimensional. Thus the PDL threading generates 2
2030 distinct curves, with varying values for x,y and identical values for
2031 everything else. To label the curves differently, 2 different sets of
2032 curve options are given. Omitting the "cdim" curve option would yield
2033 a 201x2 grid with the "linespoints" plotstyle, rather than two separate
2034 curves.
2035  
2036 In addition to the threaded pair of linespoints curves, there are six
2037 variable size points plotted as filled squares, as a secondary curve.
2038  
2039 Plot options are passed in in two places: as a leading hash ref, and as
2040 a trailing hash ref. Any other hash elements or hash refs must be curve
2041 options.
2042  
2043 Curves are delimited by non-data arguments. After the initial hash
2044 ref, curve options for the first curve (the threaded pair of spirals)
2045 are passed in as a second hash ref. The curve's data arguments are
2046 ended by the first non-data argument (the hash ref with the curve
2047 options for the second curve).
2048  
2049  
2050 =head1 FUNCTIONS
2051  
2052 =cut
2053  
2054 package PDL::Graphics::Gnuplot;
2055  
2056 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2057 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
2058 3 ▶use PDL;
Subroutine BEGIN: called CC=1 SCAR=0.0
2059 3 ▶use List::Util qw(first);
Subroutine BEGIN: called CC=1 SCAR=0.0
2060 3 ▶use Storable qw(dclone);
Subroutine BEGIN: called CC=1 SCAR=0.0
2061 3 ▶use IPC::Open3;
Subroutine BEGIN: called CC=1 SCAR=0.0
2062 3 ▶use IPC::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
2063 3 ▶use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
2064 3 ▶use Symbol qw(gensym);
Subroutine BEGIN: called CC=1 SCAR=0.0
2065 3 ▶use File::Temp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
2066 3 ▶use Time::HiRes qw(gettimeofday tv_interval);
Subroutine BEGIN: called CC=1 SCAR=0.0
2067 3 ▶use Safe::Isa;
Subroutine BEGIN: called CC=1 SCAR=0.0
2068 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
2069  
2070 3 ▶use Alien::Gnuplot;
Subroutine BEGIN: called CC=1 SCAR=0.0
2071 3 ▶if($Alien::Gnuplot::VERSION < 1.031) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Alien::Gnuplot::VERSION < "1.031") 0 3 3
2072 # Have to check explicitly since we use the version hack to check the *gnuplot* version.
2073 0 die "PDL::Graphics::Gnuplot requires Alien::Gnuplot version 1.031 or higher\n (v$Alien::Gnuplot::VERSION found). You can pull the latest from CPAN.\n";
2074 }
2075  
2076 3 our $gnuplot_dep_v = 4.006; # Versions below this are deprecated.
2077 3 our $gnuplot_req_v = 4.004; # Versions below this are not supported.
2078 # Ensure gnuplot exists and is recent, and get ancillary info about it.
2079 3 Alien::Gnuplot->VERSION('4.4');
2080  
2081 # Compile time config flags...
2082 3 our $check_syntax = 0;
2083 3 ▶our $MS_io_braindamage = ($^O =~ m/MSWin32/i || $ENV{CYGWIN}); # Do some different things on Losedows
Condition33%1/3
$^O =~ /MSWin32/i || $ENV{'CYGWIN'}
l!l&&r!l&&!r
003
MC/DC0%0/2
$^O =~ /MSWin32/i || $ENV{'CYGWIN'}
$^O =~ /MSWin32/i $ENV{'CYGWIN'}
Truth table33%1/3
A || B
A= $^O =~ /MSWin32/iB= $ENV{'CYGWIN'}
ABresult
1X1
011
000
2084 3 our $echo_eating = 0; # Older versions of gnuplot on windows echo commands
2085 3 our $debug_echo = 0; # If set, mock up Losedows half-duplex pipes
2086  
2087  
2088 3 our $VERSION = '2.033';
2089 3 $VERSION = eval $VERSION;
2090  
2091 3 our $gp_version = undef; # eventually gets the extracted gnuplot(1) version number.
2092 3 our $gp_numversion = undef; # which is here converted to a float
2093  
2094 3 my $did_warn_non_numeric_patchlevel; # whether we already warned about this
2095  
2096 3 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
2097 3 our @EXPORT_OK = qw(
2098 plot plot3d line lines points image terminfo reset restart replot
2099 multiplot_generate plot_generate multiplot_next_generate end_multi_generate
2100 );
2101 3 our @EXPORT = qw(gpwin gplot greplot greset grestart);
2102  
2103 0 ▶$SIG{TERM} = $SIG{INT} = $SIG{QUIT} = $SIG{HUP} = sub { die; };
Subroutine __ANON__: not called CC=1 SCAR=1.2
2104  
2105 # when testing plots with binary i/o, this is the unit of test data
2106 3 my $testdataunit_binary = "........"; # 8 bytes - length of an IEEE double
2107  
2108 # globalPlot holds state when methods are called with non-object
2109 # syntax. (If you want more than one plot at once, you have to use
2110 # the object syntax).
2111 3 our $globalPlot;
2112  
2113 # get a list of all the -- options that this gnuplot supports
2114 3 our %gnuplotFeatures = _getGnuplotFeatures();
2115  
2116 # Declare the parse tables for plot and curve options. (They're populated below).
2117 3 our($pOpt, $cOpt);
2118  
2119 # This is a magic string that's used to separate curve blocks when assembling the
2120 # plot command.
2121 3 our $cmdFence = "cmdFENCEcmd";
2122  
2123 ##############################
2124 #
2125 # Constructor(s)
2126 #
2127 # gpwin & new - constructor
2128 # DESTROY - destructor kills gnuplot task
2129 #
2130 # _startGnuplot - helper for new
2131  
2132 =pod
2133  
2134 =head2 gpwin
2135  
2136 =for usage
2137  
2138 use PDL::Graphics::Gnuplot;
2139 $w = gpwin( @options );
2140 $w->plot( @plot_args );
2141  
2142  
2143 =for ref
2144  
2145 gpwin is the PDL::Graphics::Gnuplot exported constructor. It is
2146 exported by default and is a synonym for "new
2147 PDL::Graphics::Gnuplot(...)". If given no arguments, it creates a
2148 plot object with the default terminal settings for your gnuplot. You
2149 can also give it the name of a Gnuplot terminal type (e.g. 'x11') and
2150 some terminal and output options (see "output").
2151  
2152  
2153 =cut
2154  
2155 20 ▶sub gpwin { return new("PDL::Graphics::Gnuplot",@_); }
Subroutine gpwin: called CC=1 SCAR=0.0
Pod documented
2156  
2157 =pod
2158  
2159 =head2 new
2160  
2161 =for usage
2162  
2163 $w = new PDL::Graphics::Gnuplot;
2164 $w->plot( @plot_args );
2165 #
2166 # Specify plot options alone
2167 $w = new PDL::Graphics::Gnuplot( {%plot_options} );
2168 #
2169 # Specify device and device options (and optional default plot options)
2170 $w = new PDL::Graphics::Gnuplot( device, %device_options, {%plot_options} );
2171 $w->plot( @plot_args );
2172  
2173 =for ref
2174  
2175 Creates a PDL::Graphics::Gnuplot persistent plot object, and connects it to gnuplot.
2176  
2177 For convenience, you can specify the output device and its options
2178 right here in the constructor. Because different gnuplot devices
2179 accept different options, you must specify a device if you want to
2180 specify any device configuration options (such as window size, output
2181 file, text mode, or default font).
2182  
2183 If you don't specify a device type, then the Gnuplot default device
2184 for your system gets used. You can set that with an environment
2185 variable (check the Gnuplot documentation).
2186  
2187 Gnuplot uses the word "terminal" for output devices; you can see a
2188 list of terminals supported by PDL::Graphics::Gnuplot by invoking
2189 C<PDL::Graphics::Gnuplot::terminfo()> (for example in the perldl shell).
2190  
2191 For convenience, you can provide default plot options here. If the last
2192 argument to C<new()> is a trailing hash ref, it is treated as plot options.
2193  
2194 After you have created an object, you can change its terminal/output
2195 device with the C<output> method, which is useful for (e.g.) throwing
2196 up an interactive plot and then sending it to a hardcopy device. See
2197 C<output> for a description of terminal options and how to format
2198 them.
2199  
2200 Normally, the object connects to the command "gnuplot" in your path,
2201 using the C<Alien::Gnuplot> module. If you need to specify a binary
2202 other than this default, check the C<Alien::Gnuplot> documentation.
2203  
2204 =for example
2205  
2206 my $plot = PDL::Graphics::Gnuplot->new({title => 'Object-oriented plot'});
2207 $plot->plot( legend => 'curve', sequence(5) );
2208  
2209  
2210 =cut
2211  
2212 3 our $termTab;
2213  
2214 sub new
2215 22 ▶{
Subroutine new: called CC=4 SCAR=13.9
Pod documented
2216 22 my $classname;
2217  
2218 # DWIM if we call this like gpwin(). That usage is deprecated but tolerated.
2219 22 ▶ if(UNIVERSAL::isa('PDL::Graphics::Gnuplot',$_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa('PDL::Graphics::Gnuplot', $_[0])) { } 21 1 22
2220 21 $classname = shift;
2221 } else {
2222 1 $classname = "PDL::Graphics::Gnuplot";
2223 }
2224  
2225 # Declare & bless minimal object to hold everything.
2226 22 my $this = { t0 => [gettimeofday], # last access
2227 options => {multiplot=>0}, # multiplot option actually holds multiplotting state flag
2228 replottable => 0, # small amount of state...
2229 interactive => 0,
2230 };
2231 22 bless($this,$classname);
2232  
2233 # start up a gnuplot
2234 22 _startGnuplot($this,'main');
2235 22 ▶ _startGnuplot($this,'syntax') if($check_syntax);
Branch: 1 branch
BranchTrueFalseTotal
if $PDL::Graphics::Gnuplot::check_syntax 0 22 22
2236  
2237 # Parse and process all remaining parameters using output(), below.
2238 22 output($this, @_);
2239  
2240 22 ▶ _logEvent($this, "startGnuplot() finished") if ($this->{options}{tee});
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"options"}{"tee"} 0 22 22
2241  
2242 22 return $this;
2243 }
2244  
2245 ##############################
2246 # output - set output terminal and options.
2247  
2248 =pod
2249  
2250 =head2 output
2251  
2252 =for usage
2253  
2254 $window->output( $device );
2255 $window->output( $device, %device_options );
2256 $window->output( $device, %device_options, {plot_options} );
2257 $window->output( %device_options, {plot_options} );
2258 $window->output( %device_options );
2259  
2260 =for ref
2261  
2262 Sets the output device and options for a Gnuplot object. If you omit
2263 the C<$device> name, then you get the gnuplot default device (generally
2264 C<x11>, C<wxt>, or C<aqua>, depending on platform).
2265  
2266 You can control the output device of a PDL::Graphics::Gnuplot object on
2267 the fly. That is useful, for example, to replot several versions of the
2268 same plot to different output devices (interactive and hardcopy).
2269  
2270 Gnuplot interprets terminal options differently per device.
2271 PDL::Graphics::Gnuplot attempts to interpret some of the more common
2272 ones in a common way. In particular:
2273  
2274 =over 3
2275  
2276 =item size
2277  
2278 Most drivers support a "size" option to specify the size of the output
2279 plotting surface. The format is [$width, $height, $unit]; the
2280 trailing unit string is optional but recommended, since the default
2281 unit of length changes from device to device.
2282  
2283 The unit string can be in, cm, mm, px, char, or pt. Pixels are taken
2284 to be 1 point in size (72 pixels per inch) and dimensions are computed
2285 accordingly. Characters are taken to be 12 point in size (6 per
2286 inch).
2287  
2288 =item output
2289  
2290 This option actually sets the object's "output" option for most terminal
2291 devices; that changes the file to which the plot will be written. Some
2292 devices, notably X11 and Aqua, don't make proper use of "output"; for those
2293 devices, specifying "output" in the object constructor actually sets the
2294 appropriate terminal option (e.g. "window" in the X11 terminal).
2295 This is described as a "plot option" in the Gnuplot manual, but it is
2296 treated as a setup variable and parsed with the setup/terminal options here
2297 in the constructor.
2298  
2299 If you don't specify an output device, plots will go to sequentially-numbered
2300 files of the form C<Plot-E<lt>nE<gt>.E<lt>sufE<gt>> in your current working
2301 directory. In that case, PDL::Graphics::Gnuplot will report (on STDERR)
2302 where the plot ended up.
2303  
2304 =item enhanced
2305  
2306 This is a flag that indicates whether to enable Gnuplot's enhanced text
2307 processing (e.g. for superscripts and subscripts). Set it to a false
2308 value for plain text, to a true value for enhanced text (which includes
2309 LaTeX-like markup for super/sub scripts and fonts).
2310  
2311 =item aa
2312  
2313 For certain pixel-grid terminals (currently only C<pncairo> and
2314 C<png>, as of v2.012), you can specify an antialiasing factor for the
2315 output. The output is rendered oversized by a factor of C<aa>, then
2316 scaled down using C<PDL::Transform>. Fixed font sized, line widths,
2317 and point sizes are autoscaled -- but you must handle variable ones
2318 explicitly.
2319  
2320 Antialiasing is done in the gamma=2.2 approximation, to match the sRGB
2321 coding that most pixel image files use. (See PDL::Transform::Color
2322 for more information).
2323  
2324 =back
2325  
2326 For a brief description of the terminal options that any one device supports,
2327 you can run PDL::Graphics::Gnuplot::terminfo().
2328  
2329 As with plot options, terminal options can be abbreviated to the shortest
2330 unique string -- so (e.g.) "size" can generally be abbreviated "si" and
2331 "monochrome" can be abbreviated "mono" or "mo".
2332  
2333 =cut
2334  
2335 23 ▶sub output {
Subroutine output: called CC=26 SCAR=42.7
Pod documented
2336 23 my $this = _obj_or_global(\@_);
2337  
2338 # Check if the last passed-in parameter is a hash ref -- if it is, then it is plot options
2339 23 my $poh;
2340 23 ▶ if( (0+@_) && ref($_[$#_]) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (0 + @_ and ref $_[$#_] eq "HASH") 0 23 23
Condition66%2/3
0 + @_ and ref $_[$#_] eq "HASH"
!ll&&!rl&&r
3200
MC/DC0%0/2
0 + @_ and ref $_[$#_] eq "HASH"
0 + @_ ref $_[$#_] eq "HASH"
Truth table66%2/3
A and B
A= 0 + @_B= ref $_[$#_] eq "HASH"
ABresult
0X0
100
111
2341 0 $poh = pop @_;
2342 }
2343 # parse plot options (if any)
2344 23 ▶ if($poh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($poh) 0 23 23
2345 0 options($this,$poh);
2346 }
2347  
2348 # If there are no arguments, we're not setting the terminal - so we need to
2349 # ask gnuplot what it thinks the terminal is. Then we run it through the usual
2350 # setting logic, to make sure we've got our terminal options parsing and
2351 # other switches set right (e.g. does the default terminal support mouse input?)
2352 23 my $terminal = "";
2353 23 ▶ unless(@_ && (@_ % 2)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@_ and @_ % 2) 4 19 23
Condition100%3/3
@_ and @_ % 2
!ll&&!rl&&r
3119
MC/DC100%2/2
@_ and @_ % 2
@_ @_ % 2
Truth table100%3/3
A and B
A= @_B= @_ % 2
ABresult
0X0
100
111
2354 4 _printGnuplotPipe($this, "main","show terminal\n");
2355 4 my $show = _checkpoint($this, "main");
2356 4 ▶ unless($show =~ s/^\s*terminal type is ((\w+)(.*[^\s])?)\s*$/$1/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($show =~ s/^\s*terminal type is ((\w+)(.*[^\s])?)\s*$/$1/) { } 4 0 4
2357 0 barf "You seem to be using the default terminal, but gnuplot was unwilling to report it!"
2358 } else {
2359 4 unshift(@_, $2);
2360 }
2361 }
2362  
2363 23 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 23 0 23
2364 # Check that, if there is at least one more argument, it is recognizable as a terminal
2365 23 my $terminal = lc(shift);
2366 23 ▶ $terminal = 'dumb' if $terminal eq 'unknown';
Branch: 1 branch
BranchTrueFalseTotal
if $terminal eq "unknown" 4 19 23
2367 ##############################
2368 # Check the terminal list here!
2369 23 ▶ if(!exists($this->{valid_terms}->{$terminal})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $this->{"valid_terms"}{$terminal}) 0 23 23
2370 0 my $s;
2371 0 our $termTabSource;
2372  
2373 0 ▶ if(exists($this->{unknown_terms}->{$terminal})) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $this->{'unknown_terms'}{$terminal}) { } 0 0 0
elsif (exists $PDL::Graphics::Gnuplot::termTab->{$terminal}) { } 0 0 0
2374 0 $s = <<"FOO";
2375 PDL::Graphics::Gnuplot: Your gnuplot has terminal '$terminal' but it is not supported.
2376 $terminal: $this->{unknown_terms}->{$terminal}
2377 FOO
2378  
2379 }
2380 elsif(exists($termTab->{$terminal})) {
2381 0 $s = <<"FOO";
2382 PDL::Graphics::Gnuplot: your gnuplot appears not to support the terminal '$terminal'.
2383 $terminal: $termTabSource->{$terminal}->{desc} [not in reported list from gnuplot]
2384 FOO
2385 }
2386 else {
2387 0 $s = "PDL::Graphics::Gnuplot: neither this module nor your gnuplot support '$terminal'.\n";
2388 0 ▶ if(exists($termTabSource->{$terminal})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDL::Graphics::Gnuplot::termTabSource->{$terminal}) { } 0 0 0
2389 0 $s .= " $terminal: $termTabSource->{$terminal}\n";
2390 } else {
2391 0 $s .= " $terminal: doesn't appear to be a gnuplot terminal name\n";
2392 }
2393 }
2394  
2395 0 $s .= "\nYou can use the 'terminfo' method for a list of available terminals.\n\n";
2396 0 barf($s);
2397 }
2398  
2399 # Generate abbrevs on first invokation for each terminal type.
2400 23 ▶ unless($termTab->{$terminal}->{opt}->[1]) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDL::Graphics::Gnuplot::termTab->{$terminal}{"opt"}[1]) 1 22 23
2401 1 $termTab->{$terminal}->{opt}->[1] = _gen_abbrev_list(keys %{$termTab->{$terminal}->{opt}[0]});
2402 1 $termTab->{$terminal}->{opt}->[0]->{__unit__} = ['s','-']; # Hack so we can stash the unit string in there later.
2403 }
2404  
2405 23 my $termOptions = {};
2406  
2407 # parse "terminal" options
2408 23 ▶ if($termTab->{$terminal} && $termTab->{$terminal}->{opt}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PDL::Graphics::Gnuplot::termTab->{$terminal} and $PDL::Graphics::Gnuplot::termTab->{$terminal}{'opt'}) { } 23 0 23
Condition33%1/3
$PDL::Graphics::Gnuplot::termTab->{$terminal} and $PDL::Graphics::Gnuplot::termTab->{$terminal}{"opt"}
!ll&&!rl&&r
0023
MC/DC0%0/2
$PDL::Graphics::Gnuplot::termTab->{$terminal} and $PDL::Graphics::Gnuplot::termTab->{$terminal}{"opt"}
$PDL::Graphics::Gnuplot::termTab->{$terminal} $PDL::Graphics::Gnuplot::termTab->{$terminal}{"opt"}
Truth table33%1/3
A and B
A= $PDL::Graphics::Gnuplot::termTab->{$terminal}B= $PDL::Graphics::Gnuplot::termTab->{$terminal}{"opt"}
ABresult
0X0
100
111
2409  
2410 # Stuff the default output filename into the options hash (will be overwritten if
2411 # the user specified an "output" option)
2412 23 $termOptions->{'output'} = $termTab->{$terminal}->{default_output};
2413  
2414 # Stuff the default size unit into the options hash, so that the parser has access to it.
2415 23 $termOptions->{'__unit__'} = $termTab->{$terminal}->{unit};
2416  
2417 23 _parseOptHash( $termOptions, $termTab->{$terminal}->{opt}, @_ );
2418  
2419 # Default the 'persist' option to 0, so that interactive windows behave nicely unless
2420 # asked to stay.
2421 23 ▶ if (exists($termTab->{$terminal}{opt}[0]{persist}) and
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDL::Graphics::Gnuplot::termTab->{$terminal}{"opt"}[0]{"persist"} and not defined $termOptions->{"persist"}) 0 23 23
Condition33%1/3
exists $PDL::Graphics::Gnuplot::termTab->{$terminal}{"opt"}[0]{"persist"} and not defined $termOptions->{"persist"}
!ll&&!rl&&r
2300
MC/DC0%0/2
exists $PDL::Graphics::Gnuplot::termTab->{$terminal}{"opt"}[0]{"persist"} and not defined $termOptions->{"persist"}
exists $PDL::Graphics::Gnuplot::termTab->{$terminal}{"opt"}[0]{"persist"} not defined $termOptions->{"persist"}
Truth table33%1/3
A and not(B)
A= exists $PDL::Graphics::Gnuplot::termTab->{$terminal}{"opt"}[0]{"persist"}B= not defined $termOptions->{"persist"}
ABresult
0X0
100
111
2422 !defined($termOptions->{persist}) ) {
2423 0 $termOptions->{persist} = 0;
2424 }
2425  
2426 # Default the 'dashed' option to 1.
2427 23 ▶ if (exists($termTab->{$terminal}{opt}[0]{dashed}) and
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDL::Graphics::Gnuplot::termTab->{$terminal}{"opt"}[0]{"dashed"} and not defined $termOptions->{"dashed"}) 0 23 23
Condition33%1/3
exists $PDL::Graphics::Gnuplot::termTab->{$terminal}{"opt"}[0]{"dashed"} and not defined $termOptions->{"dashed"}
!ll&&!rl&&r
2300
MC/DC0%0/2
exists $PDL::Graphics::Gnuplot::termTab->{$terminal}{"opt"}[0]{"dashed"} and not defined $termOptions->{"dashed"}
exists $PDL::Graphics::Gnuplot::termTab->{$terminal}{"opt"}[0]{"dashed"} not defined $termOptions->{"dashed"}
Truth table33%1/3
A and not(B)
A= exists $PDL::Graphics::Gnuplot::termTab->{$terminal}{"opt"}[0]{"dashed"}B= not defined $termOptions->{"dashed"}
ABresult
0X0
100
111
2428 !defined($termOptions->{dashed}) ) {
2429 0 $termOptions->{dashed} = 1;
2430 }
2431  
2432 # Although 'output' is strictly speaking a terminal option, gnuplot treats it as a plot option -- so
2433 # we copy it into the main plot options hash to be emitted as part of the plot operation.
2434 23 $this->{options}{output} = $termOptions->{output};
2435 23 ▶ $this->{wait} = $termOptions->{wait} if defined $termOptions->{wait};
Branch: 1 branch
BranchTrueFalseTotal
if defined $termOptions->{"wait"} 1 22 23
2436  
2437 ### Deal with anti-aliasing scaling factors
2438 23 ▶ if( defined $termOptions->{aa}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $termOptions->{'aa'}) { } 0 23 23
2439 $this->{aa} = $termOptions->{aa}
2440 0 } else {
2441 23 $this->{aa} = 1;
2442 }
2443  
2444 ### Set a default font size for better control
2445 23 ▶ unless(defined $termOptions->{font}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $termOptions->{"font"}) 23 0 23
2446 23 ▶ if($termTab->{$terminal}->{opt}->[0]->{font}){
Branch: 1 branch
BranchTrueFalseTotal
if ($PDL::Graphics::Gnuplot::termTab->{$terminal}{"opt"}[0]{"font"}) 0 23 23
2447 0 $termOptions->{font} = ',10';
2448 }
2449 }
2450  
2451 ### Terminals that support anti-aliasing all broadcast their format so that rpic can handle them.
2452 23 ▶ if( defined $termTab->{$terminal}->{image_format}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $PDL::Graphics::Gnuplot::termTab->{$terminal}{'image_format'}) { } 0 23 23
2453 0 $this->{image_format}= $termTab->{$terminal}->{image_format};
2454 } else {
2455 23 delete($this->{image_format});
2456 }
2457  
2458  
2459 23 delete $termOptions->{output};
2460  
2461 ## Emit the terminal options line for this terminal.
2462 23 $this->{options}{terminal} = join(" ", ($terminal, _emitOpts( $termOptions, $termTab->{$terminal}{opt} )));
2463 23 $this->{terminal} = $terminal;
2464 23 ▶ $this->{mouse} = $termTab->{$terminal}{mouse} || 0;
Condition50%1/2
$PDL::Graphics::Gnuplot::termTab->{$terminal}{'mouse'} || 0
l!l
023
MC/DC0%0/1
$PDL::Graphics::Gnuplot::termTab->{$terminal}{'mouse'} || 0
$PDL::Graphics::Gnuplot::termTab->{$terminal}{'mouse'}
Truth table50%1/2
A
A= $PDL::Graphics::Gnuplot::termTab->{$terminal}{'mouse'}
Aresult
11
00
2465 } else {
2466 0 barf "PDL::Graphics::Gnuplot doesn't support the device '$terminal', sorry\n\n Run PDL::Graphics::Gnuplot::terminfo() for a list of devices.\n\n";
2467 }
2468 }
2469  
2470 23 return $this;
2471 }
2472  
2473 ##############################
2474 # DESTROY - required to make sure the subprocess is gone.
2475 # (no POD since it's not part of the usual API)
2476  
2477 sub DESTROY
2478 21 ▶{
Subroutine DESTROY: called CC=1 SCAR=0.0
2479 21 my $this = shift;
2480 21 _killGnuplot($this);
2481 }
2482  
2483 =pod
2484  
2485 =head2 close
2486  
2487 =for usage
2488  
2489 $w=gpwin();
2490 $w->plot(xvals(5));
2491 $w->close;
2492  
2493 =for ref
2494  
2495 Close gnuplot process (actually just a synonym for restart)
2496  
2497 Some of the gnuplot terminals (e.g. pdf) don't write out a file
2498 promptly. The close method closes the associated gnuplot subprocess,
2499 forcing the file to be written out. It is implemented as a simple
2500 restart operation.
2501  
2502 The object preserves the plot state, so C<replot> and similar methods
2503 still work with the new subprocess.
2504  
2505 =cut
2506  
2507 sub close
2508 9 ▶{
Subroutine close: called CC=9 SCAR=38.9
Pod documented
2509 9 my $this = shift;
2510 9 restart($this);
2511 9 ▶ if(defined $this->{aa} && $this->{aa} && $this->{aa} != 1 && $this->{aa_ready}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $this->{"aa"} and $this->{"aa"} and $this->{"aa"} != 1 and $this->{"aa_ready"}) 0 9 9
Condition33%3/9
defined $this->{"aa"} and $this->{"aa"} and $this->{"aa"} != 1 and $this->{"aa_ready"}
!ll&&!rl&&r
900
defined $this->{"aa"} and $this->{"aa"} and $this->{"aa"} != 1
!ll&&!rl&&r
090
defined $this->{"aa"} and $this->{"aa"}
!ll&&!rl&&r
009
MC/DC0%0/4
defined $this->{"aa"} and $this->{"aa"} and $this->{"aa"} != 1 and $this->{"aa_ready"}
defined $this->{"aa"} $this->{"aa"} $this->{"aa"} != 1 $this->{"aa_ready"}
Truth table20%1/5
A and B and C and D
A= defined $this->{"aa"}B= $this->{"aa"}C= $this->{"aa"} != 1D= $this->{"aa_ready"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2512 0 eval "use PDL::Transform; use PDL::IO::Pic;"; # load when needed
2513 0 ▶ unless( rpiccan($this->{image_format}) and wpiccan($this->{image_format}) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (rpiccan($this->{"image_format"}) and wpiccan($this->{"image_format"})) 0 0 0
Condition0%0/3
rpiccan($this->{"image_format"}) and wpiccan($this->{"image_format"})
!ll&&!rl&&r
000
MC/DC0%0/2
rpiccan($this->{"image_format"}) and wpiccan($this->{"image_format"})
rpiccan($this->{"image_format"}) wpiccan($this->{"image_format"})
Truth table0%0/3
A and B
A= rpiccan($this->{"image_format"})B= wpiccan($this->{"image_format"})
ABresult
0X0
100
111
2514 0 carp "Can not read/write $this->{image_format} for anti-aliasing. Skipping aa operation.";
2515 0 return;
2516 }
2517 0 my $im = rpic($this->{options}{output},{FORMAT=>$this->{image_format}});
2518 0 ▶ if($im->ndims==3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($im->ndims == 3) 0 0 0
2519 0 $im = $im->mv(0,-1);
2520 }
2521 # gamma-correct before scaling, and put back after.
2522 0 my $imf = ((float $im)/255.0)->clip(0,1) ** 2.2;
2523 0 $imf = $imf->match( [ $im->dim(0)/$this->{aa}, $im->dim(1)/$this->{aa} ], {method=>'h',blur=>0.5});
2524 0 $imf->check_badflag;
2525 0 $im = byte(($imf ** (1/2.2)) * 255);
2526 0 ▶ if($im->ndims==3){
Branch: 1 branch
BranchTrueFalseTotal
if ($im->ndims == 3) 0 0 0
2527 0 $im = $im->mv(-1,0);
2528 }
2529 0 wpic($im, $this->{options}{output}, {FORMAT=>$this->{image_format}});
2530 }
2531 9 $this->{aa_ready} = 0;
2532 }
2533  
2534 =pod
2535  
2536 =head2 restart
2537  
2538 =for usage
2539  
2540 $w->restart();
2541 PDL::Graphics::Gnuplot::restart();
2542  
2543 =for ref
2544  
2545 Restart the gnuplot backend for a plot object
2546  
2547 Occasionally the gnuplot backend can get into an unknown state.
2548 C<restart> kills the gnuplot backend and starts a new one, preserving
2549 state in the object. (i.e. C<replot> and similar functions work even
2550 with the new subprocess).
2551  
2552 Called with no arguments, C<restart> applies to the global plot object.
2553  
2554 =cut
2555  
2556 # reset - stops and restarts the underlying gnuplot process for an object
2557 3 *grestart = \&restart;
2558 23 ▶sub restart {
Subroutine restart: called CC=3 SCAR=11.0
Pod documented
2559 23 my $this = _obj_or_global(\@_);
2560 23 my $dumpswitch = shift;
2561 23 my $localdumpvar = $this->{options}{dump};
2562 {
2563 # We restart the process when the dump option is switched on or off.
2564 # Since _killGnuplot uses _printGnuplotPipe, we have
2565 # to hold the old state briefly while the old process is killed.
2566 23 local($this->{options}{dump}) =
2567 23 ▶ ($dumpswitch ? $this->{dumping} : $localdumpvar);
Branch: 1 branch
BranchTrueFalseTotal
$dumpswitch ? : 0 23 23
2568  
2569 23 _killGnuplot($this);
2570 }
2571 # When starting Gnuplot we use the {options}->{dump} flag as it should be.
2572 23 _startGnuplot($this,'main');
2573 23 ▶ _startGnuplot($this,'syntax') if($check_syntax);
Branch: 1 branch
BranchTrueFalseTotal
if $PDL::Graphics::Gnuplot::check_syntax 0 23 23
2574 23 $this->{options}{multiplot} = 0;
2575 23 undef $PDL::Graphics::Gnuplot::last_plotcmd;
2576 23 undef $PDL::Graphics::Gnuplot::last_testcmd;
2577 23 undef $this->{last_plotcmd};
2578 23 undef $this->{last_testcmd};
2579 }
2580  
2581  
2582 =pod
2583  
2584 =head2 reset
2585  
2586 =for usage
2587  
2588 $w->reset()
2589  
2590 =for ref
2591  
2592 Clear state from the gnuplot backend
2593  
2594 Clears all plot option state from the underlying object. All plot
2595 options except "terminal", "termoptions", "output", and "multiplot"
2596 are cleared. This is similar to the "reset" command supported by
2597 gnuplot itself, and in fact it also causes a "reset" to be sent to
2598 gnuplot.
2599  
2600  
2601 =cut
2602  
2603 3 *greset = \*reset;
2604 4 ▶sub reset {
Subroutine reset: called CC=2 SCAR=7.1
Pod documented
2605 4 my $this = _obj_or_global(\@_);
2606 4 delete @{$this->{options}}{
2607 4 grep !/(terminal|output|termoptions|multiplot)/, keys %{$this->{options}}
2608 };
2609 4 my $checkpointMessage;
2610 4 ▶ if ($check_syntax) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PDL::Graphics::Gnuplot::check_syntax) 0 4 4
2611 # Send multiple newlines to avoid bugs in certain gnuplots, which
2612 # appear to lose a character after reset.
2613 0 _printGnuplotPipe($this, "syntax", "reset\n\n\n");
2614 0 $checkpointMessage = _checkpoint($this,"syntax");
2615 }
2616 4 _printGnuplotPipe($this, "main", "reset\n\n\n");
2617 4 $checkpointMessage = _checkpoint($this, "main");
2618 4 $this->{replottable} = 0;
2619 4 delete $this->{last_plot};
2620 4 return $this;
2621 }
2622  
2623  
2624 ##############################
2625 #
2626 # Options setting routines
2627 #
2628  
2629 =pod
2630  
2631 =head2 options
2632  
2633 =for usage
2634  
2635 $w = new PDL::Graphics::Gnuplot();
2636 $w->options( globalwith=>'lines' );
2637 print %{$w->options()};
2638  
2639 =for ref
2640  
2641 Set/get persistent plot options for a plot object
2642  
2643 The options method parses plot options into a gnuplot object on a
2644 cumulative basis, and returns the resultant options hash.
2645  
2646 If called as a sub rather than a method, options() changes the
2647 global gnuplot object.
2648  
2649 =cut
2650  
2651 3 *option = \&options;
2652 11 ▶sub options {
Subroutine options: called CC=4 SCAR=14.0
Pod documented
2653 11 my ($me) = _obj_or_global(\@_);
2654 11 ▶ $me->{options} //= {};
Condition50%1/2
$me->{"options"} //= {}
l!l
110
MC/DC0%0/1
$me->{"options"} //= {}
$me->{"options"}
Truth table50%1/2
A
A= $me->{"options"}
Aresult
11
00
2655 11 _parseOptHash($me->{options}, $pOpt, @_);
2656 _parseOptHash($me->{last_plot}{options}, $pOpt, @_)
2657 9 ▶ if $me->{last_plot} && $me->{last_plot}{options};
Branch: 1 branch
BranchTrueFalseTotal
if $me->{"last_plot"} and $me->{"last_plot"}{"options"} 2 7 9
Condition66%2/3
$me->{"last_plot"} and $me->{"last_plot"}{"options"}
!ll&&!rl&&r
702
MC/DC50%1/2
$me->{"last_plot"} and $me->{"last_plot"}{"options"}
$me->{"last_plot"} $me->{"last_plot"}{"options"}
Truth table66%2/3
A and B
A= $me->{"last_plot"}B= $me->{"last_plot"}{"options"}
ABresult
0X0
100
111
2658 9 return $me->{options};
2659 }
2660  
2661 ######################################################################
2662 ######################################################################
2663 #
2664 # plot - the main API function to generate a plot.
2665  
2666 =pod
2667  
2668 =head2 plot_generate
2669  
2670 =for ref
2671  
2672 Called with the same arguments as L</plot>, it returns the text that
2673 would be sent to Gnuplot. Exportable.
2674 Added in 2.025.
2675  
2676 =cut
2677  
2678 sub plot_generate
2679 1 ▶{
Subroutine plot_generate: called CC=3 SCAR=12.5
Pod documented
2680 1 ▶ barf "plot_generate called with no arguments" unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 1 1
2681 1 my ($plotchunks) = _obj_or_global(\@_)->_plot_generate(@_);
2682 0 ▶ join '', map ref $_ eq 'ARRAY' ? $_->[0] : ${$_->[0]}, @$plotchunks;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'ARRAY' ? : 4 0 4
2683 }
2684  
2685 =head2 gplot
2686  
2687 =for ref
2688  
2689 Plot method exported by default (synonym for "PDL::Graphics::Gnuplot::plot")
2690  
2691 =head2 plot
2692  
2693 =for ref
2694  
2695 This is the main plotting routine in PDL::Graphics::Gnuplot.
2696  
2697 Each C<plot()> call creates a new plot from whole cloth, either creating
2698 or overwriting the output for that device.
2699  
2700 If you want to add features to an existing plot, use C<replot>.
2701  
2702 C<plot()> understands the PDL bad value mechanism. Bad values are omitted
2703 from the plot.
2704  
2705 =for usage
2706  
2707 $w=gpwin();
2708 $w->plot({temp_plot_options}, # optional
2709 curve_options, data, data, ... , # curve_options are optional for the first plot
2710 curve_options, data, data, ... ,
2711 {temp_plot_options});
2712  
2713 Most of the arguments are optional.
2714  
2715 All of the extensive array of gnuplot plot styles are supported, including images and 3-D plots.
2716  
2717 =for example
2718  
2719 use PDL::Graphics::Gnuplot qw(plot);
2720 my $x = sequence(101) - 50;
2721 plot($x**2);
2722  
2723 See main POD for PDL::Graphics::Gnuplot for details.
2724  
2725 You can pass plot options into plot as either a leading or trailing hash ref, or both.
2726 If you pass both, the trailing hash ref is parsed last and overrides the leading hash.
2727  
2728 For debugging and curiosity purposes, the last plot command issued to gnuplot
2729 is maintained in a package global: C<$PDL::Graphics::Gnuplot::last_plotcmd>, and also
2730 in each object as the {last_plotcmd} field.
2731  
2732 =cut
2733  
2734 sub _plot_generate
2735 102 ▶{
Subroutine _plot_generate: called CC=139 SCAR=65.2
2736 102 my $this = shift;
2737 102 delete $this->{last_dashtype}; # implement dashtype state function for gnuplot>=5.0
2738 ##############################
2739 # Parse optional plot options - must be an array or hash ref, if present.
2740 # Cheesy but hopefully effective method (from Dima): parse as plot options
2741 # and if that throws an error treat 'em as curve options instead.
2742 #
2743 # This is additionally complicated by the desire to make these *temporary*
2744 # options -- so we don't accumulate the options in the main object options
2745 # hash.
2746 #
2747 # The temporariness is accomplished by localizing $this->{options} and replacing
2748 # it with either itself or the parsed copy of itself.
2749 #
2750 #
2751 # As an additional DWIM to make Dima happy, we parse initial options as plot
2752 # options until encountering something that could conceivably be a curve option -
2753 # whereupon we switch to curve options. The DWIMming is done by checking individual
2754 # option names to see if they (A) are NOT curve options and (B) are plot options.
2755 # We snarf up all such options and put 'em into a hash ref like they should have been.
2756 102 my @dwim_plot_options;
2757 102 ▶ while( 0+@_ and !(ref $_[0]) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 + @_ and not ref $_[0]) 52 68 120
Condition100%3/3
0 + @_ and not ref $_[0]
!ll&&!rl&&r
26652
MC/DC100%2/2
0 + @_ and not ref $_[0]
0 + @_ not ref $_[0]
Truth table100%3/3
A and not(B)
A= 0 + @_B= not ref $_[0]
ABresult
0X0
100
111
2758 52 my ($kk,$knum) = eval { _expand_abbrev($_[0], @$cOpt[1,2]) };
2759 52 ▶ last if !$@;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 34 18 52
2760 18 ($kk,$knum) = eval { _expand_abbrev($_[0], @$pOpt[1,2]) };
2761 18 ▶ last if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 18 18
2762 # It's a plot option and not a curve option -- pull it, and its argument, from the arg list and put them
2763 # into @dwim_plot_options.
2764 18 push @dwim_plot_options, shift, shift;
2765 }
2766 102 ▶ unshift @_, \@dwim_plot_options if @dwim_plot_options;
Branch: 1 branch
BranchTrueFalseTotal
if @dwim_plot_options 8 94 102
2767 # Any option parsing we do is ephemeral, so we have to localize the options hash, so we dclone it at
2768 # the start. If we're replotting, start with the last_plot options - which gets the same treatment even
2769 # though it will be overwritten with its own clone on successful completion. That is so, if we fail,
2770 # the last_plot hash options hash remains unchanged in the object.
2771 102 my $o;
2772 102 ▶ if($this->{replotting}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'replotting'}) { } 3 99 102
2773 3 $o = dclone($this->{last_plot}{options});
2774 3 $o->{terminal} = $this->{options}{terminal};
2775 3 $o->{output} = $this->{options}{output};
2776 } else {
2777 99 $o = dclone($this->{options});
2778 }
2779 # Now parse the initial hash of plot options (if there is one)
2780 102 ▶ if ( (ref $_[0]) =~ m/^(HASH|ARRAY)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($_[0]) =~ /^(HASH|ARRAY)/) 37 65 102
2781 37 my $oo = dclone($o);
2782 37 eval { _parseOptHash( $oo, $pOpt, $_[0] ); };
2783 37 ▶ if($@ =~ m/^No /) {
Branch: 2 branches
BranchTrueFalseTotal
if ($@ =~ /^No /) { } 12 25 37
elsif ($@) { } 0 25 25
2784 # Found an unrecognized keyword -- clear the error and keep going.
2785 # (not a set of plot options)
2786 12 $@ = "";
2787 } elsif($@) {
2788 # Some other actual exception -- pass it down the line. Oops.
2789 0 barf $@ . " (while parsing presumed extra plot options at start of plot command)\n";
2790 } else {
2791 # worked!
2792 25 $o = $oo;
2793 25 shift @_; # pull argument off the start.
2794 }
2795 }
2796 # Now look for and parse a trailing hash of plot options (if there is one)
2797 102 ▶ if (@_ >= 2 and ((ref $_[-1])=~ /^(HASH)/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ >= 2 and ref($_[-1]) =~ /^(HASH)/) 21 81 102
Condition100%3/3
@_ >= 2 and ref($_[-1]) =~ /^(HASH)/
!ll&&!rl&&r
146721
MC/DC100%2/2
@_ >= 2 and ref($_[-1]) =~ /^(HASH)/
@_ >= 2 ref($_[-1]) =~ /^(HASH)/
Truth table100%3/3
A and B
A= @_ >= 2B= ref($_[-1]) =~ /^(HASH)/
ABresult
0X0
100
111
2798 21 my $oo = dclone($o);
2799 21 eval { _parseOptHash( $oo, $pOpt, $_[-1] ); };
2800 21 ▶ if ($@ =~ m/^No /) {
Branch: 2 branches
BranchTrueFalseTotal
if ($@ =~ /^No /) { } 0 21 21
elsif ($@) { } 0 21 21
2801 # Found an unrecognized keyword -- clear the error and keep going.
2802 # (not a set of plot options)
2803 0 $@ = "";
2804 } elsif ($@) {
2805 # Some other actual exception -- pass it down the line. Oops.
2806 0 barf $@ . " (while parsing presumed extra plot options at end of plot command)\n";
2807 } else {
2808 # worked!
2809 21 $o = $oo;
2810 21 pop @_; # pull argument off the end.
2811 }
2812 }
2813 # Localize the options hash for uniform reference. Now the
2814 # object options has the full parsed options, but it is fully localized --
2815 # it will revert to its pre-call state when we exit this block.
2816 102 local($this->{options}) = $o;
2817 102 local($this->{tmp_options}) = {};
2818 # Make sure to reset the palette to the gnuplot default if it's not set here
2819 102 ▶ $this->{options}{palette} ||= [];
Condition100%2/2
$this->{"options"}{"palette"} ||= []
l!l
399
MC/DC100%1/1
$this->{"options"}{"palette"} ||= []
$this->{"options"}{"palette"}
Truth table100%2/2
A
A= $this->{"options"}{"palette"}
Aresult
11
00
2820 # If we're replotting, then any remaining arguments need to be put
2821 # *after* the arguments that we used for the last plot.
2822 3 ▶ unshift @_, @{$this->{last_plot}{args}}, !$_[0]->$_isa('PDL') ? () : {}
Branch: 1 branch
BranchTrueFalseTotal
!$_[0]->$PDL::Graphics::Gnuplot::_isa('PDL') ? : 2 1 3
2823 102 ▶ if $this->{replotting};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"replotting"} 3 99 102
2824 ##############################
2825 # Set binary mode default. This is a bit complex since
2826 # we sometimes default to binary and sometimes to ascii.
2827 102 local $this->{binary_flag_defaulted} = !defined $this->{options}{binary};
2828 # The user didn't explicitly set binary or non-binary mode. Try to guess.
2829 # Also, under Microsoft Windows binary mode seems to be dicey
2830 # (Juegen Mueck's hang test), so we default to ascii.
2831 $this->{options}{binary} //=
2832 # Early gnuplot - ASCII mode only (by default)
2833 ($this->{early_gnuplot} || $MS_io_braindamage) ? 0 :
2834 # Late-model gnuplot - binary for non time format plots, ASCII for time plots.
2835 # (Note: some transfer formats force binary transfer)
2836 102 ▶ !grep +($this->{options}{$_."data"}||'') =~ m/time/,
Branch: 1 branch
BranchTrueFalseTotal
$this->{'early_gnuplot'} || $PDL::Graphics::Gnuplot::MS_io_braindamage ? : 0 82 82
Condition71%5/7
$this->{"options"}{"binary"} //= $this->{"early_gnuplot"} || $PDL::Graphics::Gnuplot::MS_io_braindamage ? 0 : !grep((($this->{"options"}{$_ . 'data'} || "") =~ /time/), ("x", "x2", "y", "y2", "z", "cb"))
l!l
2082
$this->{"early_gnuplot"} or $PDL::Graphics::Gnuplot::MS_io_braindamage
l!l&&r!l&&!r
0082
$this->{'options'}{$_ . 'data'} || ''
l!l
3489
MC/DC100%1/1
$this->{"options"}{"binary"} //= $this->{"early_gnuplot"} || $PDL::Graphics::Gnuplot::MS_io_braindamage ? 0 : !grep((($this->{"options"}{$_ . 'data'} || "") =~ /time/), ("x", "x2", "y", "y2", "z", "cb"))
$this->{"options"}{"binary"}
MC/DC100%1/1
$this->{'options'}{$_ . 'data'} || ''
$this->{'options'}{$_ . 'data'}
Truth table100%2/2
A
A= $this->{"options"}{"binary"}
Aresult
11
00
Truth table100%2/2
A
A= $this->{'options'}{$_ . 'data'}
Aresult
11
00
2837 qw/x x2 y y2 z cb/;
2838 # Store the current arguments into the state array for next time.
2839 # (This has to be done here because plot options need to be stripped out first).
2840 #
2841 # Because of all the local-variable shenanigans with overlain configs for this and that,
2842 # we unfortunately have to make a deep copy of the plot options for the last_plot.
2843 # The variables we deliberately do *not* deep copy, in case someone wants to use the
2844 # modify-and-replot trick that is in the gnuplot documentation. (That trick uses
2845 # file modification, but in-place modification of PDLs "feels right" too)
2846 #
2847 # We don't store the arguments if we're carrying the "ephemeral" flag - that is
2848 # so we can do ephemeral markup of plots, without adding to the replot list.
2849 102 ▶ unless($this->{ephemeral}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($this->{"ephemeral"}) 102 0 102
2850 102 $this->{last_plot}{args} = [@_];
2851 102 $this->{last_plot}{options} = dclone($this->{options});
2852 delete $this->{last_plot}{options}{binary}
2853 102 ▶ if $this->{binary_flag_defaulted};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"binary_flag_defaulted"} 82 20 102
2854 }
2855 # Now parse the rest of the arguments into chunks.
2856 102 my ($chunks, $Ncurves) = parseArgs($this, @_);
2857 0 ▶ if (scalar @$chunks == 0) { barf "plot() was not given any data"; }
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$chunks == 0) 0 85 85
2858 ##############################
2859 #
2860 # Now generate the plot command.
2861 # This is complicated by the need to generate two separate commands --
2862 # the main command (which goes into $plotcmd), and a separate test command
2863 # that is intended to check syntax (and goes into $testcmd).
2864 #
2865 # We start by emitting the options string (and re-emitting it with the dumb
2866 # terminal, for the test command), then emitting a mock-up of each
2867 # chunk's plot/curve arguments into a single "plot" command line. This first
2868 # line doesn't contain the data specifier, only a fence string.
2869 #
2870 # Then we cut up the command line into pieces at the fences, so that we can assemble the
2871 # data specifiers and build a complete command line.
2872 #
2873 ##########
2874 # Figure per-curve binary/ASCII mode, and fix up some of the option defaults based on context.
2875 # In particular, gnuplot 4.4-4.6 don't handle image scaling correctly, so unless an xrange/yrange
2876 # is specified we have to take care of it ourselves.
2877 #
2878 # This is complicated in the case when there are multiple chunks, one of which is an image.
2879 # We can't set an overall range until we scan the whole collection of chunks.
2880 85 my ($im_ranges, $active_axes, $cbmin, $cbmax, @axes_by_chunkno) = ({}, {});
2881 85 for my $i (0..$#$chunks) {
2882 # Allow global binary/ASCII flag to be overridden by per-curve binary/ASCII flag
2883 92 ▶ $chunks->[$i]{binaryCurveFlag} = $chunks->[$i]{binaryWith} // $this->{options}{binary};
Condition66%2/3
$chunks->[$i]{"binaryWith"} // $this->{"options"}{"binary"}
l!l&&r!l&&!r
13790
MC/DC0%0/2
$chunks->[$i]{"binaryWith"} // $this->{"options"}{"binary"}
$chunks->[$i]{"binaryWith"} $this->{"options"}{"binary"}
Truth table66%2/3
A // B
A= $chunks->[$i]{"binaryWith"}B= $this->{"options"}{"binary"}
ABresult
1X1
011
000
2884 # Figure which axes are active
2885 92 ▶ my $axis_str = $chunks->[$i]{options}{axes} // 'x1y1';
Condition50%1/2
$chunks->[$i]{"options"}{"axes"} // "x1y1"
l!l
092
MC/DC0%0/1
$chunks->[$i]{"options"}{"axes"} // "x1y1"
$chunks->[$i]{"options"}{"axes"}
Truth table50%1/2
A
A= $chunks->[$i]{"options"}{"axes"}
Aresult
11
00
2886 92 my ($xax,$yax);
2887 92 ▶ if ($axis_str =~ m/x([12])y([12])/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($axis_str =~ /x([12])y([12])/i) { } 92 0 92
2888 92 my ($x,$y) = ($1,$2);
2889 92 ▶ ($xax,$yax) = ($x==1 ? 'x' : 'x2', $y==1 ? 'y' : 'y2');
Branch: 2 branches
BranchTrueFalseTotal
$x == 1 ? : 92 0 92
$y == 1 ? : 92 0 92
2890 } else {
2891 0 carp "WARNING: axes specifier '$axis_str' doesn't make sense. Continuing anyway...\n";
2892 0 ($xax,$yax) = ('x','y');
2893 }
2894 92 $axes_by_chunkno[$i] = [$xax,$yax];
2895 92 $_++ for @$active_axes{$xax, $yax};
2896 # Everything else in this block is an image fix
2897 92 ▶ next unless($chunks->[$i]{imgFlag});
Branch: 1 branch
BranchTrueFalseTotal
unless $chunks->[$i]{"imgFlag"} 75 17 92
2898 # Fix up gnuplot color scaling bug/misfeature for RGB images
2899 # Here, we accumulate min/max color ranges across *all* imagelike chunks,
2900 # so mixing rgb and palette images will scale right.
2901 17 ▶ if(!defined( $this->{options}{cbrange} )) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $this->{"options"}{"cbrange"}) 17 0 17
2902 17 my $with = $chunks->[$i]{options}{with}[0];
2903 17 my $slice = "-1";
2904 17 ▶ $slice = "-3:-1" if $with eq 'rgbimage';
Branch: 1 branch
BranchTrueFalseTotal
if $with eq "rgbimage" 3 14 17
2905 17 ▶ $slice = "-4:-2" if $with eq 'rgbalpha';
Branch: 1 branch
BranchTrueFalseTotal
if $with eq "rgbalpha" 2 15 17
2906 # Sometimes data comes in that has BAD values but they are
2907 # not marked as such, which messes up the cbmin &c. calc.
2908 17 ▶ if ($PDL::Bad::Status){
Branch: 1 branch
BranchTrueFalseTotal
if ($PDL::Bad::Status) 17 0 17
2909 $chunks->[$i]->{data}->[0]->inplace->setvaltobad(
2910 17 $chunks->[$i]->{data}->[0]->type->badvalue)->check_badflag;
2911 }
2912 17 my $bolus = $chunks->[$i]->{data}->[0]->slice($slice);
2913 # Convert NaNs to bad if possible. This is slow --
2914 # need to fix the minmax &c. operators in PDL to ignore NaNs on command;
2915 # currently the default behavior is that NaN poisons the whole min/max
2916 # operation.
2917 17 my ($cmin,$cmax) = $bolus->where(isfinite($bolus))->minmax;
2918 17 ▶ $cbmin = $cmin if( !defined($cbmin) or $cmin < $cbmin );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $cbmin or $cmin < $cbmin 17 0 17
Condition33%1/3
not defined $cbmin or $cmin < $cbmin
l!l&&r!l&&!r
1700
MC/DC0%0/2
not defined $cbmin or $cmin < $cbmin
not defined $cbmin $cmin < $cbmin
Truth table33%1/3
not(A) or B
A= not defined $cbminB= $cmin < $cbmin
ABresult
1X1
011
000
2919 17 ▶ $cbmax = $cmax if( !defined($cbmax) or $cmax < $cbmax );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $cbmax or $cmax < $cbmax 17 0 17
Condition33%1/3
not defined $cbmax or $cmax < $cbmax
l!l&&r!l&&!r
1700
MC/DC0%0/2
not defined $cbmax or $cmax < $cbmax
not defined $cbmax $cmax < $cbmax
Truth table33%1/3
not(A) or B
A= not defined $cbmaxB= $cmax < $cbmax
ABresult
1X1
011
000
2920 }
2921 # Do image ranging.
2922 # This is necessary to tighten up the boundaries around images -- gnuplot ranging
2923 # has a wart in that case, where image boundaries are extended to the nearest round
2924 # number of pixels by default.
2925 #
2926 # We implement that here by accumulating the largest extent covered by images.
2927 # If there are images and no xrange/yrange was set by the user, we set it to that.
2928 17 my $z; # temp. holding space for xrange/yrange for this chunk
2929 17 ▶ if ($chunks->[$i]{ArrayRec} eq 'array') {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunks->[$i]{'ArrayRec'} eq 'array') { } 5 12 17
2930 5 $z = [-0.5, $chunks->[$i]{data}[0]->dim(1) - 0.5];
2931 } else {
2932 12 my($xmin,$xmax) = $chunks->[$i]{data}[0]->slice("(0)")->minmax;
2933 12 my($dx) = ($xmax-$xmin) / $chunks->[$i]{data}[0]->dim(1) * 0.5;
2934 12 $z = [$xmin - $dx, $xmax + $dx];
2935 }
2936 17 ▶ $im_ranges->{$xax} //= [undef, undef];
Condition50%1/2
$im_ranges->{$xax} //= [undef, undef]
l!l
017
MC/DC0%0/1
$im_ranges->{$xax} //= [undef, undef]
$im_ranges->{$xax}
Truth table50%1/2
A
A= $im_ranges->{$xax}
Aresult
11
00
2937 17 ▶ $im_ranges->{$xax}[0] = $z->[0] if( !defined( $im_ranges->{$xax}[0] ) or $z->[0] < $im_ranges->{$xax}[0] );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $im_ranges->{$xax}[0] or $z->[0] < $im_ranges->{$xax}[0] 17 0 17
Condition33%1/3
not defined $im_ranges->{$xax}[0] or $z->[0] < $im_ranges->{$xax}[0]
l!l&&r!l&&!r
1700
MC/DC0%0/2
not defined $im_ranges->{$xax}[0] or $z->[0] < $im_ranges->{$xax}[0]
not defined $im_ranges->{$xax}[0] $z->[0] < $im_ranges->{$xax}[0]
Truth table33%1/3
not(A) or B
A= not defined $im_ranges->{$xax}[0]B= $z->[0] < $im_ranges->{$xax}[0]
ABresult
1X1
011
000
2938 17 ▶ $im_ranges->{$xax}[1] = $z->[1] if( !defined( $im_ranges->{$xax}[1] ) or $z->[1] > $im_ranges->{$xax}[1] );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $im_ranges->{$xax}[1] or $z->[1] > $im_ranges->{$xax}[1] 17 0 17
Condition33%1/3
not defined $im_ranges->{$xax}[1] or $z->[1] > $im_ranges->{$xax}[1]
l!l&&r!l&&!r
1700
MC/DC0%0/2
not defined $im_ranges->{$xax}[1] or $z->[1] > $im_ranges->{$xax}[1]
not defined $im_ranges->{$xax}[1] $z->[1] > $im_ranges->{$xax}[1]
Truth table33%1/3
not(A) or B
A= not defined $im_ranges->{$xax}[1]B= $z->[1] > $im_ranges->{$xax}[1]
ABresult
1X1
011
000
2939 17 ▶ if($chunks->[$i]->{ArrayRec} eq 'array') {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunks->[$i]{'ArrayRec'} eq 'array') { } 5 12 17
2940 5 $z= [ -0.5, $chunks->[$i]{data}[0]->dim(2) - 0.5 ];
2941 } else {
2942 12 my ($ymin,$ymax) = $chunks->[$i]{data}[0]->slice("(1)")->minmax;
2943 12 my($dy) = ($ymax-$ymin) / $chunks->[$i]{data}[0]->dim(2) * 0.5;
2944 12 $z = [$ymin - $dy, $ymax + $dy];
2945 }
2946 17 ▶ $im_ranges->{$yax} //= [undef, undef];
Condition50%1/2
$im_ranges->{$yax} //= [undef, undef]
l!l
017
MC/DC0%0/1
$im_ranges->{$yax} //= [undef, undef]
$im_ranges->{$yax}
Truth table50%1/2
A
A= $im_ranges->{$yax}
Aresult
11
00
2947 17 ▶ $im_ranges->{$yax}[0] = $z->[0] if( !defined( $im_ranges->{$yax}[0] ) or $z->[0] < $im_ranges->{$yax}[0] );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $im_ranges->{$yax}[0] or $z->[0] < $im_ranges->{$yax}[0] 17 0 17
Condition33%1/3
not defined $im_ranges->{$yax}[0] or $z->[0] < $im_ranges->{$yax}[0]
l!l&&r!l&&!r
1700
MC/DC0%0/2
not defined $im_ranges->{$yax}[0] or $z->[0] < $im_ranges->{$yax}[0]
not defined $im_ranges->{$yax}[0] $z->[0] < $im_ranges->{$yax}[0]
Truth table33%1/3
not(A) or B
A= not defined $im_ranges->{$yax}[0]B= $z->[0] < $im_ranges->{$yax}[0]
ABresult
1X1
011
000
2948 17 ▶ $im_ranges->{$yax}[1] = $z->[1] if( !defined( $im_ranges->{$yax}[1] ) or $z->[1] > $im_ranges->{$yax}[1] );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $im_ranges->{$yax}[1] or $z->[1] > $im_ranges->{$yax}[1] 17 0 17
Condition33%1/3
not defined $im_ranges->{$yax}[1] or $z->[1] > $im_ranges->{$yax}[1]
l!l&&r!l&&!r
1700
MC/DC0%0/2
not defined $im_ranges->{$yax}[1] or $z->[1] > $im_ranges->{$yax}[1]
not defined $im_ranges->{$yax}[1] $z->[1] > $im_ranges->{$yax}[1]
Truth table33%1/3
not(A) or B
A= not defined $im_ranges->{$yax}[1]B= $z->[1] > $im_ranges->{$yax}[1]
ABresult
1X1
011
000
2949 }
2950 ##############################
2951 # If image xrange/yrange has been set, check it against the maximum extent of other types of
2952 # data. If other types of data exceed the image xrange/yrange, then delete the corresponding
2953 # element of image xrange/yrange, to allow gnuplot to autoscale.
2954 # This is complicated (of course) by the fact that the user can omit the ordinate - so we have
2955 # to detect the missing-ordinate case and use the dimension instead.
2956 #
2957 # We don't actually keep the non-image range limits, since we want to fall back to gnuplot's
2958 # axis estimator in the case where a non-image curve is setting the size of the axis.
2959 85 ▶ if ( 0 + (keys %$im_ranges) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 + keys(%$im_ranges)) 17 68 85
2960 17 my $ranges = {};
2961 17 for my $i (grep !$chunks->[$_]{imgFlag}, 0..$#$chunks) {
2962 1 my ($cxr, $cyr);
2963 1 ▶ if($chunks->[$i]{ArrayRec} eq 'array') {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunks->[$i]{'ArrayRec'} eq 'array') { } 1 0 1
2964 1 my $data = $chunks->[$i]{data};
2965 1 ▶ if ( $chunks->[$i]{cdims}==2 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($chunks->[$i]{'cdims'} == 2) { } 0 1 1
elsif ($chunks->[$i]{'cdims'} == 1) { } 1 0 1
2966 0 $cxr = [0, $data->[0]->dim(1)];
2967 0 $cyr = [0, $data->[1]->dim(2)];
2968 } elsif ( $chunks->[$i]->{cdims}==1 ) {
2969 1 $cxr = [0, $data->[0]->dim(0)];
2970 1 $cyr = [$data->[0]->minmax];
2971 } else {
2972 0 carp "WARNING: Found an 'impossible' case in autoranging. Your plot is probably OK.\n\tplease file a bug report for PDL::Graphics::Gnuplot version $VERSION\n";
2973 0 next;
2974 }
2975 } else {
2976 0 $cxr = [ PDL->topdl($chunks->[$i]{data}[0])->minmax ];
2977 0 $cyr = [ PDL->topdl($chunks->[$i]{data}[1])->minmax ];
2978 }
2979 1 my ($xax,$yax) = @{$axes_by_chunkno[$i]}[0,1];
2980 1 ▶ $ranges->{$xax} //= [undef,undef];
Condition50%1/2
$ranges->{$xax} //= [undef, undef]
l!l
01
MC/DC0%0/1
$ranges->{$xax} //= [undef, undef]
$ranges->{$xax}
Truth table50%1/2
A
A= $ranges->{$xax}
Aresult
11
00
2981 1 ▶ $ranges->{$xax}[0] = $cxr->[0] if( !defined( $ranges->{$xax}[0] ) or $cxr->[0] < $ranges->{$xax}[0]);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $ranges->{$xax}[0] or $cxr->[0] < $ranges->{$xax}[0] 1 0 1
Condition33%1/3
not defined $ranges->{$xax}[0] or $cxr->[0] < $ranges->{$xax}[0]
l!l&&r!l&&!r
100
MC/DC0%0/2
not defined $ranges->{$xax}[0] or $cxr->[0] < $ranges->{$xax}[0]
not defined $ranges->{$xax}[0] $cxr->[0] < $ranges->{$xax}[0]
Truth table33%1/3
not(A) or B
A= not defined $ranges->{$xax}[0]B= $cxr->[0] < $ranges->{$xax}[0]
ABresult
1X1
011
000
2982 1 ▶ $ranges->{$xax}[1] = $cxr->[1] if( !defined( $ranges->{$xax}[1] ) or $cxr->[1] > $ranges->{$xax}[1]);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $ranges->{$xax}[1] or $cxr->[1] > $ranges->{$xax}[1] 1 0 1
Condition33%1/3
not defined $ranges->{$xax}[1] or $cxr->[1] > $ranges->{$xax}[1]
l!l&&r!l&&!r
100
MC/DC0%0/2
not defined $ranges->{$xax}[1] or $cxr->[1] > $ranges->{$xax}[1]
not defined $ranges->{$xax}[1] $cxr->[1] > $ranges->{$xax}[1]
Truth table33%1/3
not(A) or B
A= not defined $ranges->{$xax}[1]B= $cxr->[1] > $ranges->{$xax}[1]
ABresult
1X1
011
000
2983 1 ▶ $ranges->{$yax} //= [undef,undef];
Condition50%1/2
$ranges->{$yax} //= [undef, undef]
l!l
01
MC/DC0%0/1
$ranges->{$yax} //= [undef, undef]
$ranges->{$yax}
Truth table50%1/2
A
A= $ranges->{$yax}
Aresult
11
00
2984 1 ▶ $ranges->{$yax}[0] = $cyr->[0] if( !defined( $ranges->{$yax}[0] ) or $cyr->[0] < $ranges->{$yax}[0]);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $ranges->{$yax}[0] or $cyr->[0] < $ranges->{$yax}[0] 1 0 1
Condition33%1/3
not defined $ranges->{$yax}[0] or $cyr->[0] < $ranges->{$yax}[0]
l!l&&r!l&&!r
100
MC/DC0%0/2
not defined $ranges->{$yax}[0] or $cyr->[0] < $ranges->{$yax}[0]
not defined $ranges->{$yax}[0] $cyr->[0] < $ranges->{$yax}[0]
Truth table33%1/3
not(A) or B
A= not defined $ranges->{$yax}[0]B= $cyr->[0] < $ranges->{$yax}[0]
ABresult
1X1
011
000
2985 1 ▶ $ranges->{$yax}[1] = $cyr->[1] if( !defined( $ranges->{$yax}[1] ) or $cyr->[1] > $ranges->{$yax}[1]);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $ranges->{$yax}[1] or $cyr->[1] > $ranges->{$yax}[1] 1 0 1
Condition33%1/3
not defined $ranges->{$yax}[1] or $cyr->[1] > $ranges->{$yax}[1]
l!l&&r!l&&!r
100
MC/DC0%0/2
not defined $ranges->{$yax}[1] or $cyr->[1] > $ranges->{$yax}[1]
not defined $ranges->{$yax}[1] $cyr->[1] > $ranges->{$yax}[1]
Truth table33%1/3
not(A) or B
A= not defined $ranges->{$yax}[1]B= $cyr->[1] > $ranges->{$yax}[1]
ABresult
1X1
011
000
2986 }
2987 # Having accumulated the max/min values for non-image plots on this axis,
2988 # if one of them goes past the image, then void the im_range for that axis
2989 # in that direction (to allow gnuplot to autoscale that axis in that direction).
2990 17 for my $ax (grep defined($ranges->{$_}), keys %$im_ranges) {
2991 $im_ranges->{$ax}[0] = undef if defined($im_ranges->{$ax}[0]) and
2992 defined($ranges->{$ax}[0]) and
2993 2 ▶ $ranges->{$ax}[0] < $im_ranges->{$ax}[0];
Branch: 1 branch
BranchTrueFalseTotal
if defined $im_ranges->{$ax}[0] and defined $ranges->{$ax}[0] and $ranges->{$ax}[0] < $im_ranges->{$ax}[0] 0 2 2
Condition33%2/6
defined $im_ranges->{$ax}[0] and defined $ranges->{$ax}[0] and $ranges->{$ax}[0] < $im_ranges->{$ax}[0]
!ll&&!rl&&r
020
defined $im_ranges->{$ax}[0] and defined $ranges->{$ax}[0]
!ll&&!rl&&r
002
MC/DC0%0/3
defined $im_ranges->{$ax}[0] and defined $ranges->{$ax}[0] and $ranges->{$ax}[0] < $im_ranges->{$ax}[0]
defined $im_ranges->{$ax}[0] defined $ranges->{$ax}[0] $ranges->{$ax}[0] < $im_ranges->{$ax}[0]
Truth table25%1/4
A and B and C
A= defined $im_ranges->{$ax}[0]B= defined $ranges->{$ax}[0]C= $ranges->{$ax}[0] < $im_ranges->{$ax}[0]
ABCresult
0XX0
10X0
1100
1111
2994 $im_ranges->{$ax}[1] = undef if defined($im_ranges->{$ax}[1]) and
2995 defined($ranges->{$ax}[1]) and
2996 2 ▶ $ranges->{$ax}[1] > $im_ranges->{$ax}[1];
Branch: 1 branch
BranchTrueFalseTotal
if defined $im_ranges->{$ax}[1] and defined $ranges->{$ax}[1] and $ranges->{$ax}[1] > $im_ranges->{$ax}[1] 1 1 2
Condition50%3/6
defined $im_ranges->{$ax}[1] and defined $ranges->{$ax}[1] and $ranges->{$ax}[1] > $im_ranges->{$ax}[1]
!ll&&!rl&&r
011
defined $im_ranges->{$ax}[1] and defined $ranges->{$ax}[1]
!ll&&!rl&&r
002
MC/DC33%1/3
defined $im_ranges->{$ax}[1] and defined $ranges->{$ax}[1] and $ranges->{$ax}[1] > $im_ranges->{$ax}[1]
defined $im_ranges->{$ax}[1] defined $ranges->{$ax}[1] $ranges->{$ax}[1] > $im_ranges->{$ax}[1]
Truth table50%2/4
A and B and C
A= defined $im_ranges->{$ax}[1]B= defined $ranges->{$ax}[1]C= $ranges->{$ax}[1] > $im_ranges->{$ax}[1]
ABCresult
0XX0
10X0
1100
1111
2997 }
2998 }
2999 ##############################
3000 # Fix up cbrange if necessary.
3001 85 ▶ if( defined($cbmin) or defined($cbmax) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cbmin or defined $cbmax) 17 68 85
Condition66%2/3
defined $cbmin or defined $cbmax
l!l&&r!l&&!r
17068
MC/DC50%1/2
defined $cbmin or defined $cbmax
defined $cbmin defined $cbmax
Truth table66%2/3
A or B
A= defined $cbminB= defined $cbmax
ABresult
1X1
011
000
3002 17 ▶ $cbmin = undef if(defined($cbmin) and "$cbmin" =~ m/nan/i);
Branch: 1 branch
BranchTrueFalseTotal
if defined $cbmin and "$cbmin" =~ /nan/i 0 17 17
Condition33%1/3
defined $cbmin and "$cbmin" =~ /nan/i
!ll&&!rl&&r
0170
MC/DC0%0/2
defined $cbmin and "$cbmin" =~ /nan/i
defined $cbmin "$cbmin" =~ /nan/i
Truth table33%1/3
A and B
A= defined $cbminB= "$cbmin" =~ /nan/i
ABresult
0X0
100
111
3003 17 ▶ $cbmax = undef if(defined($cbmax) and "$cbmax" =~ m/nan/i);
Branch: 1 branch
BranchTrueFalseTotal
if defined $cbmax and "$cbmax" =~ /nan/i 0 17 17
Condition33%1/3
defined $cbmax and "$cbmax" =~ /nan/i
!ll&&!rl&&r
0170
MC/DC0%0/2
defined $cbmax and "$cbmax" =~ /nan/i
defined $cbmax "$cbmax" =~ /nan/i
Truth table33%1/3
A and B
A= defined $cbmaxB= "$cbmax" =~ /nan/i
ABresult
0X0
100
111
3004 17 ▶ if($cbmin==$cbmax) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cbmin == $cbmax) 0 17 17
3005 0 $cbmin -= 0.1;
3006 0 $cbmax += 0.1;
3007 }
3008 17 $this->{tmp_options}{cbrange} = [$cbmin, $cbmax];
3009 }
3010 ##############################
3011 # Now reconcile all of the <axis>range stuff for the plot itself,
3012 # and set it as a temporary plot option.
3013 #
3014 # Remember, the purpose of this whole shenanigan is to fix up image ranging.
3015 # Axes whose values are set by option only or by non-image curves only are just fine.
3016 # (Maybe it would have been better to just submit a gnuplot patch...)
3017 85 for my $k (keys %$im_ranges) {
3018 34 my $rkey = $k."range";
3019 # Calculate the widest-range merge of any supplied plot options and curve options
3020 # for this axis.
3021 34 ▶ my $po_range = $this->{options}{$rkey} // [undef,undef];
Condition100%2/2
$this->{"options"}{$rkey} // [undef, undef]
l!l
133
MC/DC100%1/1
$this->{"options"}{$rkey} // [undef, undef]
$this->{"options"}{$rkey}
Truth table100%2/2
A
A= $this->{"options"}{$rkey}
Aresult
11
00
3022 34 ▶ if( defined( $chunks->[0]->{options}{$rkey} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $chunks->[0]{"options"}{$rkey}) 0 34 34
3023 0 my $z = $chunks->[0]->{options}{$rkey};
3024 0 ▶ $po_range->[0] = $z->[0] if( !defined($po_range->[0]) or (defined($z->[0]) and $z->[0] < $po_range->[0]) );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $po_range->[0] or defined $z->[0] and $z->[0] < $po_range->[0] 0 0 0
Condition0%0/6
not defined $po_range->[0] or defined $z->[0] and $z->[0] < $po_range->[0]
l!l&&r!l&&!r
000
defined $z->[0] and $z->[0] < $po_range->[0]
!ll&&!rl&&r
000
MC/DC0%0/3
not defined $po_range->[0] or defined $z->[0] and $z->[0] < $po_range->[0]
not defined $po_range->[0] defined $z->[0] $z->[0] < $po_range->[0]
Truth table0%0/4
not(A) or B and C
A= not defined $po_range->[0]B= defined $z->[0]C= $z->[0] < $po_range->[0]
ABCresult
1XX1
0111
00X0
0100
3025 0 ▶ $po_range->[1] = $z->[1] if( !defined($po_range->[1]) or (defined($z->[1]) and $z->[1] > $po_range->[1]) );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $po_range->[1] or defined $z->[1] and $z->[1] > $po_range->[1] 0 0 0
Condition0%0/6
not defined $po_range->[1] or defined $z->[1] and $z->[1] > $po_range->[1]
l!l&&r!l&&!r
000
defined $z->[1] and $z->[1] > $po_range->[1]
!ll&&!rl&&r
000
MC/DC0%0/3
not defined $po_range->[1] or defined $z->[1] and $z->[1] > $po_range->[1]
not defined $po_range->[1] defined $z->[1] $z->[1] > $po_range->[1]
Truth table0%0/4
not(A) or B and C
A= not defined $po_range->[1]B= defined $z->[1]C= $z->[1] > $po_range->[1]
ABCresult
1XX1
0111
00X0
0100
3026 }
3027 # If an image range exists for this axis, use it for any default (undef) values.
3028 34 ▶ $po_range->[0] //= $im_ranges->{$k}[0];
Condition66%2/3
$po_range->[0] //= $im_ranges->{$k}[0]
l!l&&r!l&&!r
1330
MC/DC0%0/2
$po_range->[0] //= $im_ranges->{$k}[0]
$po_range->[0] $im_ranges->{$k}[0]
Truth table66%2/3
A //= B
A= $po_range->[0]B= $im_ranges->{$k}[0]
ABresult
1X1
011
000
3029 34 ▶ $po_range->[1] //= $im_ranges->{$k}[1];
Condition100%3/3
$po_range->[1] //= $im_ranges->{$k}[1]
l!l&&r!l&&!r
1321
MC/DC100%2/2
$po_range->[1] //= $im_ranges->{$k}[1]
$po_range->[1] $im_ranges->{$k}[1]
Truth table100%3/3
A //= B
A= $po_range->[1]B= $im_ranges->{$k}[1]
ABresult
1X1
011
000
3030 # Now we have a merged range value whose limits come from supplied options or existing image "curve"s.
3031 # Normal curves are not represented and appear as undef, allowing gnuplot to pix the axis range.
3032 # Create a temporary option representing this.
3033 34 $this->{tmp_options}{$rkey} = $po_range;
3034 }
3035 ##############################
3036 # If we're working with time data, and timefmt isn't set, then default it to '%s'.
3037 $this->{options}{timefmt} = '%s'
3038 if !defined($this->{options}{timefmt}) and
3039 85 ▶ grep +($this->{options}{$_."data"} // "") =~ m/^time/i, qw/x x2 y y2 z cb/;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $this->{"options"}{"timefmt"} and grep((($this->{"options"}{$_ . 'data'} // "") =~ /^time/i), ("x", "x2", "y", "y2", "z", "cb")) 3 82 85
Condition80%4/5
not defined $this->{"options"}{"timefmt"} and grep((($this->{"options"}{$_ . 'data'} // "") =~ /^time/i), ("x", "x2", "y", "y2", "z", "cb"))
!ll&&!rl&&r
0823
$this->{"options"}{$_ . 'data'} // ""
l!l
3507
MC/DC50%1/2
not defined $this->{"options"}{"timefmt"} and grep((($this->{"options"}{$_ . 'data'} // "") =~ /^time/i), ("x", "x2", "y", "y2", "z", "cb"))
not defined $this->{"options"}{"timefmt"} grep((($this->{"options"}{$_ . 'data'} // "") =~ /^time/i), ("x", "x2", "y", "y2", "z", "cb"))
MC/DC100%1/1
$this->{"options"}{$_ . 'data'} // ""
$this->{"options"}{$_ . 'data'}
Truth table66%2/3
not(A) and B
A= not defined $this->{"options"}{"timefmt"}B= grep((($this->{"options"}{$_ . 'data'} // "") =~ /^time/i), ("x", "x2", "y", "y2", "z", "cb"))
ABresult
0X0
100
111
Truth table100%2/2
A
A= $this->{"options"}{$_ . 'data'}
Aresult
11
00
3040 ##############################
3041 # Now deal with x2/y2 ticks. By default they don't get turned on (blech). So if they are
3042 # active, we turn them on with default values -- and also turn off mirroring for the x/y ticks.
3043 # (all by default -- if the user sets those options then keep those)
3044 85 for my $ax(qw/x y/) {
3045 170 my $ax2 = $ax.'2';
3046 170 my $axtics = $ax.'tics';
3047 170 my $ax2tics = $ax2.'tics';
3048 170 ▶ if($active_axes->{$ax2}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($active_axes->{$ax2}) 0 170 170
3049 # Turn on the axis2 tick marks
3050 0 ▶ unless ( exists($this->{options}{$ax2tics} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $this->{"options"}{$ax2tics}) 0 0 0
3051 0 $this->{tmp_options}{$ax2tics} = ' ';
3052 }
3053 # Turn off the axis1 mirror marks by default.
3054 # Do this with a 'topcmds' command since it will be overridden
3055 # by whatever comes below (and axis1 ticks are on by default anyway,
3056 # so if the user doesn't want them he will have turned them off).
3057 0 ▶ my $tc = $this->{options}->{topcmds} // "";
Condition0%0/2
$this->{"options"}{"topcmds"} // ""
l!l
00
MC/DC0%0/1
$this->{"options"}{"topcmds"} // ""
$this->{"options"}{"topcmds"}
Truth table0%0/2
A
A= $this->{"options"}{"topcmds"}
Aresult
11
00
3058 0 $tc .= "\nset $axtics nomirror\n";
3059 0 $this->{options}->{topcmds} = $tc;
3060 }
3061 }
3062 ##########
3063 # Merge in any temporary options that have been set by the argument parsing.
3064 # (e.g. prefrobnicators can set plot options via $this->{tmp_options}). This is OK since
3065 # we've already localized $this->{options}.
3066 85 ▶ if (my $t_o = $this->{tmp_options}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $t_o = $this->{"tmp_options"}) 85 0 85
3067 85 @{$this->{options}}{keys %$t_o} = values %$t_o;
3068 }
3069 ##########
3070 # Emit the plot options lines that go above the plot command. We do this
3071 # twice -- once for the main plot command and once for the syntax test.
3072 85 my $plotOptionsString = "";
3073 85 ▶ if($this->{options}->{multiplot}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'options'}{'multiplot'}) { } 4 81 85
3074 # In multiplot we can't issue a "reset", because that would end the multiplot.
3075 # This should take care of the major view stuff, but state might leak in here!
3076 4 $plotOptionsString .= <<'POS';
3077 set size noratio
3078 set view noequal
3079 set view 60,30,1.0,1.0
3080 unset label
3081 unset xlabel
3082 unset ylabel
3083 unset cblabel
3084 unset xrange
3085 unset yrange
3086 unset link x2
3087 unset link y2
3088 POS
3089 4 ▶ $plotOptionsString .= <<'POS' if $gp_numversion >= 5.002;
Branch: 1 branch
BranchTrueFalseTotal
if $PDL::Graphics::Gnuplot::gp_numversion >= "5.002" 4 0 4
3090 unset nonlinear x
3091 unset nonlinear y
3092 unset nonlinear x2
3093 unset nonlinear y2
3094 POS
3095 } else {
3096 # In single-plot mode, just issue a reset. Multiple newlines to work around a gnuplot problem.
3097 81 $plotOptionsString .= "reset\n\n\n";
3098 }
3099 85 $plotOptionsString .= _emitOpts($this->{options}, $pOpt);
3100 ##########
3101 # Generate the plot command with the fences in it instead of data specifiers.
3102 # (The fences are emitted in _emitOpts and contained in the global $cmdFence)
3103 my $plotcmd = ($this->{options}{'3d'} ? "splot " : "plot ") .
3104 85 ▶ join ", ", map _emitOpts($chunks->[$_]{options}, $cOpt, $this),
Branch: 1 branch
BranchTrueFalseTotal
$this->{'options'}{'3d'} ? : 13 72 85
3105 0..$#$chunks;
3106 ##########
3107 # Break up the plot command so we can insert data specifiers in each location
3108 85 my @plotcmds = split /$cmdFence/, $plotcmd;
3109 85 ▶ barf "This should never happen, but it did. That's odd. I give up."
Branch: 1 branch
BranchTrueFalseTotal
if @plotcmds != @$chunks + 1 0 85 85
3110 if @plotcmds != @$chunks+1;
3111 ##########
3112 # Rebuild the plot command by inserting the format string and data spec for each piece,
3113 # instead of the placeholder fence strings.
3114 #
3115 # Image-style formats use binary matrix format rather than ordinary binary format and must
3116 # be handled slightly differently.
3117 #
3118 85 $plotcmd = my $fl = shift @plotcmds;
3119 85 ▶ my $testcmd = $check_syntax ? $fl : undef;
Branch: 1 branch
BranchTrueFalseTotal
$PDL::Graphics::Gnuplot::check_syntax ? : 0 85 85
3120 85 for my $i (0..$#plotcmds) {
3121 92 my ($pchunk, $tchunk);
3122 92 ▶ if ( $chunks->[$i]{cdims} == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunks->[$i]{'cdims'} == 2) { } 17 75 92
3123 # It's an image -- always use binary to push the image out.
3124 # The map statement ensures the main and test cmd get identical sprintf templates.
3125 17 my $fstr = "%double" x $chunks->[$i]{tuplesize};
3126 ($pchunk, $tchunk) = map
3127 sprintf(' "-" binary %s=(%s) format="%s" %s',
3128 $chunks->[$i]{ArrayRec},
3129 $_,
3130 $fstr,
3131 $plotcmds[$i]),
3132 join(",", ($chunks->[$i]{data}[0]->slice("(0)")->dims)),
3133 17 ▶ $check_syntax ? join(",", (("1") x ($chunks->[$i]{data}[0]->ndims - 1))) : ();
Branch: 1 branch
BranchTrueFalseTotal
$PDL::Graphics::Gnuplot::check_syntax ? : 0 17 17
3134 # Mock up test data - just a single data point for each (8 is the size of an IEEE double)
3135 17 ▶ $chunks->[$i]{testdata} = "." x ($chunks->[$i]->{tuplesize} * 8) if $check_syntax;
Branch: 1 branch
BranchTrueFalseTotal
if $PDL::Graphics::Gnuplot::check_syntax 0 17 17
3136 } else {
3137 # It's a non-image plot. Calculate whether binary or ASCII output.
3138 # First, check the per-chunk flag (if set). If it's not, then
3139 # use the global flag.
3140 75 ▶ if( $chunks->[$i]{binaryCurveFlag} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunks->[$i]{'binaryCurveFlag'}) { } 53 22 75
3141 53 my $fstr = "%double" x $chunks->[$i]{tuplesize};
3142 53 my $first = $chunks->[$i]{data}[0];
3143 # The specifiers are identical, except that one gets a length of 1 and the other gets
3144 # the correct length. The map statement ensures the main and test cmd get identical
3145 # sprintf templates.
3146 ($pchunk, $tchunk) = map
3147 sprintf(" '-' binary %s=(%d) format=\"%s\" %s",
3148 $chunks->[$i]{ArrayRec},
3149 $_,
3150 $fstr,
3151 $plotcmds[$i]),
3152 53 ▶ (ref($first) eq 'ARRAY') ? 0+@{$first} : $first->dim(0), $check_syntax ? 1 : ();
Branch: 2 branches
BranchTrueFalseTotal
ref $first eq 'ARRAY' ? : 5 48 53
$PDL::Graphics::Gnuplot::check_syntax ? : 0 53 53
3153 # test data is a string containing the data to send -- just garbage. Use '.' to aid
3154 # byte counting in the test string.
3155 53 ▶ $chunks->[$i]{testdata} = $testdataunit_binary x ($chunks->[$i]{tuplesize}) if $check_syntax;
Branch: 1 branch
BranchTrueFalseTotal
if $PDL::Graphics::Gnuplot::check_syntax 0 53 53
3156 } else {
3157 # ASCII transfer has been specified - plot command is easier, but the data are in ASCII.
3158 22 $pchunk = " \$PGG_data_$i ".$plotcmds[$i];
3159 22 ▶ $tchunk = $pchunk if $check_syntax;
Branch: 1 branch
BranchTrueFalseTotal
if $PDL::Graphics::Gnuplot::check_syntax 0 22 22
3160 22 ▶ $chunks->[$i]{testdata} = " 1 " x ($chunks->[$i]{tuplesize}) . "\ne\n" if $check_syntax;
Branch: 1 branch
BranchTrueFalseTotal
if $PDL::Graphics::Gnuplot::check_syntax 0 22 22
3161 }
3162 }
3163 92 $plotcmd .= $pchunk;
3164 92 ▶ $testcmd .= $tchunk if $check_syntax;
Branch: 1 branch
BranchTrueFalseTotal
if $PDL::Graphics::Gnuplot::check_syntax 0 92 92
3165 }
3166 85 $plotcmd .= "\n";
3167 85 our $last_testcmd;
3168 85 ▶ if ($check_syntax) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PDL::Graphics::Gnuplot::check_syntax) 0 85 85
3169 0 my $postTestplotCheckpoint = 'xxxxxxx Plot succeeded xxxxxxx';
3170 0 my $print_checkpoint = "; print \"$postTestplotCheckpoint\"";
3171 0 $testcmd .= "$print_checkpoint\n";
3172 ##########
3173 # Put data and final checkpointing on the test command
3174 0 $testcmd .= join("", map $_->{testdata}, @$chunks);
3175 # Stash this plot command in the debugging variable
3176 0 $this->{last_testcmd} = $last_testcmd = $plotOptionsString.$testcmd;
3177 #######
3178 # The commands are assembled. Now test 'em by sending the test command down the pipe.
3179 0 _printGnuplotPipe( $this, "syntax", $plotOptionsString.$testcmd );
3180 0 my $checkpointMessage = _checkpoint($this,"syntax");
3181 0 ▶ if(defined $checkpointMessage && $checkpointMessage !~ /^$postTestplotCheckpoint/m)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $checkpointMessage and not $checkpointMessage =~ /^$postTestplotCheckpoint/m) 0 0 0
Condition0%0/3
defined $checkpointMessage and not $checkpointMessage =~ /^$postTestplotCheckpoint/m
!ll&&!rl&&r
000
MC/DC0%0/2
defined $checkpointMessage and not $checkpointMessage =~ /^$postTestplotCheckpoint/m
defined $checkpointMessage not $checkpointMessage =~ /^$postTestplotCheckpoint/m
Truth table0%0/3
A and not(B)
A= defined $checkpointMessageB= not $checkpointMessage =~ /^$postTestplotCheckpoint/m
ABresult
0X0
100
111
3182 {
3183 0 $checkpointMessage =~ s/$print_checkpoint//;
3184 0 barf "Gnuplot error: \"$checkpointMessage\" while syntax-checking the plot cmd \"$testcmd\"";
3185 }
3186 }
3187 ##############################
3188 ##### Send the PlotOptionsString
3189 85 my @plot_chunks = [$plotOptionsString];
3190 85 my @plotshow_chunks = $plotOptionsString;
3191 ##############################
3192 ##### Finally..... send the actual plot command to the gnuplot device.
3193 85 ▶ print "plot command is:\n$plotcmd\n" if $PDL::Graphics::Gnuplot::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $PDL::Graphics::Gnuplot::DEBUG 0 85 85
3194 85 push @plot_chunks, [$plotcmd];
3195 85 push @plotshow_chunks, $plotcmd;
3196 85 my $chunk_i = 0;
3197 85 for my $chunk (@$chunks) {
3198 # Gnuplot doesn't handle bad values, but it *does* know to
3199 # omit nans. If we're running under a PDL that uses the
3200 # bad value handling stuff, replace bad values with nan in the current chunk.
3201 92 ▶ if ($PDL::Bad::Status) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PDL::Bad::Status) 92 0 92
3202 92 for my $n (0..$#{$chunk->{data}}) {
3203 141 my $dp = $chunk->{data}[$n];
3204 141 ▶ next if(ref($dp) eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if ref $dp eq "ARRAY" 16 125 141
3205 125 ▶ if ($dp->badflag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dp->badflag) 0 125 125
3206 0 $dp = $chunk->{data}[$n] = $dp + pdl(0.0); # force copy and convert to floating point
3207 0 $dp->where($dp->isbad) .= asin(pdl(1.1)); # NaN
3208 }
3209 }
3210 }
3211 92 ▶ if ($chunk->{cdims}==2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($chunk->{'cdims'} == 2) { } 17 75 92
elsif ($chunk->{'binaryCurveFlag'}) { } 53 22 75
3212 # Currently all images are sent binary
3213 17 my $p = $chunk->{data}[0]->double->sever;
3214 17 push @plot_chunks, [${$p->get_dataref}, {binary => 1, data => 1 }];
3215 17 push @plotshow_chunks, " [ ".length(${$p->get_dataref})." bytes of binary image data ]\n";
3216 } elsif ($chunk->{binaryCurveFlag}) {
3217 # Send in binary if the binary flag is set.
3218 53 my $p = pdl(@{$chunk->{data}})->mv(-1,0)->double->sever;
3219 53 push @plot_chunks, [${$p->get_dataref}, {binary => 1, data => 1 }];
3220 53 push @plotshow_chunks, " [ ".length(${$p->get_dataref})." bytes of binary data ]\n";
3221 } else {
3222 # Assemble and dump the ASCII
3223 22 ▶ if ($chunk->{data}[0]->$_isa('PDL')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunk->{'data'}[0]->$PDL::Graphics::Gnuplot::_isa('PDL')) { } 20 2 22
3224 # It's a collection of PDL data only.
3225 20 my $p = pdl(@{$chunk->{data}})->slice(":,:"); # ensure at least 2 dims
3226 20 $p = $p->mv(-1,0); # tuple dim first, rows second
3227 20 splice @plotshow_chunks, 1, 0, "\$PGG_data_$chunk_i << [ ".$p->dim(1)." lines of ASCII data ]\n";
3228 # Create a set of ASCII lines. If any of the elements of a given row are NaN or BAD, blank that line.
3229 20 ▶ my $outbuf = join("\n", map $_->isfinite->all ? join(" ", $_->list) : "", $p->dog) . "\n";
Branch: 1 branch
BranchTrueFalseTotal
$_->isfinite->all ? : 10139 1 10140
3230 20 splice @plot_chunks, 1, 0, _emit_ascii($this, $chunk_i, $outbuf);
3231 } else {
3232 # It's a collection of array ref data only. Assemble strings.
3233 2 my $data = $chunk->{data};
3234 2 my $last = $#{$data->[0]};
3235 2 my $s = "";
3236 2 for my $i (0..$last) {
3237 6 for my $j (0..$#$data) {
3238 13 my $elem = $data->[$j][$i];
3239 13 ▶ if ($elem =~ m/[\s\"]/) { # element contains whitespace or quotes
Branch: 1 branch
BranchTrueFalseTotal
if ($elem =~ /[\s\"]/) 0 13 13
3240 0 $elem =~ s/\"/\\\"/g; # Escape quotes
3241 0 $elem =~ s/[\n\r]/ /g; # Remove any newlines or returns
3242 0 $elem = "\"$elem\""; # quote the element
3243 }
3244 13 $s .= "$elem "; # append the element to the output string.
3245 }
3246 6 $s .= "\n"; # add newline
3247 }
3248 2 splice @plotshow_chunks, 1, 0, "\$PGG_data_$chunk_i << e\n${s}e\n";
3249 2 splice @plot_chunks, 1, 0, _emit_ascii($this, $chunk_i, $s);
3250 }
3251 }
3252 92 $chunk_i++;
3253 }
3254 ##############################
3255 # Finally, finally ... send any required cleanup commands. This
3256 # starts with {bottomcmds} and includes several things we don't want to persist,
3257 # but that do by default.
3258 85 my $bc = $this->{options}{bottomcmds};
3259 85 ▶ my $cleanup_cmd = !defined $bc ? "" :
Branch: 2 branches
BranchTrueFalseTotal
!defined($bc) ? : 84 1 85
ref $bc ne 'ARRAY' ? : 0 1 1
3260 ref($bc) ne 'ARRAY' ? "$bc\n" : join("\n", @$bc, "");
3261 # Mark the gnuplot as replottable - we now have a full set of plot parameters stashed away.
3262 85 $this->{replottable} = 1;
3263 85 ▶ if ($check_syntax) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PDL::Graphics::Gnuplot::check_syntax) 0 85 85
3264 0 _printGnuplotPipe($this, "syntax", $cleanup_cmd);
3265 0 $_ .= $cleanup_cmd for $this->{last_testcmd}, $last_testcmd;
3266 0 my $checkpointMessage = _checkpoint($this, "syntax", {printwarnings=>1});
3267 0 ▶ barf "Gnuplot error: \"$checkpointMessage\" after syntax-checking cleanup cmd \"$cleanup_cmd\"\n"
Branch: 1 branch
BranchTrueFalseTotal
if $checkpointMessage 0 0 0
3268 if $checkpointMessage;
3269 }
3270 85 push @plot_chunks, [$cleanup_cmd];
3271 85 push @plotshow_chunks, $cleanup_cmd;
3272 # Flag the output as rescalable if anti-aliasing is in effect
3273 85 ▶ $this->{aa_ready} = 1 if $this->{aa} && $this->{aa} != 1;
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"aa"} and $this->{"aa"} != 1 0 85 85
Condition33%1/3
$this->{"aa"} and $this->{"aa"} != 1
!ll&&!rl&&r
0850
MC/DC0%0/2
$this->{"aa"} and $this->{"aa"} != 1
$this->{"aa"} $this->{"aa"} != 1
Truth table33%1/3
A and B
A= $this->{"aa"}B= $this->{"aa"} != 1
ABresult
0X0
100
111
3274 85 (\@plot_chunks, join('', @plotshow_chunks));
3275 }
3276  
3277 3 *gplot = \&plot;
3278 sub plot
3279 101 ▶{
Subroutine plot: called CC=14 SCAR=38.8
Pod documented
3280 101 ▶ barf "Plot called with no arguments" unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 101 101
3281 101 my $this = _obj_or_global(\@_);
3282 101 my ($plotchunks, $plotshow) = $this->_plot_generate(@_);
3283 84 _printGnuplotPipe($this, "main", @{shift @$plotchunks}); # options
3284 84 my $optionsWarnings = _checkpoint($this, "main", {printwarnings=>1});
3285 # Mask out some common useless chatter
3286 82 $optionsWarnings =~ s/^Terminal type set to .*$//m;
3287 82 $optionsWarnings =~ s/^Options are \'.*$//m;
3288 82 ▶ $optionsWarnings = '' if($optionsWarnings =~ m/^\s+$/s);
Branch: 1 branch
BranchTrueFalseTotal
if $optionsWarnings =~ /^\s+$/s 0 82 82
3289 82 ▶ if ($optionsWarnings) {
Branch: 1 branch
BranchTrueFalseTotal
if ($optionsWarnings) 0 82 82
3290 0 ▶ if ($MS_io_braindamage) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PDL::Graphics::Gnuplot::MS_io_braindamage) { } 0 0 0
3291 # MS Windows can yield some chatter on the line, and it's not necessarily an
3292 # error. So we don't barf, we only warn. Blech.
3293 0 carp "WARNING: the gnuplot process gave some unexpected chatter during plot setup:\n$optionsWarnings\n\n";
3294 } else {
3295 # Used to barf here, but now we just issue an announcement, since
3296 # some messages are warnings (rather than errors).
3297 0 carp "WARNING: the gnuplot process gave some unexpected chatter:\n$optionsWarnings\n\n";
3298 }
3299 }
3300 82 my $cleanup_chunk = pop @$plotchunks;
3301 82 for my $data_chunk (@$plotchunks) {
3302 171 ▶ if (ref $data_chunk eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data_chunk eq 'ARRAY') { } 171 0 171
3303 171 _printGnuplotPipe($this, "main", @$data_chunk);
3304 } else {
3305 0 _printGnuplotPipe($this, "main", @$$data_chunk);
3306 0 my $pipe = $this->{"err-main"};
3307 0 my $byte;
3308 0 while (1) {
3309 0 sysread $pipe, $byte, 1;
3310 0 ▶ last if $byte eq \004 or $byte eq \000 or $byte eq '>';
Branch: 1 branch
BranchTrueFalseTotal
if $byte eq \4 or $byte eq \0 or $byte eq ">" 0 0 0
Condition0%0/6
$byte eq \4 or $byte eq \0 or $byte eq ">"
l!l&&r!l&&!r
000
$byte eq \4 or $byte eq \0
l!l&&r!l&&!r
000
MC/DC0%0/3
$byte eq \4 or $byte eq \0 or $byte eq ">"
$byte eq \4 $byte eq \0 $byte eq ">"
Truth table0%0/4
A or B or C
A= $byte eq \4B= $byte eq \0C= $byte eq ">"
ABCresult
1XX1
01X1
0011
0000
3311 };
3312 }
3313 }
3314 82 my $plotWarnings = _checkpoint($this, "main", {printwarnings=>1});
3315 82 ▶ if ($plotWarnings) {
Branch: 1 branch
BranchTrueFalseTotal
if ($plotWarnings) 0 82 82
3316 0 ▶ barf("the gnuplot process returned an error during plotting: $plotWarnings\n\n")
Branch: 1 branch
BranchTrueFalseTotal
unless $PDL::Graphics::Gnuplot::MS_io_braindamage 0 0 0
3317 if !$MS_io_braindamage;
3318 # MS Windows can yield some chatter on the line, and it's not necessarily an
3319 # error. So we don't barf, we only warn. Blech.
3320 0 carp "WARNING: the gnuplot process gave some unexpected chatter:\n$plotWarnings\n\n";
3321 }
3322 82 _printGnuplotPipe($this, "main", @$cleanup_chunk);
3323 82 ▶ if (my $checkpointMessage = _checkpoint($this, "main", {printwarnings=>1})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $checkpointMessage = _checkpoint($this, "main", {"printwarnings", 1})) 0 82 82
3324 0 ▶ barf "Gnuplot error: \"$checkpointMessage\" after sending cleanup cmd \"$cleanup_chunk->[0]\"\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $PDL::Graphics::Gnuplot::MS_io_braindamage 0 0 0
3325 if !$MS_io_braindamage;
3326 # MS Windows can yield some chatter on the line, and it's not necessarily an
3327 # error. So we don't barf, we only warn. Blech.
3328 0 carp "WARNING: the gnuplot process gave some unexpected chatter after plot cleanup:\n$checkpointMessage\n";
3329 }
3330 82 $this->{last_plotcmd} = our $last_plotcmd = $plotshow;
3331 # read and report any warnings that happened during the plot
3332 82 return $plotWarnings;
3333 }
3334  
3335 # Not in binary mode - send this chunk in ASCII. Each line gets one
3336 # tuple, followed a line with just "e".
3337 22 ▶sub _emit_ascii {
Subroutine _emit_ascii: called CC=4 SCAR=23.2
3338 22 my ($this, $chunk_i, $chunk) = @_;
3339 # Under real OSes, we can just send a schwack of stuff - there is no echo.
3340 22 ▶ return ["\$PGG_data_$chunk_i << e\n${chunk}e\n", {data => 1}]
Branch: 1 branch
BranchTrueFalseTotal
unless $PDL::Graphics::Gnuplot::MS_io_braindamage 22 0 22
3341 if !$MS_io_braindamage;
3342 0 ▶ my $pipe_stuff = !$this->{dumping} && $echo_eating;
Condition0%0/3
!$this->{'dumping'} && $PDL::Graphics::Gnuplot::echo_eating
!ll&&!rl&&r
000
MC/DC0%0/2
!$this->{'dumping'} && $PDL::Graphics::Gnuplot::echo_eating
!$this->{'dumping'} $PDL::Graphics::Gnuplot::echo_eating
Truth table0%0/3
not(A) && B
A= !$this->{'dumping'}B= $PDL::Graphics::Gnuplot::echo_eating
ABresult
0X0
100
111
3343 0 ▶ ((map $pipe_stuff ? \$_ : $_, map ["$_\n", {data => 1}], "\$PGG_data_$chunk_i <<e", split /\n/, $chunk), ["e\n", {data => 1 }]);
Branch: 1 branch
BranchTrueFalseTotal
$pipe_stuff ? : 0 0 0
3344 }
3345  
3346 #####################
3347 #
3348 # parseArgs - helper sub nested inside plot
3349 #
3350 # This breaks out the parsing of the curve arguments.
3351 #
3352 # Each chunk of data to plot appears in the argument list as
3353 # plot(options, options, ..., data, data, ....).
3354 # The options are a hashref or an inline hash and also serve as delimiters between
3355 # chunks of data.
3356 #
3357 # Curve options, with the exception of "legend", are accumulated - each set
3358 # is used as the default value of the same option for the next one.
3359 #
3360 # The data arguments are one-argument-per-tuple-element, but higher
3361 # dims can be used for threading. Plot elements that are to be treated
3362 # as 1-D (non-image) data can be threaded over -- so, e.g., you can pass in
3363 # a 50 PDL (as X) and a 50x3 PDL (as Y) and you'll get three separate plots with
3364 # the same options. As a special case, you can pass an array ref into the
3365 # "legend" or "color" options in that case, and thereby specify a different legend/color
3366 # for each of those threaded plots.
3367 #
3368 sub parseArgs
3369 102 ▶{
Subroutine parseArgs: called CC=84 SCAR=47.0
Pod undocumented
3370 102 my $this = shift;
3371 ##############################
3372 # Parse curve option / data chunks.
3373 102 my @args = @_;
3374 102 ▶ my $is3d = $this->{options}{'3d'} // 0;
Condition100%2/2
$this->{"options"}{"3d"} // 0
l!l
1983
MC/DC100%1/1
$this->{"options"}{"3d"} // 0
$this->{"options"}{"3d"}
Truth table100%2/2
A
A= $this->{"options"}{"3d"}
Aresult
11
00
3375 102 my $ND = (('2D','3D')[!!$is3d]); # mainly for error messages
3376 102 my $spec_legends = 0;
3377 # options were once cumulative. The 'with' specifier is still kept, but most
3378 # of that functionality is not present as of 2.003.
3379 # We keep the lastOptions accumulator around just in case it comes in handy for
3380 # a little more context.
3381 102 my $lastOptions = {};
3382 102 my @chunks;
3383 102 my $Ncurves = 0;
3384 102 my $argIndex = 0;
3385 102 ▶ while($argIndex <= $#args)
Branch: 1 branch
BranchTrueFalseTotal
if ($argIndex <= $#args) 105 85 190
3386 {
3387 # First, I find and parse the options in this chunk
3388 # Array refs are allowed in some curve options, but only as values of key/value
3389 # pairs -- so any array refs glommed in with a bunch of other refs are data.
3390 105 my $nextDataIdx = $argIndex;
3391 105 while (1) {
3392 179 ▶ $nextDataIdx = undef, last if $nextDataIdx > $#args;
Branch: 1 branch
BranchTrueFalseTotal
if $nextDataIdx > $#args 0 179 179
3393 179 ▶ $nextDataIdx += 2, next if !ref $args[$nextDataIdx]; # a key
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args[$nextDataIdx] 59 120 179
3394 120 ▶ last if ref $args[$nextDataIdx] ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $args[$nextDataIdx] ne "HASH" 105 15 120
3395 15 $nextDataIdx++;
3396 }
3397 105 ▶ last if !defined $nextDataIdx; # no more data. done.
Branch: 1 branch
BranchTrueFalseTotal
unless defined $nextDataIdx 0 105 105
3398 105 my $lastWith = {};
3399 105 ▶ $lastWith->{with} = $lastOptions->{with} if($lastOptions->{with});
Branch: 1 branch
BranchTrueFalseTotal
if $lastOptions->{"with"} 0 105 105
3400 105 my %chunk;
3401 105 eval {
3402 105 $chunk{options} = dclone(
3403 _parseOptHash( $lastWith, $cOpt, @args[$argIndex..$nextDataIdx-1] )
3404 );
3405 ### As of Gnuplot 5.0, some curve options (dashtype) require a default value to maintain legacy
3406 ### behavior in the default case. This is the place where curve options are parsed, so we
3407 ### hand-tweak a couple of default values here.
3408 # dashtype doesn't have to have a defined value it only has to exist in the curve options hash,
3409 # to trigger emission of a dashtype.
3410 103 ▶ $chunk{options}{dashtype} = undef unless(defined($chunk{options}{dashtype}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $chunk{"options"}{"dashtype"} 103 0 103
3411 ## Even worse -- some plot types (notably "with labels") barf in newer gnuplots
3412 ## if you feed them a "dt". So don't send a dashtype to those.
3413 my $with = (
3414 ( ref($chunk{options}{with}) =~ m/ARRAY/ ) ?
3415 $chunk{options}{with}[0] :
3416 $chunk{options}{with}
3417 ) //
3418 $this->{options}{globalwith} //
3419 103 ▶ "";
Branch: 1 branch
BranchTrueFalseTotal
ref($chunk{'options'}{'with'}) =~ /ARRAY/ ? : 52 51 103
Condition100%5/5
((ref($chunk{"options"}{"with"}) =~ /ARRAY/ ? $chunk{"options"}{"with"}[0] : $chunk{"options"}{"with"}) // $this->{"options"}{"globalwith"}) // ""
l!l
6043
(ref($chunk{"options"}{"with"}) =~ /ARRAY/ ? $chunk{"options"}{"with"}[0] : $chunk{"options"}{"with"}) // $this->{"options"}{"globalwith"}
l!l&&r!l&&!r
52843
MC/DC100%2/2
((ref($chunk{"options"}{"with"}) =~ /ARRAY/ ? $chunk{"options"}{"with"}[0] : $chunk{"options"}{"with"}) // $this->{"options"}{"globalwith"}) // ""
(ref($chunk{"options"}{"with"}) =~ /ARRAY/ ? $chunk{"options"}{"with"}[0] : $chunk{"options"}{"with"}) $this->{"options"}{"globalwith"}
Truth table100%3/3
A // B
A= (ref($chunk{"options"}{"with"}) =~ /ARRAY/ ? $chunk{"options"}{"with"}[0] : $chunk{"options"}{"with"})B= $this->{"options"}{"globalwith"}
ABresult
1X1
011
000
3420 103 ▶ if($with =~ m/^label/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($with =~ /^label/) 1 102 103
3421 1 $chunk{options}{dashtype} = "INVALID";
3422 }
3423 };
3424 105 ▶ if($@){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 2 103 105
3425 2 ▶ unless(@chunks){
Branch: 1 branch
BranchTrueFalseTotal
unless (@chunks) 2 0 2
3426 2 barf "$@\n(Did you mix plot options and curve options at the beginning of the arg list?)\n\n";
3427 }
3428 0 barf "$@\n";
3429 }
3430 103 $chunk{options}{data}="dummy"; # force emission of the data field
3431 # Find the data for this chunk...
3432 103 $argIndex = $nextDataIdx;
3433 191 ▶ my $nextOptionIdx = first { !(ref $args[$_]) or
Subroutine __ANON__: called CC=3 SCAR=11.1
Condition83%5/6
ref $args[$_] && (ref $args[$_] eq 'ARRAY' || $args[$_]->$PDL::Graphics::Gnuplot::_isa('PDL'))
!ll&&!rl&&r
03188
ref $args[$_] eq "ARRAY" or $args[$_]->$PDL::Graphics::Gnuplot::_isa("PDL")
l!l&&r!l&&!r
171713
MC/DC66%2/3
ref $args[$_] && (ref $args[$_] eq 'ARRAY' || $args[$_]->$PDL::Graphics::Gnuplot::_isa('PDL'))
ref $args[$_] ref $args[$_] eq "ARRAY" $args[$_]->$PDL::Graphics::Gnuplot::_isa("PDL")
Truth table75%3/4
A && B or C
A= ref $args[$_]B= ref $args[$_] eq "ARRAY"C= $args[$_]->$PDL::Graphics::Gnuplot::_isa("PDL")
ABCresult
0XX0
1000
11X1
1011
3434 !( (ref $args[$_]) eq 'ARRAY' or
3435 $args[$_]->$_isa('PDL')
3436 )
3437 103 } $argIndex..$#args;
3438 103 ▶ $nextOptionIdx = @args unless defined $nextOptionIdx;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $nextOptionIdx 100 3 103
3439 # Make sure we know our "with" style...
3440 103 ▶ $chunk{options}{with} ||= $this->{options}{globalwith} // ["lines"];
Condition80%4/5
$chunk{"options"}{"with"} ||= $this->{"options"}{"globalwith"} // ["lines"]
l!l&&r!l&&!r
52510
$this->{"options"}{"globalwith"} // ["lines"]
l!l
843
MC/DC0%0/2
$chunk{"options"}{"with"} ||= $this->{"options"}{"globalwith"} // ["lines"]
$chunk{"options"}{"with"} $this->{"options"}{"globalwith"}
Truth table66%2/3
A ||= B
A= $chunk{"options"}{"with"}B= $this->{"options"}{"globalwith"}
ABresult
1X1
011
000
3441 # validate "with" and get imgFlag and tupleSizes.
3442 # First, unpack the "with" -- we accept a list of with parameters, but also
3443 # unpack them if they are supplied as a single smushed-together string.
3444 103 our $plotStyleProps; # declared below
3445 103 my $with = $chunk{options}{with};
3446 103 ▶ @$with = split /\s+/, $with->[0] if @$with == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @$with == 1 103 0 103
3447 103 ▶ if (@$with > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$with > 1) 0 103 103
3448 carp q{
3449 WARNING: deprecated usage of complex 'with' detected. Use a simple 'with'
3450 specifier and curve options instead. This will fail in future releases of
3451 PDL::Graphics::Gnuplot. (Set $ENV{'PGG_DEP'}=1 to silence this warning.
3452 0 ▶} unless($ENV{'PGG_DEP'});
Branch: 1 branch
BranchTrueFalseTotal
unless $ENV{"PGG_DEP"} 0 0 0
3453 }
3454 # Look for the plotStyleProps entry. If not there, try cleaning up the with style
3455 # before giving up entirely.
3456 103 ▶ unless ( exists $plotStyleProps->{$with->[0]} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $$PDL::Graphics::Gnuplot::plotStyleProps{$with->[0]}) 3 100 103
3457 # Try pluralizing and lc'ing if that works...
3458 3 ▶ if ($with->[0] !~ m/s$/i and exists( $plotStyleProps->{lc $with->[0].'s'} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $with->[0] =~ /s$/i and exists $$PDL::Graphics::Gnuplot::plotStyleProps{lc $with->[0] . 's'}) { } 2 1 3
Condition66%2/3
not $with->[0] =~ /s$/i and exists $$PDL::Graphics::Gnuplot::plotStyleProps{lc $with->[0] . 's'}
!ll&&!rl&&r
102
MC/DC50%1/2
not $with->[0] =~ /s$/i and exists $$PDL::Graphics::Gnuplot::plotStyleProps{lc $with->[0] . 's'}
not $with->[0] =~ /s$/i exists $$PDL::Graphics::Gnuplot::plotStyleProps{lc $with->[0] . 's'}
Truth table66%2/3
not(A) and B
A= not $with->[0] =~ /s$/iB= exists $$PDL::Graphics::Gnuplot::plotStyleProps{lc $with->[0] . 's'}
ABresult
0X0
100
111
3459 2 $with->[0] = lc $with->[0].'s';
3460 } else {
3461 # nope. throw a fit.
3462 1 barf "invalid plotstyle 'with $with->[0]' in plot\n";
3463 }
3464 }
3465 102 my $psProps = $plotStyleProps->{$with->[0]};
3466 # Extract the data objects from the argument list.
3467 # They should all be either PDLs or array refs.
3468 102 my @dataPiddles = @args[$argIndex..$nextOptionIdx-1];
3469 # Some plot styles (currently just "fits") are implemented via a
3470 # prefrobnicator that processes the data.
3471 102 ▶ if( $psProps->[ 4 ] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($psProps->[4]) 6 96 102
3472 6 @dataPiddles = &{ $psProps->[4] }( $with, $this, \%chunk, @dataPiddles );
3473 5 $psProps = $plotStyleProps->{$with->[0]};
3474 }
3475 # Image flag and base tuplesizes allowed for this plot style...
3476 101 my $tupleSizes = $psProps->[ !!$is3d ]; # index is 0 or 1 depending on truth of 3D flag
3477 101 my $imgFlag = $psProps->[ 2 ];
3478 101 $chunk{binaryWith} = $psProps->[ 3 ];
3479 # If the user wanted binary but this style requires ASCII (or vice
3480 # versa) I throw a warning
3481 101 ▶ if ( !$ENV{PGG_SUPPRESS_BINARY_MISMATCH_WARNING} &&
Branch: 1 branch
BranchTrueFalseTotal
if (not $ENV{"PGG_SUPPRESS_BINARY_MISMATCH_WARNING"} and defined $chunk{"binaryWith"}) 13 88 101
Condition66%2/3
not $ENV{"PGG_SUPPRESS_BINARY_MISMATCH_WARNING"} and defined $chunk{"binaryWith"}
!ll&&!rl&&r
08813
MC/DC50%1/2
not $ENV{"PGG_SUPPRESS_BINARY_MISMATCH_WARNING"} and defined $chunk{"binaryWith"}
not $ENV{"PGG_SUPPRESS_BINARY_MISMATCH_WARNING"} defined $chunk{"binaryWith"}
Truth table66%2/3
not(A) and B
A= not $ENV{"PGG_SUPPRESS_BINARY_MISMATCH_WARNING"}B= defined $chunk{"binaryWith"}
ABresult
0X0
100
111
3482 defined $chunk{binaryWith} )
3483 {
3484 # style requires some specific ascii/binary transfer
3485 13 ▶ my $got = $chunk{binaryWith} ? "binary" : "ascii";
Branch: 1 branch
BranchTrueFalseTotal
$chunk{'binaryWith'} ? : 12 1 13
3486 13 ▶ my $asked = $this->{options}{binary} ? "binary" : "ascii";
Branch: 1 branch
BranchTrueFalseTotal
$this->{'options'}{'binary'} ? : 13 0 13
3487 13 ▶ if( $got ne $asked and !($this->{binary_flag_defaulted}))
Branch: 1 branch
BranchTrueFalseTotal
if ($got ne $asked and not $this->{"binary_flag_defaulted"}) 0 13 13
Condition66%2/3
$got ne $asked and not $this->{"binary_flag_defaulted"}
!ll&&!rl&&r
1210
MC/DC0%0/2
$got ne $asked and not $this->{"binary_flag_defaulted"}
$got ne $asked not $this->{"binary_flag_defaulted"}
Truth table66%2/3
A and not(B)
A= $got ne $askedB= not $this->{"binary_flag_defaulted"}
ABresult
0X0
100
111
3488 {
3489 0 carp <<EOF;
3490 PDL::Graphics::Gnuplot warning: user asked for $asked data transfer, but
3491 '$with->[0]' plots are ALWAYS sent in $got. Ignoring '$asked' request.
3492 Set environment variable PGG_SUPPRESS_BINARY_MISMATCH_WARNING to suppress
3493 this warning.
3494 EOF
3495 0 $ENV{PGG_SUPPRESS_BINARY_MISMATCH_WARNING} = 1;
3496 }
3497 }
3498 # Reject disallowed plot styles
3499 101 ▶ unless (ref $tupleSizes) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $tupleSizes) 0 101 101
3500 0 barf "plotstyle 'with $with->[0]' isn't valid in $ND plots\n";
3501 }
3502 # Additional columns are needed for certain 'with' modifiers. Figure 'em, cheesily: each
3503 # palette or variable option to 'with' needs an additional column.
3504 # The search over @$with will disappear with the deprecated compound-with form;
3505 # the real one is the second line that scans through curve options.
3506 101 my $ExtraColumns = grep /(palette|variable)/, @$with;
3507 101 for my $k (qw/linecolor textcolor fillstyle pointsize linewidth fillcolor/ ) {
3508 606 my $v = $chunk{options}{$k};
3509 606 ▶ next unless defined($v);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 600 6 606
3510 6 ▶ my $s = ref $v eq 'ARRAY' ? join(" ",@$v) : $v;
Branch: 1 branch
BranchTrueFalseTotal
ref $v eq 'ARRAY' ? : 0 6 6
3511 6 ▶ $ExtraColumns++ if($s =~ m/palette|variable/);
Branch: 1 branch
BranchTrueFalseTotal
if $s =~ /palette|variable/ 6 0 6
3512 }
3513 101 ▶ $ExtraColumns++ if $chunk{options}{palette};
Branch: 1 branch
BranchTrueFalseTotal
if $chunk{"options"}{"palette"} 3 98 101
3514 ##############################
3515 # Figure out what size of tuple we have, and check it against the tuple sizes we can take...
3516 101 my $NdataPiddles = @dataPiddles;
3517 # Check in case it was explicitly set [not normally needed, but still...]
3518 101 ▶ if ($chunk{options}{tuplesize} and $NdataPiddles != $chunk{options}{tuplesize}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunk{"options"}{"tuplesize"} and $NdataPiddles != $chunk{"options"}{"tuplesize"}) 0 101 101
Condition33%1/3
$chunk{"options"}{"tuplesize"} and $NdataPiddles != $chunk{"options"}{"tuplesize"}
!ll&&!rl&&r
10100
MC/DC0%0/2
$chunk{"options"}{"tuplesize"} and $NdataPiddles != $chunk{"options"}{"tuplesize"}
$chunk{"options"}{"tuplesize"} $NdataPiddles != $chunk{"options"}{"tuplesize"}
Truth table33%1/3
A and B
A= $chunk{"options"}{"tuplesize"}B= $NdataPiddles != $chunk{"options"}{"tuplesize"}
ABresult
0X0
100
111
3519 0 barf "You specified a tuple size of ".($chunk{options}->{tuplesize})." but only $NdataPiddles columns of data\n";
3520 }
3521 101 my @tuplematch = grep abs($_)+$ExtraColumns == $NdataPiddles, @$tupleSizes;
3522 101 ▶ if ( @tuplematch ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tuplematch) { } 93 8 101
3523 # Tuple sizes that require autogenerated dimensions require 'array' in binary mode;
3524 # all others require 'record' in binary mode. Note that in ascii mode it's slightly
3525 # different -- an additional "using" column (or two) is needed (see below).
3526 93 ▶ $chunk{ArrayRec} = ($tuplematch[0] < 0) ? 'array' : 'record';
Branch: 1 branch
BranchTrueFalseTotal
$tuplematch[0] < 0 ? : 42 51 93
3527 } else {
3528 # No match -- barf unless you really meant it
3529 8 ▶ if (!$chunk{options}{tuplesize}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($chunk{"options"}{"tuplesize"}) 8 0 8
3530 8 ▶ my $pl = ($NdataPiddles==1)?"":"s";
Branch: 1 branch
BranchTrueFalseTotal
$NdataPiddles == 1 ? : 0 8 8
3531 8 my $s = "Found $NdataPiddles PDL$pl for $ND plot type 'with $with->[0]', which needs ";
3532 8 ▶ barf "Ouch! I'm never supposed to take this path. Please report a bug."
Branch: 1 branch
BranchTrueFalseTotal
unless @$tupleSizes 0 8 8
3533 if !@$tupleSizes;
3534 8 ▶ if (@$tupleSizes==1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$tupleSizes == 1) { } 0 8 8
3535 0 $s .= abs($tupleSizes->[0]) + $ExtraColumns;
3536 } else {
3537 8 $s .= "one of [".join(",",map abs($_)+$ExtraColumns, @$tupleSizes)."]";
3538 }
3539 8 ▶ if ($ExtraColumns) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ExtraColumns) { } 3 5 8
3540 3 ▶ my $pl = ($ExtraColumns==1)?"":"s";
Branch: 1 branch
BranchTrueFalseTotal
$ExtraColumns == 1 ? : 1 2 3
3541 3 $s .= " (including the $ExtraColumns extra$pl from your 'with' options).\n";
3542 } else {
3543 5 $s .= ".\n";
3544 }
3545 8 barf $s;
3546 }
3547 0 $chunk{ArrayRec} = 'record';
3548 0 carp "WARNING: forced disallowed tuplesize with a curve option...\n";
3549 }
3550 ##############################
3551 # Implicit dimensions in 3-D plots require imgFlag to be set...
3552 my $cdims = $chunk{options}{cdims} ||
3553 93 ▶ ($imgFlag or ( $is3d && $dataPiddles[0]->$_isa('PDL') && $dataPiddles[0]->ndims >= 2 )) ? 2 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$chunk{'options'}{'cdims'} || ($imgFlag || $is3d && $dataPiddles[0]->$PDL::Graphics::Gnuplot::_isa('PDL') && $dataPiddles[0]->ndims >= 2) ? : 17 76 93
Condition100%12/12
$chunk{"options"}{"cdims"} or ($imgFlag or $is3d and $dataPiddles[0]->$PDL::Graphics::Gnuplot::_isa("PDL") and $dataPiddles[0]->ndims >= 2)
l!l&&r!l&&!r
11676
$imgFlag or $is3d and $dataPiddles[0]->$PDL::Graphics::Gnuplot::_isa("PDL") and $dataPiddles[0]->ndims >= 2
l!l&&r!l&&!r
12476
$is3d and $dataPiddles[0]->$PDL::Graphics::Gnuplot::_isa("PDL") and $dataPiddles[0]->ndims >= 2
!ll&&!rl&&r
6974
$is3d and $dataPiddles[0]->$PDL::Graphics::Gnuplot::_isa("PDL")
!ll&&!rl&&r
68111
MC/DC100%5/5
$chunk{"options"}{"cdims"} or ($imgFlag or $is3d and $dataPiddles[0]->$PDL::Graphics::Gnuplot::_isa("PDL") and $dataPiddles[0]->ndims >= 2)
$chunk{"options"}{"cdims"} $imgFlag $is3d $dataPiddles[0]->$PDL::Graphics::Gnuplot::_isa("PDL") $dataPiddles[0]->ndims >= 2
Truth table100%6/6
A or B or C and D and E
A= $chunk{"options"}{"cdims"}B= $imgFlagC= $is3dD= $dataPiddles[0]->$PDL::Graphics::Gnuplot::_isa("PDL")E= $dataPiddles[0]->ndims >= 2
ABCDEresult
1XXXX1
01XXX1
001111
000XX0
0010X0
001100
3554 93 ▶ barf("You specified column dimension of 1 for an image plot type! Not allowed.")
Branch: 1 branch
BranchTrueFalseTotal
if $cdims == 1 and $imgFlag 0 93 93
Condition66%2/3
$cdims == 1 and $imgFlag
!ll&&!rl&&r
17760
MC/DC0%0/2
$cdims == 1 and $imgFlag
$cdims == 1 $imgFlag
Truth table66%2/3
A and B
A= $cdims == 1B= $imgFlag
ABresult
0X0
100
111
3555 if $cdims==1 and $imgFlag;
3556 ##############################
3557 # A little aside: streamline the common optimization cases --
3558 # if the user specified "image" but handed in an RGB or RGBA image,
3559 # bust it up into components and update the 'with' accordingly.
3560 # This happens if RGB or RGBA is in dim 0 or in dim 2.
3561 # The other dimensions have to have at least five elements.
3562 93 ▶ if ( $cdims==2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cdims == 2) 17 76 93
3563 17 ▶ if ($with->[0] eq 'image') {
Branch: 1 branch
BranchTrueFalseTotal
if ($with->[0] eq "image") 12 5 17
3564 12 my $dp = $dataPiddles[-1];
3565 12 ▶ if ($dp->ndims==3 and $dp->dim(1) >= 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dp->ndims == 3 and $dp->dim(1) >= 5) 5 7 12
Condition66%2/3
$dp->ndims == 3 and $dp->dim(1) >= 5
!ll&&!rl&&r
705
MC/DC50%1/2
$dp->ndims == 3 and $dp->dim(1) >= 5
$dp->ndims == 3 $dp->dim(1) >= 5
Truth table66%2/3
A and B
A= $dp->ndims == 3B= $dp->dim(1) >= 5
ABresult
0X0
100
111
3566 5 my ($new_with, @ndarrays) = _regularise_image($dp);
3567 5 $with->[0] = $new_with;
3568 5 splice @dataPiddles, -1, 1, @ndarrays;
3569 }
3570 }
3571 }
3572 93 $chunk{cdims} = $cdims;
3573 93 $chunk{tuplesize} = @dataPiddles;
3574 # Get the threading dims right
3575 93 @dataPiddles = matchDims( @dataPiddles );
3576 ##############################
3577 # Make sure there is a using spec, in case one wasn't given.
3578 # If we have one implicit dim in ASCII, we need a different using spec
3579 # (blech). If we have implicit dims in 3-D, imgFlag is set (see just above),
3580 # and we will be sending the data in binary anyway (see the emission code in plot itself).
3581 90 ▶ unless (exists($chunk{options}{using})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $chunk{"options"}{"using"}) 90 0 90
3582 90 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $this->{'options'}{'binary'} and not $this->{'options'}{'binary'} and not $imgFlag and $chunk{'ArrayRec'} eq 'array') { } 9 81 90
Condition77%7/9
defined $this->{"options"}{"binary"} and not $this->{"options"}{"binary"} and not $imgFlag and $chunk{"ArrayRec"} eq "array"
!ll&&!rl&&r
71109
defined $this->{"options"}{"binary"} and not $this->{"options"}{"binary"} and not $imgFlag
!ll&&!rl&&r
71019
defined $this->{"options"}{"binary"} and not $this->{"options"}{"binary"}
!ll&&!rl&&r
07119
MC/DC50%2/4
defined $this->{"options"}{"binary"} and not $this->{"options"}{"binary"} and not $imgFlag and $chunk{"ArrayRec"} eq "array"
defined $this->{"options"}{"binary"} not $this->{"options"}{"binary"} not $imgFlag $chunk{"ArrayRec"} eq "array"
Truth table60%3/5
A and not(B) and not(C) and D
A= defined $this->{"options"}{"binary"}B= not $this->{"options"}{"binary"}C= not $imgFlagD= $chunk{"ArrayRec"} eq "array"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
3583 defined($this->{options}{binary}) and !$this->{options}{binary} and
3584 !$imgFlag and
3585 $chunk{ArrayRec} eq 'array'
3586 ) {
3587 # ASCII mode, not an image. Add the requisite implicit columns.
3588 9 ▶ if ($is3d) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is3d) { } 2 7 9
3589 # Two implicit columns. The first is column 0, the second is all zeroes since
3590 # we'd have to be sending an image to make it otherwise. We sleaze up the
3591 # y=0 column by multipling column 0 by 0.
3592 2 $chunk{options}{using} = join(":",0,'($0*0)',1..$chunk{tuplesize});
3593 } else {
3594 # one implicit column. It is column 0.
3595 7 $chunk{options}{using} = join(":",0..$chunk{tuplesize});
3596 }
3597 } else {
3598 # Binary mode and/or is an image. Omit the implicit columns since they'll be
3599 # added by gnuplot.
3600 81 $chunk{options}{using} = join(":",1..$chunk{tuplesize});
3601 }
3602 }
3603 # Check number of lines threaded into this tupleset; make sure everything
3604 # is consistent...
3605 90 ▶ barf "Image plot types require at least a 2-D input PDL\n"
Branch: 1 branch
BranchTrueFalseTotal
if $imgFlag and $dataPiddles[0]->dims < 2 0 90 90
Condition66%2/3
$imgFlag and $dataPiddles[0]->dims < 2
!ll&&!rl&&r
78120
MC/DC0%0/2
$imgFlag and $dataPiddles[0]->dims < 2
$imgFlag $dataPiddles[0]->dims < 2
Truth table66%2/3
A and B
A= $imgFlagB= $dataPiddles[0]->dims < 2
ABresult
0X0
100
111
3606 if $imgFlag and $dataPiddles[0]->dims < 2;
3607 # For the image case glom everything together into one 3-dimensional PDL,
3608 # pre-inverted so that the 0 dim runs across column.
3609 90 my $ncurves;
3610 90 ▶ if($cdims==2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cdims == 2) { } 17 73 90
elsif ($dataPiddles[0]->$PDL::Graphics::Gnuplot::_isa('PDL')) { } 66 7 73
3611 # Surfaces never get a label unless one is explicitly set
3612 17 ▶ $chunk{options}{legend} = undef unless exists $chunk{options}{legend};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $chunk{"options"}{"legend"} 17 0 17
3613 17 $spec_legends = 1;
3614 17 my $p = pdl(@dataPiddles);
3615 # Coerce up to 3 dimensions, with (col, ix, iy).
3616 17 ▶ if ($p->dims == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p->dims == 2) { } 5 12 17
3617 5 $p = $p->dummy(0,1);
3618 } else {
3619 12 $p = $p->mv(-1,0);
3620 }
3621 17 ▶ if ( ($p->dims > 3) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p->dims > 3) 0 17 17
3622 0 barf("PDL::Graphics::Gnuplot::plot: I can't make sense of this dimensional mix -- \n I ended up with (".join("x",$p->dims).") data after combining everything. \n (Did you mix list and PDL-stack formulations, or try to thread 2-D columns?)\n");
3623 }
3624 # Place the PDL onto the argument stack.
3625 17 @dataPiddles = ($p);
3626 17 $chunk{tuplesize} = $p->dim(0);
3627 17 $ncurves = 1;
3628 17 $chunk{data} = \@dataPiddles;
3629 17 $chunk{imgFlag} = 1;
3630 17 push @chunks, \%chunk;
3631 } elsif ( $dataPiddles[0]->$_isa('PDL') ) {
3632 # Non-image case: check that the legend count agrees with the
3633 # number of curves we found, and break up compound chunks (with multiple
3634 # curves) into separate chunks of one curve each.
3635 66 $ncurves = $dataPiddles[0]->slice("(0)")->nelem;
3636 # Speed bump for weird case
3637 66 our $bigthreads;
3638 66 ▶ if ($ncurves >= 100 and !$bigthreads) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ncurves >= 100 and not $PDL::Graphics::Gnuplot::bigthreads) 0 66 66
Condition33%1/3
$ncurves >= 100 and not $PDL::Graphics::Gnuplot::bigthreads
!ll&&!rl&&r
6600
MC/DC0%0/2
$ncurves >= 100 and not $PDL::Graphics::Gnuplot::bigthreads
$ncurves >= 100 not $PDL::Graphics::Gnuplot::bigthreads
Truth table33%1/3
A and not(B)
A= $ncurves >= 100B= not $PDL::Graphics::Gnuplot::bigthreads
ABresult
0X0
100
111
3639 0 carp <<"FOO"
3640 PDL::Graphics::Gnuplot: WARNING - you seem to be plotting $ncurves
3641 curves in a single threaded collection. This could be because you fed
3642 in a 2-D (or higher) data set when you meant to plot a single curve.
3643 If so, you may want to flatten your data and try again. (To disable
3644 this message, set \$PDL::Graphics::Gnuplot::bigthreads to be true).
3645 If you are trying to plot a surface, you might try setting 'trid=>1'
3646 in the plot options.
3647 FOO
3648 }
3649 66 ▶ if ($chunk{options}{legend} and
Branch: 1 branch
BranchTrueFalseTotal
if ($chunk{"options"}{"legend"} and @{$chunk{"options"}{"legend"};} and @{$chunk{"options"}{"legend"};} != $ncurves) 2 64 66
Condition83%5/6
$chunk{"options"}{"legend"} and @{$chunk{"options"}{"legend"};} and @{$chunk{"options"}{"legend"};} != $ncurves
!ll&&!rl&&r
6222
$chunk{"options"}{"legend"} and @{$chunk{"options"}{"legend"};}
!ll&&!rl&&r
6204
MC/DC66%2/3
$chunk{"options"}{"legend"} and @{$chunk{"options"}{"legend"};} and @{$chunk{"options"}{"legend"};} != $ncurves
$chunk{"options"}{"legend"} @{$chunk{"options"}{"legend"};} @{$chunk{"options"}{"legend"};} != $ncurves
Truth table75%3/4
A and B and C
A= $chunk{"options"}{"legend"}B= @{$chunk{"options"}{"legend"};}C= @{$chunk{"options"}{"legend"};} != $ncurves
ABCresult
0XX0
10X0
1100
1111
3650 4 @{$chunk{options}{legend}} and
3651 4 @{$chunk{options}{legend}} != $ncurves
3652 ) {
3653 2 ▶ my $ent = (0+@{$chunk{options}{legend}} == 1) ? "y" : "ies";
Branch: 1 branch
BranchTrueFalseTotal
0 + @{$chunk{'options'}{'legend'};} == 1 ? : 1 1 2
3654 2 ▶ my $pl = ($ncurves==1)?"":"s";
Branch: 1 branch
BranchTrueFalseTotal
$ncurves == 1 ? : 1 1 2
3655 2 barf "Legend has ".(0+@{$chunk{options}{legend}})." entr$ent; but ".($ncurves)." curve$pl supplied!";
3656 }
3657 # Ensure legend appears in the options parsing (to emit "notitle" if necessary)
3658 64 ▶ $chunk{options}{legend} = undef unless(exists($chunk{options}{legend}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $chunk{"options"}{"legend"} 62 2 64
3659 64 ▶ $spec_legends = 1 if($chunk{options}{legend});
Branch: 1 branch
BranchTrueFalseTotal
if $chunk{"options"}{"legend"} 2 62 64
3660 64 $chunk{tuplesize} = $NdataPiddles;
3661 64 ▶ if ($ncurves==1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ncurves == 1) { } 63 1 64
3662 # The chunk is OK.
3663 63 $chunk{data} = \@dataPiddles;
3664 63 push @chunks, \%chunk;
3665 } else {
3666 # The chunk needs splitting, options and all.
3667 1 for my $i (0..$ncurves - 1) {
3668 5 my $chk = dclone(\%chunk);
3669 5 $chk->{data} = [ map $_->slice(":,($i)"), @dataPiddles ];
3670 5 ▶ if (exists($chk->{options}{legend})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $chk->{"options"}{"legend"}) 5 0 5
3671 5 $chk->{options}{legend} = [$chk->{options}{legend}[$i]];
3672 }
3673 5 push @chunks, $chk;
3674 }
3675 }
3676 } else {
3677 # Non-image case, with array refs instead of PDLs -- we required the chunk to be
3678 # simple in matchDims, so just push it.
3679 7 $ncurves = 1;
3680 7 $chunk{data} = \@dataPiddles;
3681 7 $chunk{imgFlag} = 0;
3682 # Ensure legend appears in the options parsing (to emit "notitle" if necessary)
3683 7 ▶ $chunk{options}{legend} = undef unless(exists($chunk{options}{legend}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $chunk{"options"}{"legend"} 7 0 7
3684 7 push @chunks, \%chunk;
3685 }
3686 88 $Ncurves += $ncurves;
3687 88 $argIndex = $nextOptionIdx;
3688 }
3689 85 return (\@chunks, $Ncurves);
3690 }
3691  
3692 5 ▶sub _regularise_image {
Subroutine _regularise_image: called CC=13 SCAR=26.7
3693 5 my ($dp) = @_;
3694 5 ▶ my $with = $dp->dim(0) == 3 || $dp->dim(2) == 3 ? 'rgbimage' :
Branch: 2 branches
BranchTrueFalseTotal
$dp->dim(0) == 3 || $dp->dim(2) == 3 ? : 3 2 5
$dp->dim(0) == 4 || $dp->dim(2) == 4 ? : 2 0 2
Condition83%5/6
$dp->dim(0) == 3 or $dp->dim(2) == 3
l!l&&r!l&&!r
122
$dp->dim(0) == 4 or $dp->dim(2) == 4
l!l&&r!l&&!r
110
MC/DC100%2/2
$dp->dim(0) == 3 or $dp->dim(2) == 3
$dp->dim(0) == 3 $dp->dim(2) == 3
MC/DC0%0/2
$dp->dim(0) == 4 or $dp->dim(2) == 4
$dp->dim(0) == 4 $dp->dim(2) == 4
Truth table100%3/3
A or B
A= $dp->dim(0) == 3B= $dp->dim(2) == 3
ABresult
1X1
011
000
Truth table66%2/3
A or B
A= $dp->dim(0) == 4B= $dp->dim(2) == 4
ABresult
1X1
011
000
3695 $dp->dim(0) == 4 || $dp->dim(2) == 4 ? 'rgbalpha' : undef;
3696 5 my @ndarrays;
3697 5 ▶ if ($dp->dim(0) == 3 && $dp->dim(2) >= 5) {
Branch: 4 branches
BranchTrueFalseTotal
if ($dp->dim(0) == 3 and $dp->dim(2) >= 5) { } 1 4 5
elsif ($dp->dim(2) == 3 and $dp->dim(0) >= 5) { } 2 2 4
elsif ($dp->dim(0) == 4 and $dp->dim(2) >= 5) { } 1 1 2
elsif ($dp->dim(2) == 4 and $dp->dim(0) >= 5) { } 1 0 1
Condition66%2/3
$dp->dim(0) == 3 and $dp->dim(2) >= 5
!ll&&!rl&&r
401
MC/DC50%1/2
$dp->dim(0) == 3 and $dp->dim(2) >= 5
$dp->dim(0) == 3 $dp->dim(2) >= 5
Truth table66%2/3
A and B
A= $dp->dim(0) == 3B= $dp->dim(2) >= 5
ABresult
0X0
100
111
3698 1 @ndarrays = $dp->using(0..2);
3699 ▶ } elsif ($dp->dim(2) == 3 && $dp->dim(0) >= 5) {
Condition66%2/3
$dp->dim(2) == 3 and $dp->dim(0) >= 5
!ll&&!rl&&r
202
MC/DC50%1/2
$dp->dim(2) == 3 and $dp->dim(0) >= 5
$dp->dim(2) == 3 $dp->dim(0) >= 5
Truth table66%2/3
A and B
A= $dp->dim(2) == 3B= $dp->dim(0) >= 5
ABresult
0X0
100
111
3700 2 @ndarrays = $dp->mv(2,0)->using(0..2);
3701 ▶ } elsif ($dp->dim(0) == 4 && $dp->dim(2) >= 5) {
Condition66%2/3
$dp->dim(0) == 4 and $dp->dim(2) >= 5
!ll&&!rl&&r
101
MC/DC50%1/2
$dp->dim(0) == 4 and $dp->dim(2) >= 5
$dp->dim(0) == 4 $dp->dim(2) >= 5
Truth table66%2/3
A and B
A= $dp->dim(0) == 4B= $dp->dim(2) >= 5
ABresult
0X0
100
111
3702 1 @ndarrays = $dp->using(0..3);
3703 ▶ } elsif ($dp->dim(2) == 4 && $dp->dim(0) >= 5) {
Condition33%1/3
$dp->dim(2) == 4 and $dp->dim(0) >= 5
!ll&&!rl&&r
001
MC/DC0%0/2
$dp->dim(2) == 4 and $dp->dim(0) >= 5
$dp->dim(2) == 4 $dp->dim(0) >= 5
Truth table33%1/3
A and B
A= $dp->dim(2) == 4B= $dp->dim(0) >= 5
ABresult
0X0
100
111
3704 1 @ndarrays = $dp->mv(2,0)->using(0..3);
3705 }
3706 5 ($with, @ndarrays);
3707 }
3708  
3709 ##########
3710 # matchDims: nested sub inside plot - kludge up thread style matching across
3711 # the data arguments to a given chunk.
3712 sub matchDims
3713 93 ▶{
Subroutine matchDims: called CC=27 SCAR=34.4
Pod undocumented
3714 93 my @data = @_;
3715 93 my $nonPDLCount = 0;
3716 93 ▶ map { $nonPDLCount++ unless( $_->$_isa('PDL') ) } @data;
Branch: 1 branch
BranchTrueFalseTotal
unless $_->$PDL::Graphics::Gnuplot::_isa("PDL") 17 164 181
3717 # In the case where all data are PDLs, we match dimensions.
3718 93 ▶ unless($nonPDLCount) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($nonPDLCount) 83 10 93
3719 # Make sure the domain and ranges describe the same number of data points,
3720 # and that all PDLs have at least one dim.
3721 #
3722 # ( This is complicated by the need/desire to preserve threading rules. Here,
3723 # we accumulate thread dimensions manually and then match 'em using dummy
3724 # dimensions... --CED )
3725 83 my @data_dims = (1); # ensure at least 1 dim with at least 1 element
3726 # Assemble the thread-rules dim list
3727 83 for my $i(0..$#data) {
3728 159 my @ddims = $data[$i]->dims;
3729 159 for my $i(0..$#ddims) {
3730 213 ▶ if( (!defined($data_dims[$i])) || ($data_dims[$i] <= 1) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $data_dims[$i] or $data_dims[$i] <= 1) { } 102 111 213
elsif ($ddims[$i] > 1 and $ddims[$i] != $data_dims[$i]) { } 0 111 111
Condition100%3/3
not defined $data_dims[$i] or $data_dims[$i] <= 1
l!l&&r!l&&!r
1983111
MC/DC100%2/2
not defined $data_dims[$i] or $data_dims[$i] <= 1
not defined $data_dims[$i] $data_dims[$i] <= 1
Truth table100%3/3
not(A) or B
A= not defined $data_dims[$i]B= $data_dims[$i] <= 1
ABresult
1X1
011
000
3731 102 $data_dims[$i] = $ddims[$i];
3732 }
3733 ▶ elsif( ( $ddims[$i]>1) && ($ddims[$i] != $data_dims[$i] )) {
Condition33%1/3
$ddims[$i] > 1 and $ddims[$i] != $data_dims[$i]
!ll&&!rl&&r
01110
MC/DC0%0/2
$ddims[$i] > 1 and $ddims[$i] != $data_dims[$i]
$ddims[$i] > 1 $ddims[$i] != $data_dims[$i]
Truth table33%1/3
A and B
A= $ddims[$i] > 1B= $ddims[$i] != $data_dims[$i]
ABresult
0X0
100
111
3734 0 barf "plot(): mismatched arguments in tuple; dims of data item $i=(@ddims), but data_dims=(@data_dims)";
3735 }
3736 }
3737 }
3738 # Now pad each data element out, by slicing, to match the full dim list. If the
3739 # dim matches, mark a ':'; if not, put in the correct dummy dim to make it match.
3740 # Don't bother slicing unless at least one dummy dim is needed.
3741 83 for my $i(0..$#data) {
3742 159 my @ddims = $data[$i]->dims;
3743 159 my @s = ();
3744 159 my $slice_needed = 0;
3745 159 for my $id(0..$#data_dims) {
3746 214 ▶ if((!defined($ddims[$id])) || !$ddims[$id]) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $ddims[$id] && $ddims[$id]) { } 1 213 214
elsif ($data_dims[$id] == $ddims[$id]) { } 213 0 213
elsif ($ddims[$id] == 1) { } 0 0 0
Condition66%2/3
defined $ddims[$id] && $ddims[$id]
!ll&&!rl&&r
10213
MC/DC50%1/2
defined $ddims[$id] && $ddims[$id]
defined $ddims[$id] $ddims[$id]
Truth table66%2/3
A && B
A= defined $ddims[$id]B= $ddims[$id]
ABresult
0X0
100
111
3747 1 push(@s,"*$data_dims[$id]");
3748 1 $slice_needed = 1;
3749 }
3750 elsif($data_dims[$id] == $ddims[$id]) {
3751 213 push(@s,":");
3752 }
3753 elsif( $ddims[$id]==1 ) {
3754 0 push(@s,"(0), *$data_dims[$id]");
3755 0 $slice_needed = 1;
3756 } else {
3757 # should never happen
3758 0 barf "plot(): problem with dim assignments. This is a bug."; # no newline
3759 }
3760 }
3761 159 ▶ if($slice_needed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($slice_needed) 1 158 159
3762 1 my $s = join(",",@s);
3763 1 $data[$i] = $data[$i]->slice( join(",",@s) );
3764 }
3765 }
3766 83 return @data;
3767 }
3768 # At least one of the data columns is a non-PDL. Force them to be simple columns, and
3769 # require exact dimensional match.
3770 #
3771 # Also, convert any contained PDLs to array refs.
3772 10 my $nelem;
3773 10 my @out = ();
3774 10 for(@data) {
3775 20 ▶ barf "plot(): only 1-D PDLs are allowed to be mixed with array ref data\n"
Branch: 1 branch
BranchTrueFalseTotal
if $_->$PDL::Graphics::Gnuplot::_isa("PDL") and $_->ndims > 1 2 18 20
Condition100%3/3
$_->$PDL::Graphics::Gnuplot::_isa("PDL") and $_->ndims > 1
!ll&&!rl&&r
1532
MC/DC100%2/2
$_->$PDL::Graphics::Gnuplot::_isa("PDL") and $_->ndims > 1
$_->$PDL::Graphics::Gnuplot::_isa("PDL") $_->ndims > 1
Truth table100%3/3
A and B
A= $_->$PDL::Graphics::Gnuplot::_isa("PDL")B= $_->ndims > 1
ABresult
0X0
100
111
3776 if( $_->$_isa('PDL') and $_->ndims > 1 );
3777 18 ▶ if((ref $_) eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_ eq 'ARRAY') { } 15 3 18
elsif ($_->$PDL::Graphics::Gnuplot::_isa('PDL')) { } 3 0 3
3778 15 ▶ barf "plot(): row count mismatch: ".(0+@$_)." != $nelem\n"
Branch: 1 branch
BranchTrueFalseTotal
if defined $nelem and @$_ != $nelem 1 14 15
Condition100%3/3
defined $nelem and @$_ != $nelem
!ll&&!rl&&r
681
MC/DC100%2/2
defined $nelem and @$_ != $nelem
defined $nelem @$_ != $nelem
Truth table100%3/3
A and B
A= defined $nelemB= @$_ != $nelem
ABresult
0X0
100
111
3779 if( (defined $nelem) and (@$_ != $nelem) );
3780 14 $nelem = @$_;
3781 14 for (@$_) {
3782 64 ▶ barf "plot(): nested references not allowed in list data\n"
Branch: 1 branch
BranchTrueFalseTotal
if ref $_ 0 64 64
3783 if( ref($_) );
3784 }
3785 14 push(@out, $_);
3786 } elsif( $_->$_isa('PDL') ) {
3787 3 ▶ barf "plot(): nelem disagrees with row count: ".$_->nelem." != $nelem\n"
Branch: 1 branch
BranchTrueFalseTotal
if defined $nelem and $_->nelem != $nelem 0 3 3
Condition66%2/3
defined $nelem and $_->nelem != $nelem
!ll&&!rl&&r
210
MC/DC0%0/2
defined $nelem and $_->nelem != $nelem
defined $nelem $_->nelem != $nelem
Truth table66%2/3
A and B
A= defined $nelemB= $_->nelem != $nelem
ABresult
0X0
100
111
3788 if( (defined $nelem) and ($_->nelem != $nelem) );
3789 3 $nelem = $_->nelem;
3790 3 push(@out, [ $_->list ]);
3791 } else {
3792 0 barf "plot(): problem with dim checking. This should never happen.";
3793 }
3794 }
3795 7 return @out;
3796 } # end of matchDims (nested in plot)
3797  
3798 ######################################################################
3799 ######################################################################
3800 #
3801 # convenience wrappers for plot
3802 #
3803 ##############################
3804  
3805 =pod
3806  
3807 =head2 replot
3808  
3809 =for ref
3810  
3811 Replot the last plot (possibly with new arguments).
3812  
3813 C<replot> is similar to gnuplot's "replot" command - it allows you to
3814 regenerate the last plot made with this object. You can change the
3815 plot by adding new elements to it, modifying options, or even (with the
3816 "device" method) changing the output device. C<replot> takes the same
3817 arguments as C<plot>.
3818  
3819 If you give no arguments at all (or only a plot object) then the plot
3820 is simply redrawn. If you give plot arguments, they are added to the
3821 new plot exactly as if you'd included them in the original plot
3822 element list, and maintained for subsequent replots.
3823  
3824 (Compare to 'markup').
3825  
3826 =cut
3827  
3828 3 ▶sub replot {
Subroutine replot: called CC=2 SCAR=7.4
Pod documented
3829 3 my $this = _obj_or_global(\@_);
3830 3 ▶ if($this->{replottable}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'replottable'}) { } 3 0 3
3831 3 local($this->{replotting}) = 1;
3832 3 $this->plot(@_);
3833 } else {
3834 0 die "PDL::Graphics::Gnuplot::replot: you must have already plotted something!\n";
3835 }
3836 }
3837  
3838 =pod
3839  
3840 =head2 markup
3841  
3842 =for ref
3843  
3844 Add ephemeral markup to the last plot.
3845  
3846 C<markup> works exactly the same as C<replot>, except that any
3847 new arguments are not added to the replot list - so you can
3848 add temporary markup to a plot and regenerate the plot later
3849 without it.
3850  
3851 =cut
3852  
3853 0 ▶sub markup {
Subroutine markup: not called CC=2 SCAR=17.9
Pod documented
3854 0 my $this = _obj_or_global(\@_);
3855 0 ▶ if($this->{replottable}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'replottable'}) { } 0 0 0
3856 0 local($this->{replotting}) = 1;
3857 0 local($this->{ephemeral}) = 1;
3858 0 $this->plot(@_);
3859 } else {
3860 0 die "PDL::Graphics::Gnuplot::markup: you must have already plotted something!\n";
3861 }
3862 }
3863  
3864 =pod
3865  
3866 =head2 plot3d
3867  
3868 =for ref
3869  
3870 Generate 3D plots. Synonym for C<plot(trid =E<gt> 1, ...)>
3871  
3872 =cut
3873  
3874 =pod
3875  
3876 =head2 splot
3877  
3878 =for ref
3879  
3880 Generate 3D plots. Synonym for C<plot(trid =E<gt> 1, ...)>
3881  
3882 =cut
3883  
3884 3 *splot = \&plot3d;
3885 9 ▶sub plot3d {
Subroutine plot3d: called CC=1 SCAR=0.0
Pod documented
3886 9 my $this = _obj_or_global(\@_);
3887 9 local($this->{options}{'3d'}) = 1;
3888 9 plot($this,@_);
3889 }
3890  
3891 =pod
3892  
3893 =head2 lines
3894  
3895 =for ref
3896  
3897 Generates plots with lines, by default. Shorthand for C<plot(globalwith =E<gt> 'lines', ...)>
3898  
3899 =cut
3900  
3901 3 *line = \&lines;
3902 8 ▶sub lines {
Subroutine lines: called CC=1 SCAR=0.0
Pod documented
3903 8 my $this = _obj_or_global(\@_);
3904 8 local($this->{options}{globalwith}) = ['lines'];
3905 8 plot($this,@_);
3906 }
3907  
3908 =pod
3909  
3910 =head2 points
3911  
3912 =for ref
3913  
3914 Generates plots with points, by default. Shorthand for C<plot(globalwith =E<gt> 'points', ...)>
3915  
3916 =cut
3917  
3918 0 ▶sub points {
Subroutine points: not called CC=1 SCAR=6.9
Pod documented
3919 0 my $this = _obj_or_global(\@_);
3920 0 local($this->{options}{globalwith}) = ['points'];
3921 0 plot($this,@_);
3922 }
3923  
3924 =pod
3925  
3926 =head2 image
3927  
3928 =for ref
3929  
3930 Displays an image (either greyscale or RGB). Shorthand for C<plot(globalwith =E<gt> 'image', ...)>
3931  
3932 =cut
3933  
3934  
3935 0 ▶sub image {
Subroutine image: not called CC=1 SCAR=6.9
Pod documented
3936 0 my $this = _obj_or_global(\@_);
3937 0 local($this->{options}{globalwith}) = ["image"];
3938 0 plot($this, @_);
3939 }
3940  
3941 =pod
3942  
3943 =head2 imag
3944  
3945 =for ref
3946  
3947 Synonym for "image", for people who grew up with PDL::Graphics::PGPLOT and can't remember the closing 'e'
3948  
3949 =cut
3950  
3951 3 *imag = \&image;
3952  
3953 =pod
3954  
3955 =head2 fits
3956  
3957 =for ref
3958  
3959 Displays a FITS image. Synonym for C<plot(globalwith =E<gt> 'fits', ...)>.
3960  
3961 =cut
3962  
3963 0 ▶sub fits {
Subroutine fits: not called CC=1 SCAR=6.9
Pod documented
3964 0 my $this = _obj_or_global(\@_);
3965 0 local($this->{options}{globalwith}) = ["fits"];
3966 0 plot($this,@_);
3967 }
3968  
3969 ##############################
3970 # Multiplot support
3971  
3972 =pod
3973  
3974 =head2 multiplot_generate
3975  
3976 =for ref
3977  
3978 Called with the same arguments as L</multiplot>, it returns the text that
3979 would be sent to Gnuplot.
3980 Added in 2.025.
3981  
3982 =head2 multiplot
3983  
3984 =for example
3985  
3986 $a = (xvals(101)/100) * 6 * 3.14159/180;
3987 $b = sin($a);
3988  
3989 $w->multiplot(layout=>[2,2,"columnsfirst"]);
3990 $w->plot({title=>"points"},with=>"points",$a,$b);
3991 $w->plot({title=>"lines"}, with=>"lines", $a,$b);
3992 $w->multiplot_next; # with Gnuplot 4.7+
3993 $w->plot({title=>"image"}, with=>"image", $a->(*1) * $b );
3994 $w->end_multi();
3995  
3996 =for ref
3997  
3998 Plot multiple plots into a single page of output.
3999  
4000 The C<multiplot> method enables multiplot mode in gnuplot, which permits
4001 multiple plots on a single pane. Plots can be lain out in a grid,
4002 or can be lain out freeform using the C<size> and C<origin> plot
4003 options for each of the individual plots.
4004  
4005 It is not possible to change the terminal or output device when in
4006 multiplot mode; if you try to do that, by setting one of those plot
4007 options, PDL::Graphics::Gnuplot will throw an error.
4008  
4009 The options hash will accept:
4010  
4011 =over 3
4012  
4013 =item layout - define a regular grid of plots to multiplot
4014  
4015 C<layout> should be followed by an ARRAY ref that contains at least
4016 number of columns ("NX") followed by number of rows ("NY). After
4017 that, you may include any of the "rowsfirst", "columnsfirst",
4018 "downwards", or "upwards" keywords to specify traversal order through
4019 the grid. Only the first letter is examined, so (e.g.) "down" or even
4020 "dog" works the same as "downwards".
4021  
4022 =item title - define a title for the entire page
4023  
4024 C<title> should be followed by a single scalar containing the title string.
4025  
4026 =item scale - make gridded plots larger or smaller than their allocated space
4027  
4028 C<scale> takes either a scalar or an array ref containing one or two
4029 values. If only one value is supplied, it is a general scale factor
4030 of each plot in the grid. If two values are supplied, the first is an
4031 X stretch factor for each plot in the grid, and the second is a Y
4032 stretch factor for each plot in the grid.
4033  
4034 =item offset - offset each plot from its grid origin
4035  
4036 C<offset> takes an array ref containing two values, that control placement
4037 of each plot within the grid.
4038  
4039 =back
4040  
4041 =head2 multiplot_next_generate
4042  
4043 =for ref
4044  
4045 Called with the same arguments as L</multiplot_next>, it returns the text that
4046 would be sent to Gnuplot. Exportable.
4047 Added in 2.025.
4048  
4049 =head2 multiplot_next
4050  
4051 =for ref
4052  
4053 Skip one plot. Added in 2.025. Requires Gnuplot 4.7+.
4054  
4055 =head2 end_multi_generate
4056  
4057 =for ref
4058  
4059 Called with the same arguments as L</end_multi>, it returns the text that
4060 would be sent to Gnuplot. Exportable.
4061 Added in 2.025.
4062  
4063 =head2 end_multi
4064  
4065 =for usage
4066  
4067 $w=gpwin();
4068 $w->multiplot(layout=>[2,1]);
4069 $w->plot({title=>"points"},with=>'points',$a,$b);
4070 $w->plot({title=>"lines"},with=>"lines",$a,$b);
4071 $w->end_multi();
4072  
4073 =for ref
4074  
4075 Ends a multiplot block (i.e. a block of plots that are meant to render to a single page).
4076  
4077 =cut
4078  
4079  
4080 # This table describes gnuplot option parsing for the multiplot command.
4081 # Its format is the same as the $plotOptionsTable, below.
4082  
4083 our $mpOptionsTable = {
4084 4 ▶ 'layout' => [sub { my($old, $new, $h) = @_;
Subroutine __ANON__: called CC=10 SCAR=33.7
4085 4 my ($nx,$ny);
4086 4 my @dirs=("","");
4087 4 ▶ if(!ref($new)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $new) { } 0 4 4
elsif (ref $new eq 'ARRAY') { } 4 0 4
4088 0 $nx = $ny = $new;
4089 } elsif(ref($new) eq 'ARRAY') {
4090 4 ▶ $new = [1] if(@$new == 0);
Branch: 1 branch
BranchTrueFalseTotal
if @$new == 0 0 4 4
4091 4 $nx = shift @$new;
4092 4 ▶ $ny = (@$new) ? shift @$new : $nx;
Branch: 1 branch
BranchTrueFalseTotal
@$new ? : 4 0 4
4093 4 ▶ while($_ = shift @$new) { # assignment
Branch: 1 branch
BranchTrueFalseTotal
if ($_ = shift @$new) 0 4 4
4094 0 ▶ $dirs[0]="rowsfirst" if(m/^r/i);
Branch: 1 branch
BranchTrueFalseTotal
if /^r/i 0 0 0
4095 0 ▶ $dirs[0]="columnsfirst" if(m/^c/i);
Branch: 1 branch
BranchTrueFalseTotal
if /^c/i 0 0 0
4096 0 ▶ $dirs[1]="downwards" if(m/^d/i);
Branch: 1 branch
BranchTrueFalseTotal
if /^d/i 0 0 0
4097 0 ▶ $dirs[1]="upwards" if(m/^u/i);
Branch: 1 branch
BranchTrueFalseTotal
if /^u/i 0 0 0
4098 }
4099 } else {
4100 0 barf "multiplot: layout option needs a scalar or array ref value\n";
4101 }
4102 4 return join(" ",("$ny,$nx",$dirs[0],$dirs[1]));
4103 },
4104 3 'cl',undef,1,''],
4105 'title' => ['s','cq',undef,2,''],
4106 'scale' => ['l','c,',undef,3,''],
4107 'offset'=> ['l','c,',undef,4,'']
4108 };
4109 3 our $mpOptionsAbbrevs = _gen_abbrev_list(keys %$mpOptionsTable);
4110 3 our $mpOpt = [$mpOptionsTable, $mpOptionsAbbrevs, "multiplot option"];
4111  
4112 4 ▶sub multiplot_generate {
Subroutine multiplot_generate: called CC=5 SCAR=24.2
Pod documented
4113 4 my $this = _obj_or_global(\@_);
4114 4 ▶ if ($this->{options}{multiplot}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"options"}{"multiplot"}) 0 4 4
4115 0 carp "Warning: multiplot: object is already in multiplot mode!\n Exiting multiplot mode first...\n";
4116 0 end_multi($this);
4117 }
4118 4 my $mp_opts = _parseOptHash( undef, $mpOpt, @_ );
4119 # Assemble the command.
4120 my $preamble = _emitOpts({ 'terminal' => $this->{options}{terminal},
4121 'output' => $this->{options}{output},
4122 'termoption' => $this->{options}{termoption}
4123 },
4124 4 $pOpt);
4125 4 my $command = "set multiplot " . _emitOpts($mp_opts, $mpOpt) . "\n";
4126 4 ▶ if ($check_syntax) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PDL::Graphics::Gnuplot::check_syntax) 0 4 4
4127 0 my $test_preamble = "set terminal dumb\nset output \" \"\n";
4128 0 $PDL::Graphics::Gnuplot::last_testcmd = $test_preamble . $command;
4129 0 $this->{last_testcmd} = $test_preamble . $command;
4130 0 _printGnuplotPipe($this, "syntax", $test_preamble . $command);
4131 0 my $checkpointMessage = _checkpoint($this, "syntax");
4132 0 ▶ if ($checkpointMessage) {
Branch: 1 branch
BranchTrueFalseTotal
if ($checkpointMessage) 0 0 0
4133 0 ▶ if($MS_io_braindamage) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PDL::Graphics::Gnuplot::MS_io_braindamage) { } 0 0 0
4134 0 carp "WARNING: unexpected chatter while sending multiplot command:\n$checkpointMessage\n\n";
4135 } else {
4136 0 barf("Gnuplot error: \"$checkpointMessage\" while sending multiplot command.");
4137 }
4138 }
4139 }
4140 4 $this->{options}{multiplot} = 1;
4141 4 $preamble . $command;
4142 }
4143  
4144 3 ▶sub multiplot {
Subroutine multiplot: called CC=3 SCAR=13.1
Pod documented
4145 3 my $this = _obj_or_global(\@_);
4146 3 my $plotshow = $this->multiplot_generate(@_);
4147 3 $this->{last_plotcmd} = our $last_plotcmd = $plotshow;
4148 3 _printGnuplotPipe($this, "main", $plotshow);
4149 3 my $checkpointMessage = _checkpoint($this,"main");
4150 3 ▶ if ($checkpointMessage) {
Branch: 1 branch
BranchTrueFalseTotal
if ($checkpointMessage) 0 3 3
4151 0 ▶ if ($MS_io_braindamage) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PDL::Graphics::Gnuplot::MS_io_braindamage) { } 0 0 0
4152 0 carp "WARNING: unexpected chatter while sending final multiplot command:\n$checkpointMessage\n\n";
4153 } else {
4154 0 barf("Gnuplot error: \"$checkpointMessage\" while sending final multiplot command.");
4155 }
4156 }
4157 3 return;
4158 }
4159  
4160 2 ▶sub multiplot_next_generate {
Subroutine multiplot_next_generate: called CC=5 SCAR=20.3
Pod documented
4161 2 ▶ barf "multiplot_next: need Gnuplot 4.7+\n"
Branch: 1 branch
BranchTrueFalseTotal
if $PDL::Graphics::Gnuplot::gp_version < "4.7" 0 2 2
4162 if $PDL::Graphics::Gnuplot::gp_version < 4.7;
4163 2 my $this = _obj_or_global(\@_);
4164 barf "multiplot_next: you can't, you're not in multiplot mode\n"
4165 2 ▶ unless $this->{options}{multiplot};
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"options"}{"multiplot"} 0 2 2
4166 2 my $checkpointMessage;
4167 2 ▶ if ($check_syntax) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PDL::Graphics::Gnuplot::check_syntax) 0 2 2
4168 0 _printGnuplotPipe($this, "syntax", "set multiplot next\n");
4169 0 $checkpointMessage = _checkpoint($this, "syntax");
4170 0 ▶ barf "Gnuplot error: set multiplot next failed on syntax check!\n$checkpointMessage"
Branch: 1 branch
BranchTrueFalseTotal
if $checkpointMessage 0 0 0
4171 if $checkpointMessage;
4172 }
4173 2 "set multiplot next\n";
4174 }
4175  
4176 1 ▶sub multiplot_next {
Subroutine multiplot_next: called CC=5 SCAR=19.7
Pod documented
4177 1 ▶ barf "multiplot_next: need Gnuplot 4.7+\n"
Branch: 1 branch
BranchTrueFalseTotal
if $PDL::Graphics::Gnuplot::gp_version < "4.7" 0 1 1
4178 if $PDL::Graphics::Gnuplot::gp_version < 4.7;
4179 1 my $this = _obj_or_global(\@_);
4180 barf "multiplot_next: you can't, you're not in multiplot mode\n"
4181 1 ▶ unless $this->{options}{multiplot};
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"options"}{"multiplot"} 0 1 1
4182 1 my $plotcmd = $this->multiplot_next_generate;
4183 1 _printGnuplotPipe($this, "main", $plotcmd);
4184 1 my $checkpointMessage = _checkpoint($this, "main");
4185 1 ▶ if ($checkpointMessage) {
Branch: 1 branch
BranchTrueFalseTotal
if ($checkpointMessage) 0 1 1
4186 0 ▶ if ($MS_io_braindamage) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PDL::Graphics::Gnuplot::MS_io_braindamage) { } 0 0 0
4187 0 carp "WARNING: unexpected chatter after set multiplot next:\n$checkpointMessage\n";
4188 } else {
4189 0 barf("Gnuplot error: set multiplot next failed!\n$checkpointMessage");
4190 }
4191 }
4192 }
4193  
4194 3 ▶sub end_multi_generate {
Subroutine end_multi_generate: called CC=4 SCAR=17.9
Pod documented
4195 3 my $this = _obj_or_global(\@_);
4196 barf "end_multi: you can't, you're not in multiplot mode\n"
4197 3 ▶ unless $this->{options}{multiplot};
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"options"}{"multiplot"} 0 3 3
4198 3 ▶ if ($check_syntax) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PDL::Graphics::Gnuplot::check_syntax) 0 3 3
4199 0 _printGnuplotPipe($this, "syntax", "unset multiplot\n");
4200 0 my $checkpointMessage = _checkpoint($this, "syntax");
4201 0 ▶ barf "Gnuplot error: unset multiplot failed on syntax check!\n$checkpointMessage"
Branch: 1 branch
BranchTrueFalseTotal
if $checkpointMessage 0 0 0
4202 if $checkpointMessage;
4203 }
4204 3 $this->{options}{multiplot} = 0;
4205 3 "unset multiplot\n";
4206 }
4207  
4208 2 ▶sub end_multi {
Subroutine end_multi: called CC=5 SCAR=19.7
Pod documented
4209 2 my $this = _obj_or_global(\@_);
4210 barf "end_multi: you can't, you're not in multiplot mode\n"
4211 2 ▶ unless $this->{options}{multiplot};
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"options"}{"multiplot"} 0 2 2
4212 2 my $plotcmd = $this->end_multi_generate;
4213 2 _printGnuplotPipe($this, "main", $plotcmd);
4214 2 my $checkpointMessage = _checkpoint($this, "main");
4215 2 ▶ if ($checkpointMessage) {
Branch: 1 branch
BranchTrueFalseTotal
if ($checkpointMessage) 0 2 2
4216 0 ▶ if ($MS_io_braindamage) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PDL::Graphics::Gnuplot::MS_io_braindamage) { } 0 0 0
4217 0 carp "WARNING: unexpected chatter after unset multiplot:\n$checkpointMessage\n";
4218 } else {
4219 0 barf("Gnuplot error: unset multiplot failed!\n$checkpointMessage");
4220 }
4221 }
4222 2 ▶ $this->close if !$termTab->{$this->{terminal}}{disp};
Branch: 1 branch
BranchTrueFalseTotal
if not $$PDL::Graphics::Gnuplot::termTab{$this->{"terminal"}}{"disp"} 2 0 2
4223 }
4224  
4225 ######################################################################
4226 ##
4227 ## Input support
4228 ##
4229  
4230 =pod
4231  
4232 =head2 read_mouse
4233  
4234 =for usage
4235  
4236 ($x,$y,$char,$modstring) = $w->read_mouse($message);
4237 $hash = $w->read_mouse($message);
4238  
4239 =for ref
4240  
4241 Get a mouse click or keystroke from the active interactive plot window.
4242  
4243 For interactive devices (e.g. x11, wxt, aqua), read_mouse lets you accept a
4244 keystroke or mouse button input from the gnuplot window. In list context, it
4245 returns four arguments containing the reported X, Y, keystroke character, and
4246 modifiers packed in a string. In scalar context, it returns a hash ref containing
4247 those things.
4248  
4249 read_mouse blocks execution for input, but responds gracefully to interrupts.
4250  
4251 =cut
4252  
4253 3 my $mouse_serial = 0;
4254 0 ▶sub read_mouse {
Subroutine read_mouse: not called CC=25 SCAR=64.8
Pod documented
4255 0 my $this = shift;
4256 0 ▶ my $message = shift() // "Click mouse or press key in plot to continue...";
Condition0%0/2
shift() // "Click mouse or press key in plot to continue..."
l!l
00
MC/DC0%0/1
shift() // "Click mouse or press key in plot to continue..."
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
4257  
4258 0 ▶ unless($this->{mouse}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($this->{"mouse"}) 0 0 0
4259 0 my $s = "read_mouse: This plot uses the '$this->{terminal}' terminal, which doesn't support mousing\n";
4260 0 my @terms = ();
4261 0 for my $k(sort keys %$termTab) {
4262 0 ▶ push(@terms, $k) if($termTab->{$k}->{mouse} );
Branch: 1 branch
BranchTrueFalseTotal
if $PDL::Graphics::Gnuplot::termTab->{$k}{"mouse"} 0 0 0
4263 }
4264 0 ▶ if(@terms==0) {
Branch: 2 branches
BranchTrueFalseTotal
if (@terms == 0) { } 0 0 0
elsif (@terms == 1) { } 0 0 0
4265 0 $s .= "Sorry, your gnuplot engine doesn't have any mousing terminal types.\n";
4266 } elsif(@terms==1) {
4267 0 $s .= "Your gnuplot supports mousing only on the $terms[0] device.\n";
4268 } else {
4269 0 $s .= "Your gnuplot supports mousing on these devices: ".join(", ", @terms)."\n";
4270 }
4271  
4272 0 barf $s."\n";
4273 }
4274  
4275 barf "read_mouse: no existing plot to mouse on!\n"
4276 0 ▶ unless($this->{replottable});
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"replottable"} 0 0 0
4277  
4278 0 $mouse_serial++;
4279 0 my $string = _checkpoint($this, "main", {notimeout=>1});
4280  
4281 0 print STDERR $message;
4282  
4283 0 my($ch,$x,$y,$b,$sft,$alt,$ctl);
4284  
4285 ## Pre-4.7, Gnuplot reported MOUSE_BUTTON on a mouse button. That changed in 4.7.
4286 0 ▶ if($gp_version < 4.7) {
Branch: 2 branches
BranchTrueFalseTotal
if ($PDL::Graphics::Gnuplot::gp_version < 4.7) { } 0 0 0
elsif ($PDL::Graphics::Gnuplot::gp_version >= 4.7) { } 0 0 0
4287 0 _printGnuplotPipe($this, "main", <<"EOC" );
4288 pause mouse any
4289 if( (exists("MOUSE_BUTTON") * exists("MOUSE_X") * exists("MOUSE_Y")) ) print "Key: -1 at xy:",MOUSE_X,",",MOUSE_Y," button:",MOUSE_BUTTON," shift:",MOUSE_SHIFT," alt:",MOUSE_ALT," ctrl:",MOUSE_CTRL; else print "Key: ",MOUSE_KEY;
4290 EOC
4291  
4292 0 $string = _checkpoint($this, "main", {notimeout=>1});
4293  
4294 0 ▶ $string =~ m/Key: (\-?\d+)( +at xy:([^\s\,]+)\,([^\s\,]+)? button:(\d+)? shift:(\d+) alt:(\d+) ctrl:(\d+))?\s*$/
Branch: 1 branch
BranchTrueFalseTotal
$string =~ /Key: (\-?\d+)( +at xy:([^\s\,]+)\,([^\s\,]+)? button:(\d+)? shift:(\d+) alt:(\d+) ctrl:(\d+))?\s*$/ or barf("read_mouse: string '${string}' doesn't look right - doesn't match parse regexp.\n") 0 0 0
4295 || barf "read_mouse: string '$string' doesn't look right - doesn't match parse regexp.\n";
4296  
4297 0 ▶ ($ch,$x,$y,$b,$sft,$alt,$ctl) = map $_//"", ($1,$3,$4,$5,$6,$7,$8);
Condition0%0/2
$_ // ""
l!l
00
MC/DC0%0/1
$_ // ""
$_
Truth table0%0/2
A
A= $_
Aresult
11
00
4298  
4299 }
4300  
4301 ## Gnuplot 4.7 runs button input into the Key indicator.
4302 elsif($gp_version >= 4.7) {
4303 0 _printGnuplotPipe($this,"main",<<"EOC");
4304 pause mouse any
4305 if( (exists("MOUSE_KEY")) ) print "Key:",MOUSE_KEY; else print "Key:";
4306 if( (exists("MOUSE_X") * exists("MOUSE_Y")) ) print "at xy:",MOUSE_X,",",MOUSE_Y; else print "at xy:-1,-1";
4307 if( (exists("MOUSE_SHIFT") ) ) print "shift:",MOUSE_SHIFT; else print "shift:";
4308 if( (exists("MOUSE_ALT"))) print "alt:",MOUSE_ALT; else print "alt:";
4309 if( (exists("MOUSE_CTRL")) ) print "ctrl:",MOUSE_CTRL; else print "ctrl:";
4310 EOC
4311 0 $string = _checkpoint($this, "main", {notimeout=>1});
4312 0 $string =~ s/[\r\n]/ /sg;
4313  
4314 0 ▶ $string =~ m/Key:\s*(\-?\d+)( +at xy:\s*([^\s\,]+)\s*\,\s*([^\s\,]+) shift:\s*(\d+) alt:\s*(\d+) ctrl:\s*(\d+))?/
Branch: 1 branch
BranchTrueFalseTotal
$string =~ /Key:\s*(\-?\d+)( +at xy:\s*([^\s\,]+)\s*\,\s*([^\s\,]+) shift:\s*(\d+) alt:\s*(\d+) ctrl:\s*(\d+))?/ or barf("read_mouse: string '${string}' doesn't look right - doesn't match parse regexp.\n") 0 0 0
4315 || barf "read_mouse: string '$string' doesn't look right - doesn't match parse regexp.\n";
4316  
4317 0 ▶ ($ch,$x,$y,$sft,$alt,$ctl) = map $_ // "", ($1,$3,$4,$5,$6,$7);
Condition0%0/2
$_ // ""
l!l
00
MC/DC0%0/1
$_ // ""
$_
Truth table0%0/2
A
A= $_
Aresult
11
00
4318  
4319 0 ▶ if($ch == 1063) {
Branch: 3 branches
BranchTrueFalseTotal
if ($ch == 1063) { } 0 0 0
elsif ($ch == 2) { } 0 0 0
elsif ($ch == 65406) { } 0 0 0
4320 0 $b = 1;
4321 0 $ch = -1;
4322 } elsif($ch == 2) {
4323 0 $b = 2;
4324 0 $ch = -1;
4325 } elsif($ch == 65406) {
4326 0 $b = 3;
4327 0 $ch = -1;
4328 }
4329 }
4330  
4331 0 ▶ my $bm = { b=>$b, m=>($sft?"S":"").($alt?"A":"").($ctl?"C":"") };
Branch: 3 branches
BranchTrueFalseTotal
$sft ? : 0 0 0
$alt ? : 0 0 0
$ctl ? : 0 0 0
4332 0 ▶ return wantarray ? ($x,$y, ($ch>=32)?chr($ch):undef, $bm) :
Branch: 4 branches
BranchTrueFalseTotal
wantarray ? : 0 0 0
$ch >= 32 ? : 0 0 0
$ch < 0 ? : 0 0 0
$ch > 32 && $ch != 127 ? : 0 0 0
Condition0%0/3
$ch > 32 and $ch != 127
!ll&&!rl&&r
000
MC/DC0%0/2
$ch > 32 and $ch != 127
$ch > 32 $ch != 127
Truth table0%0/3
A and B
A= $ch > 32B= $ch != 127
ABresult
0X0
100
111
4333 {
4334 'x' => $x,
4335 'y' => $y,
4336 'k' => ($ch<0) ? "" : ($ch > 32 && $ch != 127) ? chr($ch) : sprintf("#%3.3d",$ch),
4337 %$bm,
4338 };
4339 }
4340  
4341 =pod
4342  
4343 =head2 read_polygon
4344  
4345 =for usage
4346  
4347 $points = $w->read_polygon(%opt)
4348  
4349 =for ref
4350  
4351 Read in a polygon by accepting mouse clicks. The polygon is returned as a 2xN PDL of ($x,$y) values in scientific units. Acceptable options are:
4352  
4353 =over 3
4354  
4355 =item message - what to print before collecting points
4356  
4357 There are some printf-style escapes for the prompt:
4358  
4359  
4360 * C<%c> - expands to "an open" or "a closed"
4361  
4362 * C<%n> - number of points currently in the polygon
4363  
4364 * C<%N> - number of points expected for the polygon
4365  
4366 * C<%k> - list of all keys accepted
4367  
4368 * C<%%> - %
4369  
4370 =item prompt - what to print to prompt the user for the next point
4371  
4372 C<prompt> uses the same escapes as C<message>.
4373  
4374 =item n_points - number of points to accept (or 0 for indefinite)
4375  
4376 With 0 value, points are accepted until the user presses 'q' or 'ESC' on the keyboard with focus
4377 on the graph. With other value, points are accepted until that happens *or* until the number
4378 of points is at least n_points.
4379  
4380 =item actions - hash of callback code refs indexed by character for action
4381  
4382 You can optionally call a callback routine when any particular
4383 character is pressed. The actions table is a hash ref whose keys are
4384 characters and whose values are either code refs (to be called on the
4385 associated keypress) or array refs containing a short description
4386 string followed by a code ref. Non-printable characters (e.g. ESC,
4387 BS, DEL) are accessed via a hash followed by a three digit decimal
4388 ASCII code -- e.g. "#127" for DEL. Button events are indexed with the
4389 strings "BUTTON1", "BUTTON2", and "BUTTON3", and modifications must be
4390 entered as well for shift, control, and
4391  
4392 The code ref receives the arguments ($obj, $c, $poly,$x,$y,$mods), where:
4393  
4394 =over 2
4395  
4396 =item C<$obj> is the plot object
4397  
4398 =item C<$c> is the character (or "BUTTONC<n>" string),
4399  
4400 =item C<$poly> is a scalar ref; $$poly is the current polygon before the action,
4401  
4402 =item C<$x> and C<$y> are the current scientific coordinates, and
4403  
4404 =item C<$mods> is the modifier string.
4405  
4406 You can't override the 'q' or '#027' (ESC) callbacks. You *can* override
4407 the BUTTON1 and DEL callbacks, potentially preventing the user from entering points
4408 at all! You should do that with caution.
4409  
4410 =item closed - (default false): generate a closed polygon
4411  
4412 This works by duplicating the initial point at the end of the point list.
4413  
4414 =item markup - (default 'linespoints'): style to use to render the polygon on the fly
4415  
4416 If this is set to a true value, it should be a valid 'with' specifier (curve option).
4417 The routine will call markup after each click.
4418  
4419 =back
4420  
4421 =back
4422  
4423 =cut
4424  
4425 # This table describes option parsing for read_polygon. Its format is the same as for the large
4426 # $plotOptionsTable, below. Full Gnuplot options parsing is perhaps a bit overblown for this
4427 # application, but it's present in the module so what the heck...
4428  
4429 our $rpOptionsTable = {
4430 3 map { ( $_->[0] => ['s',undef,undef,undef,$_->[1]] ) }
4431 ( ['message' => "Message to print before reading in polygon" ],
4432 ['prompt' => "Message to print for each point", ],
4433 ['n_points' => "Number of points (or 0 for indefinite)" ],
4434 ['closed', => "Flag: close polygon by copying first point" ],
4435 ['markup' => "Plot option for rendering, or undefined for none" ]
4436 ) };
4437 3 $rpOptionsTable->{actions} = ['H',undef,undef,undef,"Action table entries"];
4438  
4439 3 our $rpOpt = [$rpOptionsTable, _gen_abbrev_list(keys %$rpOptionsTable), "read_polygon option"];
4440  
4441 0 ▶sub read_polygon {
Subroutine read_polygon: not called CC=15 SCAR=54.8
Pod documented
4442 0 my $this = _obj_or_global(\@_);
4443  
4444 barf "read_polygon: $this->{terminal} terminal doesn't support mousing\n"
4445 0 ▶ unless($this->{mouse});
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"mouse"} 0 0 0
4446  
4447 0 my $poly = zeroes(2,0); # list of zero 2-D points
4448 0 local($this->{quit}) = 0;
4449  
4450 0 my $opt = {
4451 message => <<'EOMSG'
4452 Click points on the plot to form %c polygon. Use keys in window:
4453 %k
4454 EOMSG
4455 ,
4456 prompt => "(%n points in polygon) Waiting for plot input....",
4457 n_points => 0,
4458 closed => 0,
4459 markup => "linespoints",
4460 };
4461  
4462 $opt->{actions} = {
4463 # These defaults can be overridden.
4464 0 'd' => ['Delete last point (or DEL or backspace or shift-button)', \&__del],
4465 '#010' => \&__quit, # NEWLINE (ENTER)
4466 '#013' => \&__quit, # RETURN
4467 "#127" => \&__del, # DEL
4468 "#008" => \&__del, # BS
4469 'BUTTON1S' => \&__del, # shift-click
4470 'BUTTON1' => ['Add a point',\&__add],
4471 };
4472 0 print "\@_ is ".join(", ",@_)."\n";
4473 0 _parseOptHash( $opt, $rpOpt, @_ );
4474  
4475 0 print "actions table has keys: ",join(", ",sort keys %{$opt->{actions}}),"\n";
4476  
4477 0 my $a = $opt->{actions};
4478 0 $a->{"q"} = ['Quit / finish entry (or ESC)', \&__quit ];
4479 0 $a->{"#027"} = \&__quit;
4480  
4481 ### Parsing is complete, actions are in place.
4482  
4483 0 ▶ my $pstring = sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
4484 0 my $s = shift;
4485 0 ▶ my $z = ($opt->{closed}) ? "a closed" : "an open";
Branch: 1 branch
BranchTrueFalseTotal
$opt->{'closed'} ? : 0 0 0
4486 0 $s =~ s/\%c/$z/g;
4487  
4488 0 $z = $poly->dim(1);
4489 0 $s =~ s/\%n/$z/g;
4490  
4491 0 ▶ $z = $opt->{n_points} || "indefinite";
Condition0%0/2
$opt->{'n_points'} || 'indefinite'
l!l
00
MC/DC0%0/1
$opt->{'n_points'} || 'indefinite'
$opt->{'n_points'}
Truth table0%0/2
A
A= $opt->{'n_points'}
Aresult
11
00
4492 0 $s =~ s/\%N/$z/g;
4493  
4494 0 ▶ if($s =~ m/\%k/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /\%k/) 0 0 0
4495 0 $z = "INPUT ACTIONS:\n";
4496 0 ▶ for my $k(sort { (length($a) <=> length($b)) || ($a cmp $b) } keys %$a) {
Condition0%0/3
length $a <=> length $b || $a cmp $b
l!l&&r!l&&!r
000
MC/DC0%0/2
length $a <=> length $b || $a cmp $b
length $a <=> length $b $a cmp $b
Truth table0%0/3
A || B
A= length $a <=> length $bB= $a cmp $b
ABresult
1X1
011
000
4497 0 ▶ if(ref($a->{$k}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $a->{$k} eq "ARRAY") 0 0 0
4498 0 $z .= sprintf("%10s: %s\n",$k,$a->{$k}->[0]);
4499 }
4500 }
4501 0 $s =~ s/\%k/$z/g;
4502 }
4503  
4504 0 $s =~ s/\%\%/\%/g;
4505 0 return $s;
4506 0 };
4507  
4508 0 print &$pstring($opt->{message});
4509  
4510 0 my $h;
4511 do {
4512 0 $h = $this->read_mouse(&$pstring($opt->{prompt}));
4513 0 ▶ my $key = $h->{'b'} ? "BUTTON".$h->{'b'}.$h->{'m'} : $h->{'k'};
Branch: 1 branch
BranchTrueFalseTotal
$h->{'b'} ? : 0 0 0
4514  
4515 0 ▶ if(ref $a->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $a->{$key}) { } 0 0 0
4516 0 ▶ my $z = (ref($a->{$key}) eq 'CODE') ? $a->{$key} : $a->{$key}->[1];
Branch: 1 branch
BranchTrueFalseTotal
ref $a->{$key} eq 'CODE' ? : 0 0 0
4517 0 &$z($this, $key, \$poly, $h->{x}, $h->{y}, $h->{'m'});
4518 } else {
4519 0 print "$key! ";
4520 }
4521 0 print "\n";
4522  
4523 0 ▶ if($opt->{markup}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"markup"}) 0 0 0
4524 0 ▶ if($poly->dim(1)>0){
Branch: 1 branch
BranchTrueFalseTotal
if ($poly->dim(1) > 0) 0 0 0
4525 0 $this->markup( with => $opt->{markup},$poly->mv(-1,0)->dog);
4526 }
4527 }
4528  
4529 0 ▶ } while(($h->{'b'} || $h->{'k'}) and !$this->{quit} and ($opt->{n_points}==0 or $poly->dim(1)<$opt->{n_points}));
Branch: 1 branch
BranchTrueFalseTotal
$h->{"b"} || $h->{"k"} and not $this->{"quit"} and $opt->{"n_points"} == 0 || $poly->dim(1) < $opt->{"n_points"} and do { do { $h = $this->read_mouse(&$pstring($opt->{"prompt"})); my $key = $h->{"b"} ? 'BUTTON' . $h->{"b"} . $h->{"m"} : $h->{"k"}; if (ref $a->{$key}) { my $z = ref $a->{$key} eq "CODE" ? $a->{$key} : $a->{$key}[1]; &$z($this, $key, \$poly, $h->{"x"}, $h->{"y"}, $h->{"m"}); } else { print "$key! "; } ; print "\n"; if ($opt->{"markup"}) { if ($poly->dim(1) > 0) { $this->markup("with", $opt->{"markup"}, $poly->mv(-1, 0)->dog); } ; } } } 0 0 0
Condition0%0/12
$h->{"b"} || $h->{"k"} and not $this->{"quit"} and $opt->{"n_points"} == 0 || $poly->dim(1) < $opt->{"n_points"}
!ll&&!rl&&r
000
$h->{"b"} || $h->{"k"} and not $this->{"quit"}
!ll&&!rl&&r
000
$h->{"b"} or $h->{"k"}
l!l&&r!l&&!r
000
$opt->{"n_points"} == 0 or $poly->dim(1) < $opt->{"n_points"}
l!l&&r!l&&!r
000
MC/DC0%0/5
$h->{"b"} || $h->{"k"} and not $this->{"quit"} and $opt->{"n_points"} == 0 || $poly->dim(1) < $opt->{"n_points"}
$h->{"b"} $h->{"k"} not $this->{"quit"} $opt->{"n_points"} == 0 $poly->dim(1) < $opt->{"n_points"}
Truth table0%0/9
A or B and not(C) and D or E
A= $h->{"b"}B= $h->{"k"}C= not $this->{"quit"}D= $opt->{"n_points"} == 0E= $poly->dim(1) < $opt->{"n_points"}
ABCDEresult
00XXX0
1X0XX0
010XX0
1X1000
011000
1X11X1
1X1011
0111X1
011011
4530  
4531 0 print "\n";
4532  
4533 0 ▶ if($opt->{'closed'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"closed"}) 0 0 0
4534 0 $poly = $poly->glue(1,$poly->slice(":,(0)"));
4535 0 ▶ if($opt->{markup}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"markup"}) 0 0 0
4536 0 ▶ if($poly->dim(1)>0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($poly->dim(1) > 0) 0 0 0
4537 0 $this->markup( with => $opt->{markup},$poly->mv(-1,0)->dog);
4538 }
4539 }
4540 }
4541  
4542 0 return $poly;
4543  
4544 0 ▶ sub __del { my($w, $c, $p) = @_;
Subroutine __del: not called CC=3 SCAR=24.8
4545 0 ▶ return unless( ($$p)->$_isa('PDL') and (($$p)->dim(1)>0) );
Branch: 1 branch
BranchTrueFalseTotal
unless $$p->$PDL::Graphics::Gnuplot::_isa("PDL") and $$p->dim(1) > 0 0 0 0
Condition0%0/3
$$p->$PDL::Graphics::Gnuplot::_isa("PDL") and $$p->dim(1) > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$$p->$PDL::Graphics::Gnuplot::_isa("PDL") and $$p->dim(1) > 0
$$p->$PDL::Graphics::Gnuplot::_isa("PDL") $$p->dim(1) > 0
Truth table0%0/3
A and B
A= $$p->$PDL::Graphics::Gnuplot::_isa("PDL")B= $$p->dim(1) > 0
ABresult
0X0
100
111
4546 0 $$p = $$p->slice(',0:-2')->sever;
4547 0 return;
4548 }
4549  
4550 0 ▶ sub __quit { $_[0]->{quit} = 1; }
Subroutine __quit: not called CC=1 SCAR=6.9
4551  
4552 0 ▶ sub __add { my($w,$c,$p,$x,$y,$m) = @_;
Subroutine __add: not called CC=1 SCAR=6.9
4553 0 $$p = $$p->glue(1,pdl($x,$y));
4554 }
4555 }
4556  
4557 =pod
4558  
4559 =head2 pause_until_close
4560  
4561 =for usage
4562  
4563 $w->pause_until_close;
4564  
4565 =for ref
4566  
4567 Wait until the active interactive plot window is closed (e.g., by clicking the
4568 close button, hitting the close key-binding which defaults to C<q>).
4569  
4570 C<pause_until_close> blocks execution until the close event.
4571  
4572 =cut
4573  
4574 0 ▶sub pause_until_close {
Subroutine pause_until_close: not called CC=2 SCAR=17.9
Pod documented
4575 0 my $this = shift;
4576  
4577 barf "pause_until_close: $this->{terminal} terminal doesn't support mousing\n"
4578 0 ▶ unless($this->{mouse});
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"mouse"} 0 0 0
4579  
4580 0 _printGnuplotPipe($this, 'main', <<'EOC');
4581 pause mouse close
4582 EOC
4583 0 _checkpoint($this, "main", {notimeout=>1});
4584  
4585 0 return;
4586 }
4587  
4588 ######################################################################
4589 ######################################################################
4590 ######################################################################
4591 #####
4592 ##### Parsing routines
4593 #####
4594 ##### The task of parsing input parameters is nontrivial. It is
4595 ##### pushed off to several internal routines, which are here.
4596 #####
4597  
4598 ######################################################################
4599 # parsing helpers...
4600  
4601 ##############################
4602 # _gen_abbrev_list breaks a collection of keywords out into a hash linking
4603 # unique abbreviations to the expanded keyword, for _expand_abbrev below.
4604 # Cheesy and also awful as an added bonus.
4605 23 ▶sub _gen_abbrev_list {
Subroutine _gen_abbrev_list: called CC=5 SCAR=16.1
4606 23 my @keys = @_;
4607 23 my $hash = {};
4608 23 for my $k(@keys) {
4609 681 for my $i(0..length($k)-2) {
4610 3928 my $s = substr($k,0,$i+1);
4611 3928 ▶ if(exists($hash->{$s})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $hash->{$s}) { } 828 3100 3928
4612 827 push(@{$hash->{$s}},$k)
4613 828 ▶ unless($hash->{$s}->[0] eq $s); # exact matches override abbrevs
Branch: 1 branch
BranchTrueFalseTotal
unless $hash->{$s}[0] eq $s 827 1 828
4614 } else {
4615 3100 $hash->{$s} = [$k];
4616 }
4617 }
4618 681 $hash->{$k}=[$k]; # exact match always matches only the exact match
4619 }
4620 23 return $hash;
4621 }
4622  
4623 280 ▶sub _expand_abbrev {
Subroutine _expand_abbrev: called CC=7 SCAR=19.6
4624 280 ▶ my $s = shift() // "";
Condition50%1/2
shift() // ""
l!l
2800
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
4625 280 my $sl = lc($s);
4626 280 my $abbrevs = shift;
4627 280 my $name = shift;
4628  
4629 280 my $snum = undef;
4630  
4631 280 ▶ unless(exists($abbrevs->{$sl})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $abbrevs->{$sl}) 33 247 280
4632 33 ▶ if($sl =~ s/(\d+)\s*$//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sl =~ s/(\d+)\s*$//) 5 28 33
4633 5 $snum = $1;
4634 }
4635 }
4636  
4637 280 ▶ die "No $name found that matches '$s'\n" if !exists $abbrevs->{$sl};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $abbrevs->{$sl} 32 248 280
4638 0 barf "Error: ambiguous $name: '$s' could be one of { ".join(", ",@{$abbrevs->{$sl}})." }\n"
4639 248 ▶ if @{$abbrevs->{$sl}}>1;
Branch: 1 branch
BranchTrueFalseTotal
if @{$abbrevs->{$sl};} > 1 0 248 248
4640 248 ▶ return wantarray ? ($abbrevs->{$sl}->[0],$snum) : $abbrevs->{$sl}->[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 244 4 248
4641 }
4642  
4643 ##########
4644 # pOptionsTable - describes valid plot options and their allowed value types
4645 #
4646 # The keywords are the option name (from the Gnuplot 4.6 manual); the values are
4647 # an array ref containing:
4648 # - value type:
4649 # * array ref for a single value with options (first is default)
4650 # * "b" for boolean flag (actually ternary: true/false/undef)
4651 # * "n" for number
4652 # * "s" for a scalar string
4653 # * "l" for a list of options; none required; passing in a number yields a boolean, or undef deletes.
4654 # * "ln" for a list of options; none required; passing in a number copies to list, or undef deletes.
4655 # * "C" for cumulative list of options; scalar values OK
4656 # * "H" for a hash list of options
4657 # * "N" for multivalue with optional first-parameter index
4658 # (NOTE this is explicitly hardwired into _parseOptHash to accept trailing numbers
4659 # in the keyword itself, to enable passing multiple multivalue numbers with different labels
4660 # in a hash ref -- search for "HARDWIRED-N" to find the place)
4661 # * code ref for code checker: gets ($old-val, $new-param, $hash); returns new values
4662 # (with possible side effects on the object, e.g. for "device")
4663 # - output form:
4664 # * nothing: output single value or all list values on a single line
4665 # * ",": output list values as a comma-separated list on a single line (default is with spaces)
4666 # * "1": output list values one per line
4667 # * "H": output hash-of-lists, one list per line, with leading key
4668 # * "N": output list-of-lists, one list per line, with leading index
4669 # * code ref for code emitter: accepts key, value, source options hash, and object; returns
4670 # (potentially multiline) string of commands.
4671 # * hash ref for value context switch: keys are
4672 # accepted/understood keywords, values are output form for further keywords.
4673 # This is only valid with options lists ('l' input), and is used to keep track of
4674 # (e.g.) which keywords should be auto-quoted.
4675 # * array ref is not allowed in pOptionsTable but *is* allowed in cOptionsTable below.
4676 #
4677 # - sort-after:
4678 # * nothing: can appear in no particular order
4679 # * array ref: options later than which this option should be presented
4680 #
4681 # - sort-order
4682 # * a number: numbered options, if present appear at the beginning of the option dump, in numerical order.
4683 #
4684 # - documentation-string (optional)
4685 #
4686 # keywords with capital-letter value types are recognized even with a trailing number in the keyword;
4687 # this is to allow multiple values to be set in a single hash. In the default scalar output, the
4688 # empty string causes "unset" to be emitted, while undef causes nothing to be emitted.
4689 3 our $palettesTab;
4690  
4691 # suffix => terminal type, options
4692 3 our $hardCopySuffixes = {
4693 'gif'=>'gif',
4694 'jpg'=>'jpeg',
4695 'jpeg'=>'jpeg',
4696 'pdf'=>'pdfcairo solid color font ",10" size 11in,8.5in',
4697 'png'=>'png',
4698 'ps'=>'postscript solid color landscape 10 size 11in,8.5in',
4699 'eps'=>'postscript eps',
4700 'svg'=>'svg'
4701 };
4702  
4703  
4704 our $pOptionsTable =
4705 {
4706 # Start with pseudo-options we use internally.
4707 13 ▶ '3d' => ['s', sub { "" }, undef, undef,
Subroutine __ANON__: called CC=1 SCAR=0.0
4708 '[pseudo] Make the current plot 3d (gnuplot "splot" command).' ],
4709 10 ▶ 'trid' => [sub { my($o,$n,$h)=@_; $h->{'3d'}=$n; return undef}, sub { "" }, undef, undef,
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
4710 '[pseudo] Make the current plot 3d (synonym for "3d").' ],
4711 85 ▶ 'binary' => ['b', sub {""}, undef, undef,
Subroutine __ANON__: called CC=1 SCAR=0.0
4712 '[pseudo] Communicate with gnuplot in binary mode (default on non-Microsoft platforms).' ],
4713 0 ▶ 'ascii' => [sub { my($old, $new, $hash) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
4714 0 $hash->{binary} = !$new;
4715 0 ▶ }, sub {""}, undef, undef,
Subroutine __ANON__: not called CC=1 SCAR=6.9
4716 '[pseudo] Antonym for "binary" (default is 0 for non-Microsoft platforms).' ],
4717 0 ▶ 'device' => [ sub { my ($old, $new, $hash) = @_;
Subroutine __ANON__: not called CC=4 SCAR=30.0
4718 0 ▶ barf "Can't set device while in multiplot mode!\n" if($hash->{multiplot});
Branch: 1 branch
BranchTrueFalseTotal
if $hash->{"multiplot"} 0 0 0
4719 0 ▶ barf "Device option format: [<filename>]/<terminal-type>\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $new =~ m[^(.*)/([^/]*)$] 0 0 0
4720 if $new !~ m/^(.*)\/([^\/]*)$/;
4721 0 $hash->{terminal} = $2;
4722 0 ▶ $hash->{output} = $1 || undef;
Condition0%0/2
$1 || undef
l!l
00
MC/DC0%0/1
$1 || undef
$1
Truth table0%0/2
A
A= $1
Aresult
11
00
4723 0 return undef;
4724 },
4725 0 ▶ sub { "" }, undef, undef,
Subroutine __ANON__: not called CC=1 SCAR=6.9
4726 '[pseudo] Shorthand for device spec.: "dev=>\'<output/<terminal>\'".' ],
4727  
4728 0 ▶ 'hardcopy' => [ sub { my ($old, $new, $hash) = @_;
Subroutine __ANON__: not called CC=4 SCAR=30.0
4729 0 ▶ barf "Can't set hardcopy while in multiplot mode!\n" if($hash->{multiplot});
Branch: 1 branch
BranchTrueFalseTotal
if $hash->{"multiplot"} 0 0 0
4730 0 ▶ die "hardcopy: need a file suffix to infer file type\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $new =~ /\.([a-z]+)$/i 0 0 0
4731 if $new !~ m/\.([a-z]+)$/i;
4732 0 my $suffix = lc $1;
4733 die "hardcopy: couldn't identify file type from '$new'\n"
4734 0 ▶ if !$hardCopySuffixes->{$suffix};
Branch: 1 branch
BranchTrueFalseTotal
unless $PDL::Graphics::Gnuplot::hardCopySuffixes->{$suffix} 0 0 0
4735 0 $hash->{terminal} = $hardCopySuffixes->{$suffix};
4736 0 $hash->{output} = $new;
4737 0 return undef;
4738 0 ▶ }, sub {""},undef,undef,
Subroutine __ANON__: not called CC=1 SCAR=6.9
4739 '[pseudo] Shorthand for device spec.: standard image formats inferred by suffix' ],
4740  
4741 'dump' => [
4742 0 ▶ sub { my $newval = $_[1];
Subroutine __ANON__: not called CC=5 SCAR=34.0
4743 0 ▶ if($newval && !$_[2]->{dump}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($newval and not $_[2]{'dump'}) { } 0 0 0
elsif ($_[2]{'dump'} and not $newval) { } 0 0 0
Condition0%0/3
$newval and not $_[2]{"dump"}
!ll&&!rl&&r
000
MC/DC0%0/2
$newval and not $_[2]{"dump"}
$newval not $_[2]{"dump"}
Truth table0%0/3
A and not(B)
A= $newvalB= not $_[2]{"dump"}
ABresult
0X0
100
111
4744 0 carp "WARNING - dumping ON - gnuplot commands go to the terminal only.\n";
4745 ▶ } elsif($_[2]->{dump} && !$newval) {
Condition0%0/3
$_[2]{"dump"} and not $newval
!ll&&!rl&&r
000
MC/DC0%0/2
$_[2]{"dump"} and not $newval
$_[2]{"dump"} not $newval
Truth table0%0/3
A and not(B)
A= $_[2]{"dump"}B= not $newval
ABresult
0X0
100
111
4746 0 carp "WARNING - dumping OFF - gnuplot commands will be used for plotting.\n";
4747 }
4748 0 return $newval;
4749 },
4750 0 ▶ sub { "" },undef, undef,
Subroutine __ANON__: not called CC=1 SCAR=6.9
4751 '[pseudo] Redirect gnuplot commands to stdout for inspection'
4752 ],
4753  
4754 0 ▶ 'tee' => [ sub { $_[1]; }, sub { "" }, undef, undef,
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
4755 '[pseudo] Tee gnuplot commands to stdout (set to "nobinary" for viewing)' ],
4756  
4757 0 ▶ 'silent' => ['b', sub { "" }, undef, undef,
Subroutine __ANON__: not called CC=1 SCAR=6.9
4758 '[pseudo] Be silent about gnuplot errors' ],
4759  
4760 # topcmds/extracmds/bottomcmds: contain explicit strings for gnuplot.
4761 # topcmds go just below the "set term", "set termoption", and "set output" commands;
4762 # extracmds go after all the auto-generated commands and just before the plot lines
4763 # bottomcmds comes after everything -- useful for cleanup after the plot command
4764 #is sent.
4765 3 ▶ 'topcmds' => ['l', sub { my($k,$v,$h) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.2
4766 3 ▶ return (ref $v eq 'ARRAY') ? join("\n",(@$v,"")) : $v."\n"; },
Branch: 1 branch
BranchTrueFalseTotal
ref $v eq 'ARRAY' ? : 3 0 3
4767 undef, 10,
4768 '[pseudo] extra gnuplot commands at the top of the command block' ],
4769  
4770 1 ▶ 'extracmds' => ['l', sub { my($k,$v,$h) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.2
4771 1 ▶ return (ref $v eq 'ARRAY') ? join("\n",(@$v,"")) : $v."\n"; },
Branch: 1 branch
BranchTrueFalseTotal
ref $v eq 'ARRAY' ? : 1 0 1
4772 ,undef, 1001,
4773 '[pseudo] extra gnuplot commands between plot options and the plots' ],
4774 # bottomcmds is implemented by special hook in plot().
4775 1 ▶ 'bottomcmds' => ['l', sub {""}, undef, undef,
Subroutine __ANON__: called CC=1 SCAR=0.0
4776 '[pseudo] extra gnuplot commands after all plot commands' ],
4777  
4778 8 ▶ 'globalwith'=> ['l', sub { "" }, undef, undef,
Subroutine __ANON__: called CC=1 SCAR=0.0
4779 '[pseudo] default plot style (overridden by "with" in curve options)' ],
4780  
4781  
4782 0 ▶ 'perceptual'=>[sub { my($old,$new,$this) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
4783 0 eval { require PDL::Transform::Color };
4784 0 ▶ barf("pseudocolor option requires PDL::Transform::Color, which is not present")
Branch: 1 branch
BranchTrueFalseTotal
unless $PDL::Transform::Color::VERSION 0 0 0
4785 unless($PDL::Transform::Color::VERSION);
4786 0 return $new;
4787 },
4788 0 ▶ sub { my($k, $v, $h) = @_;
Subroutine __ANON__: not called CC=4 SCAR=27.1
4789 0 ▶ return unless (defined($v));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
4790 0 my $s = "";
4791 0 my $t = eval {
4792 0 ▶ PDL::Transform::Color::t_pcp(ref($v) eq 'ARRAY' ? @$v : $v);
Branch: 1 branch
BranchTrueFalseTotal
ref $v eq 'ARRAY' ? : 0 0 0
4793 };
4794 0 ▶ if($@){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
4795 0 my $a=$@;
4796 0 $@=undef;
4797 0 $a =~ s/Usage\:.*\.\)//s;
4798 # not barf -- no traceback
4799 0 die("PDL::Transform::Color palettes for the 'perceptual'/'pcp' plot option are:\n (palettes marked 'phot' respond differently with the 'perceptual' option;\n Append the suffix '-c<n>', n in [0..5], to a name to get RGB combinatorics.)\n".$a."\n");
4800 }
4801 0 my $grey = xvals(2049)/2048;
4802 0 my $rgb = $grey->apply($t);
4803  
4804 {
4805 0 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.2
4806 my @s = map {
4807 0 sprintf(" %d '#%2.2X%2.2X%2.2X'", $_, $rgb->slice('x',[$_,,0])->list);
4808 } (0..$grey->dim(0)-1);
4809  
4810 0 $s .= "set palette defined ( ".join(",", @s)." )\n";
4811 }
4812 0 $s;
4813 },
4814 ['clut'],undef,
4815 '[pseudo] Use PDL::Transform::Color photometric palette: "pseudocolor=>\'heat\'"' ],
4816  
4817 0 ▶ 'pseudocolor'=>[sub { my($old,$new,$this) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
4818 0 eval { require PDL::Transform::Color };
4819 0 ▶ barf("pseudocolor option requires PDL::Transform::Color, which is not present")
Branch: 1 branch
BranchTrueFalseTotal
unless $PDL::Transform::Color::VERSION 0 0 0
4820 unless($PDL::Transform::Color::VERSION);
4821 0 return $new;
4822 },
4823 0 ▶ sub { my($k, $v, $h) = @_;
Subroutine __ANON__: not called CC=8 SCAR=38.9
4824 0 ▶ return unless(defined($v));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
4825 0 ▶ if(defined($h->{'perceptual'})){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $h->{"perceptual"}) 0 0 0
4826 0 print STDERR "Warning: 'perceptual'/'pcp' pseudocolor option overriding 'pseudocolor'/'pc'\n";
4827 0 return;
4828 }
4829 0 my $s = "";
4830 0 my $t = eval {
4831 0 ▶ PDL::Transform::Color::t_pc(ref($v) eq 'ARRAY' ? @$v : $v);
Branch: 1 branch
BranchTrueFalseTotal
ref $v eq 'ARRAY' ? : 0 0 0
4832 };
4833 0 ▶ if($@){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
4834 0 my $a = $@;
4835 0 $@ = undef;
4836 0 $a =~ s/Usage\:.*value\)//s;
4837 # die not barf - no traceback.
4838 0 die("PDL::Transform::Color palettes for the 'pseudocolor'/'pc' plot option are:\n (palettes marked 'phot' respond differently with the 'perceptual' option)\n".$a."\n");
4839 }
4840  
4841 0 my $grey = xvals(2049)/2048;
4842 0 my $rgb = $grey->apply($t);
4843  
4844 0 my $last_str = "";
4845 0 my @s = ();
4846 0 for(0..$grey->dim(0)-1) {
4847 # Turn off warnings to prevent "redundant argument" warnings on certain sprintfs
4848 3 ▶no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4849 0 my $this_str = sprintf("'#%2.2X%2.2X%2.2X'",$rgb->slice('x',[$_,,0])->list);
4850 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4851 0 ▶ if($_ == $grey->dim(0)-1 or $this_str ne $last_str) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ == $grey->dim(0) - 1 or $this_str ne $last_str) 0 0 0
Condition0%0/3
$_ == $grey->dim(0) - 1 or $this_str ne $last_str
l!l&&r!l&&!r
000
MC/DC0%0/2
$_ == $grey->dim(0) - 1 or $this_str ne $last_str
$_ == $grey->dim(0) - 1 $this_str ne $last_str
Truth table0%0/3
A or B
A= $_ == $grey->dim(0) - 1B= $this_str ne $last_str
ABresult
1X1
011
000
4852 0 push(@s,sprintf(" %d %s",$_,$this_str));
4853 0 $last_str = $this_str;
4854 }
4855 }
4856  
4857 0 $s .= "set palette defined ( ".join(",", @s)." )\n";
4858 0 $s;
4859 },
4860 ['clut'],undef,
4861 '[pseudo] Use PDL::Transform::Color photometric palette: "pseudocolor=>\'heat\'"' ],
4862  
4863  
4864 0 ▶ 'clut' => [sub { my($old, $new, $this) = @_;
Subroutine __ANON__: not called CC=6 SCAR=37.4
4865 0 ▶ $new = ($new ? lc $new : "default");
Branch: 1 branch
BranchTrueFalseTotal
$new ? : 0 0 0
4866 0 ▶ if($palettesTab->{$new}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PDL::Graphics::Gnuplot::palettesTab->{$new}) { } 0 0 0
4867 0 return $new;
4868 } else {
4869 0 my $s = "Unknown lookup table name passed as a 'clut' option. Acceptable values are:\n";
4870 0 for my $k(sort
4871 0 ▶ {$a eq 'default' ? $b : $a eq 'default' ? $b : $a cmp $b}
Branch: 2 branches
BranchTrueFalseTotal
$a eq 'default' ? : 0 0 0
$a eq 'default' ? : 0 0 0
4872 keys %$palettesTab
4873 ) {
4874 0 $s .= sprintf(" %10.10s (%s)\n",$k, $palettesTab->{$k}->[2]);
4875 }
4876 0 barf($s);
4877 }
4878 },
4879 0 ▶ sub { my($k, $v, $h) = @_;
Subroutine __ANON__: not called CC=6 SCAR=37.4
4880 0 my $s = "";
4881 0 ▶ return unless(defined($v));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
4882 0 ▶ if(defined($h->{'pseudocolor'}) || defined($h->{'perceptual'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $h->{"pseudocolor"} or defined $h->{"perceptual"}) 0 0 0
Condition0%0/3
defined $h->{"pseudocolor"} or defined $h->{"perceptual"}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $h->{"pseudocolor"} or defined $h->{"perceptual"}
defined $h->{"pseudocolor"} defined $h->{"perceptual"}
Truth table0%0/3
A or B
A= defined $h->{"pseudocolor"}B= defined $h->{"perceptual"}
ABresult
1X1
011
000
4883 0 print "Warning: 'pseudocolor'/'pc' or 'perceptual'/'pcp' plot option overriding 'clut'\n";
4884 0 return;
4885 }
4886 0 ▶ unless($palettesTab->{$v}) { die "Color table lookup failed -- this should never happen" }
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDL::Graphics::Gnuplot::palettesTab->{$v}) 0 0 0
4887 0 ▶ if(defined($palettesTab->{$v}->[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $PDL::Graphics::Gnuplot::palettesTab->{$v}[0]) 0 0 0
4888 0 $s .= "set palette model $palettesTab->{$v}->[0]\n";
4889 }
4890 0 $s .= "set palette $palettesTab->{$v}->[1]\n";
4891 0 $s;
4892 },
4893 ['palette'],undef,
4894 '[pseudo] Use named color look-up table for palette: "clut=>\'heat2\'"' ],
4895  
4896 2 ▶ 'globalPlot'=> ['l',sub { return '' },undef,undef,
Subroutine __ANON__: called CC=1 SCAR=0.0
4897 '[pseudo] marker for the global plot object' ],
4898  
4899 3 ▶ 'justify' => [sub { my($old,$new,$opt) = @_;
Subroutine __ANON__: called CC=6 SCAR=18.8
4900 3 ▶ return undef if !defined $new;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $new 0 3 3
4901 3 ▶ if($new > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new > 0) 1 2 3
4902 1 $opt->{'size'} = ["ratio ".(-$new)];
4903 1 return undef;
4904 }
4905 2 ▶ die "justify: positive value needed\n" if $new<0;
Branch: 1 branch
BranchTrueFalseTotal
if $new < 0 1 1 2
4906 1 ▶ if(defined($opt->{'size'}) and $opt->{'size'}->[0] =~ m/ratio/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt->{"size"} and $opt->{"size"}[0] =~ /ratio/) 0 1 1
Condition33%1/3
defined $opt->{"size"} and $opt->{"size"}[0] =~ /ratio/
!ll&&!rl&&r
100
MC/DC0%0/2
defined $opt->{"size"} and $opt->{"size"}[0] =~ /ratio/
defined $opt->{"size"} $opt->{"size"}[0] =~ /ratio/
Truth table33%1/3
A and B
A= defined $opt->{"size"}B= $opt->{"size"}[0] =~ /ratio/
ABresult
0X0
100
111
4907 0 $opt->{'size'} = undef;
4908 }
4909 1 return undef;
4910 },
4911 0 ▶ sub { '' }, undef, undef,
Subroutine __ANON__: not called CC=1 SCAR=6.9
4912 '[pseudo] Set aspect ratio (equivalent to: size=>["ratio",<r>])' ],
4913 0 ▶ 'square' => [sub { my($old, $new, $opt) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
4914 0 ▶ if($new) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new) 0 0 0
4915 0 $opt->{'size'} = ["ratio -1"];
4916 0 ▶ $opt->{'view'} = [] unless defined($opt->{'view'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opt->{"view"} 0 0 0
4917 0 @{$opt->{'view'}}[2..5] = ($new, $new, "equal", "xyz");
4918 0 return undef;
4919 }
4920 0 delete @$opt{qw(size view)};
4921 },
4922 0 ▶ sub { return '' }, undef, undef,
Subroutine __ANON__: not called CC=1 SCAR=6.9
4923 '[pseudo] Set aspect ratio to square (equivalent to: size=["ratio",1])' ],
4924 ##############################
4925 # These are all the "plot" (top-level) options recognized by gnuplot 4.4.
4926 'angles' => [['degrees','radians'],'s',undef,undef,
4927 '(radians or degrees): sets unit in which angles will be specified' ],
4928 'arrow' => ['N','N',undef,undef,
4929 'allows specification of arrows to be drawn on subsequent plots' ],
4930 'autoscale' => ['lh','H2',undef,undef,
4931 'autoscaling style: autoscale=>{ (x|y|z|cb|x2|y2|xy) => (0|" "|fix|fixmin|fixmax|min|max) }.' ],
4932 'bars' => ['l','l',undef,undef,
4933 'errorbar ticsize: bars=> {(small|large|fullwidth|<size>) => (0|" "|front|back) }."' ],
4934 'bmargin' => ['s','s',undef,undef,
4935 'bottom margin (chars); bmargin=>"at screen <frac>" for pane-rel. size' ],
4936 'border' => ['l','l',undef,undef,
4937 'specify border around the plot (see gnuplot manual)' ],
4938 'boxwidth' => ['l','l',undef,undef,
4939 'default width of boxes in those plot styles that have them' ],
4940 'cbdata' => ['s','bt', ['colorbox'], undef,
4941 'cbdata=>"time" to use time stamps on color box data axis (see timefmt)' ],
4942 'cbdtics' => ['b','b', ['colorbox'], undef,
4943 'cbdtics=>1 to use days-of-week tick labels on the color box axis' ],
4944 'cblabel' => ['l','ql', ['colorbox'], undef,
4945 'sets the label on the color box axis' ],
4946 'cbmtics' => ['b','b', ['colorbox'], undef,
4947 'cbmtics=>1 to use months-of-year tick labels on the color box axis' ],
4948 'cbrange' => ['lr','range',['colorbox'], undef,
4949 'controls rendered range of color data values: cbrange=>[<min>,<max>]' ],
4950 0 ▶ 'cbmin' => [sub { my($o,$n,$h)=@_; $h->{cbrange}->[0]=$n; return undef},sub{''},undef,undef,
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
4951 'sets minimum end of cbrange' ],
4952 0 ▶ 'cbmax' => [sub { my($o,$n,$h)=@_; $h->{cbrange}->[1]=$n; return undef},sub{''},undef,undef,
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
4953 'sets maximum end of cbrange' ],
4954 'cbtics' => ['lt','lt', ['colorbox'], undef,
4955 'controls major (labelled) ticks on the color box axis (see docs)' ],
4956 'clabel' => ['s','q',undef,undef,
4957 'Contour level legend format for contour plots (default "%8.3g")' ],
4958 'clip' => ['H','H',undef,undef,
4959 'control filtering near boundary: clip=>{points=>1,one=>0,two=>1}' ],
4960 'cntrparam' => ['l','1',undef,undef,
4961 'control contour plotting parameters (see docs)' ],
4962 'colorbox' => ['l','l',undef,undef,
4963 'set color box options for pm3d and image; set to undef to remove box' ],
4964 'contour' => ['s','s',undef,undef,
4965 'control 3d contour plots: contour=>("base"|"surface"|"both"|undef)' ],
4966 'datafile' => ['H','H',undef,undef,
4967 'control how gnuplot interprets data files (not recommended)' ],
4968 'decimalsign'=>['s','q',undef,undef,
4969 'control character used for decimal point in labels' ],
4970 'dgrid3d' => ['l','l',undef, undef,
4971 'set up interpolation of scattered datapoints onto a regular grid' ],
4972 'dummy' => ['l',',', undef, undef,
4973 'change name of dummy variable for parametric plots (not recommended)' ],
4974 'encoding' => ['s','s', undef, undef,
4975 'change locale of character encoding (not recommended)' ],
4976 0 ▶ 'fit' => [sub { die "set fit: not (yet) implemented in PDL Gnuplot interface\n";}],
Subroutine __ANON__: not called CC=1 SCAR=6.9
4977 'fontpath' => ['l','l',undef,undef,
4978 'set directories to search when looking for fonts (PostScript only)' ],
4979 'format' => ['H','H',undef,undef,
4980 'Fine-grained control over formatting of axis labels' ],
4981 0 ▶ 'function' => [sub { die "'set function' is deprecated by gnuplot and not allowed here\n"; } ],
Subroutine __ANON__: not called CC=1 SCAR=6.9
4982 'grid' => ['l','l',undef,undef,
4983 'draw grid lines on the plot (see docs)' ],
4984 'hidden3d' => ['l','l',undef,undef,
4985 'control whether and how hidden lines are removed in 3d (see docs)' ],
4986 'isosamples'=> ['l','l',undef,undef,
4987 'control isoline density for plotting functions as surfaces' ],
4988 'key' => ['l','l',undef,undef,
4989 'enable key/legend and control its position and appearance (see docs)' ],
4990 'label' => ['N','NL',undef,undef,
4991 'Define text labels to be rendered in plot (numeric index; see docs)' ],
4992 'lmargin' => ['s','s',undef,undef,
4993 'left margin (chars); lmargin=>"at screen <frac>" for pane-rel. size' ],
4994 0 ▶ 'loadpath' => [sub { die "loadpath not supported\n"; }],
Subroutine __ANON__: not called CC=1 SCAR=6.9
4995 'locale' => ['s','q',undef,undef,
4996 'set named locale for date/month formatting' ],
4997 'logscale' => ['l','l',undef,undef,
4998 'set log scaling and base: e.g. logscale=>["xyx2cb",10]' ],
4999 0 ▶ 'macros' => [sub { die "macros: not supported\n"; } ],
Subroutine __ANON__: not called CC=1 SCAR=6.9
5000 'mapping' => [['cartesian','cylindrical','spherical'],'s',undef,undef,
5001 'set coordinates for 3d plots: "cartesian","spherical", or "cylindrical"' ],
5002 # multiplot: this is not emitted as part of any plot command, only by the special multiplot method.
5003 0 ▶ 'multiplot' => [sub { die "multiplot: use the 'multiplot' method, don't set this directly\n" },sub { ""},undef,undef,undef] ,
Subroutine __ANON__: not called CC=1 SCAR=1.2
Subroutine __ANON__: called CC=1 SCAR=1.2
5004 'mxtics' => ['lt','lt',undef,undef,
5005 'set and control minor ticks on the X axis: mxtics=><freq>' ],
5006 'mx2tics' => ['lt','lt',undef,undef,
5007 'set and control minor ticks on the X2 axis: mx2tics=><freq>' ],
5008 'mytics' => ['lt','lt',undef,undef,
5009 'set and control minor ticks on the Y axis: mytics=><freq>' ],
5010 'my2tics' => ['lt','lt',undef,undef,
5011 'set and control minor ticks on the Y2 axis: my2tics=><freq>' ],
5012 'mztics' => ['lt','lt',undef,undef,
5013 'set and control minor ticks on the Z axis: mztics=><freq>' ],
5014 'object' => ['N','NO',undef,undef,
5015 'define objects to be overlain on plot (numeric index; see docs)' ],
5016 'offsets' => ['l','l',undef,undef,
5017 'define inside-axis blank margin (science units): [<l>,<r>,<t>,<b>]' ],
5018 'origin' => ['l',',',undef,undef,
5019 'set 2-D origin of the plotting surface in relative screen coordinates' ],
5020 3 ▶ 'output' => [sub { my($k,$v,$h) = @_;
Subroutine __ANON__: called CC=3 SCAR=13.3
5021 0 ▶ unless(defined($h) and $h->{globalPlot}) {barf("Don't set output as a plot option; use the constructor\n");}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $h and $h->{"globalPlot"}) 0 3 3
Condition33%1/3
defined $h and $h->{"globalPlot"}
!ll&&!rl&&r
003
MC/DC0%0/2
defined $h and $h->{"globalPlot"}
defined $h $h->{"globalPlot"}
Truth table33%1/3
A and B
A= defined $hB= $h->{"globalPlot"}
ABresult
0X0
100
111
5022 3 return $v;
5023 },
5024 89 ▶ sub { my($k,$v,$h) = @_;
Subroutine __ANON__: called CC=7 SCAR=19.5
5025 89 ▶ return "" unless((defined($v) and !($h->{multiplot})));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v and not $h->{"multiplot"} 4 85 89
Condition66%2/3
defined $v and not $h->{"multiplot"}
!ll&&!rl&&r
0485
MC/DC50%1/2
defined $v and not $h->{"multiplot"}
defined $v not $h->{"multiplot"}
Truth table66%2/3
A and not(B)
A= defined $vB= not $h->{"multiplot"}
ABresult
0X0
100
111
5026 85 ▶ return "unset $k\n" unless(length($v));
Branch: 1 branch
BranchTrueFalseTotal
unless length $v 0 85 85
5027 85 my $vv = $v;
5028 85 $vv =~ s/(^|[^\%])\%s/${1}Plot-/;
5029 85 ▶ if($vv =~ m/(^|[^\%])\%d/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vv =~ /(^|[^\%])\%d/) 5 80 85
5030 5 my $fnum = 0;
5031 5 my $vvn;
5032 5 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
-e $vvn and do { do { ++$fnum; $vvn = $vv; $vvn =~ s/(^|[^\%])\%d/$1$fnum/ } } 1 5 6
5033 6 $fnum++;
5034 6 $vvn = $vv;
5035 6 $vvn =~ s/(^|[^\%])\%d/${1}${fnum}/;
5036 } while( -e $vvn);
5037 5 $vv = $vvn;
5038 }
5039 85 ▶ if($vv ne $v) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vv ne $v) 5 80 85
5040 5 carp "INFO: Plotting to '$vv'\n";
5041 }
5042 85 $vv = quote_escape($vv);
5043 85 return "set $k \"$vv\"\n";
5044 },
5045 undef,3,
5046 'set output file or label for plot (see "terminal", "device")' ],
5047 'parametric'=> ['b','b',undef,undef,
5048 'sets parametric mode for plotting parametric curves (boolean)' ],
5049 'pm3d' => ['l','l',undef,undef,
5050 'sets up color palette-mapped 3d surface plots (see docs)' ],
5051 'palette' => ['l','l',undef,undef,
5052 'sets up color palette for color mapped plots (see docs and "clut")' ],
5053 'pointsize' => ['s','s',undef,undef,
5054 'sets the size of plotted point symbols (multiplier on base size)' ],
5055 'polar' => ['b','b',['angles'],undef,
5056 'sets 2-D plots into polar coordinates. (see also "angles")' ],
5057 'rmargin' => ['s','s',undef,undef,
5058 'right margin (chars); rmargin=>"at screen <frac>" for pane-rel. size' ],
5059 'rrange' => ['lr','range',undef,undef,
5060 'radial coordinate range in polar mode: rrange=>[<lo>,<hi>]' ],
5061 'size' => ['l','l',['view'],undef,
5062 'sets the size of the plot pane relative to the main window (see also "justify")' ],
5063 'style' => ['H','H',undef,undef,
5064 'Set various aspects of plot style by keyword (see docs)' ],
5065 'surface' => ['b','b',undef,undef,
5066 'Turn on/off surface drawing in 3-d plots (boolean)' ],
5067 0 ▶ 'table' => [sub { die "table not supported - use Perl's 'print' instead\n" } ],
Subroutine __ANON__: not called CC=1 SCAR=6.9
5068 3 ▶ 'terminal' => [sub { my($k,$v,$h)=@_;
Subroutine __ANON__: called CC=3 SCAR=13.3
5069 0 ▶ unless(defined($h) and $h->{globalPlot}) {barf("Don't set terminal as a plot option; use the constructor or output().\n")}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $h and $h->{"globalPlot"}) 0 3 3
Condition33%1/3
defined $h and $h->{"globalPlot"}
!ll&&!rl&&r
003
MC/DC0%0/2
defined $h and $h->{"globalPlot"}
defined $h $h->{"globalPlot"}
Truth table33%1/3
A and B
A= defined $hB= $h->{"globalPlot"}
ABresult
0X0
100
111
5070 3 return $v;
5071 },
5072 'nomulti',
5073 undef,1,
5074 'Set the output device type and device dependent options (see docs)\n' ],
5075 'termoption'=> ['H','HNM',undef,2,
5076 'Set certain options for the terminal driver, by keyword' ],
5077 'tics' => ['l','l',undef,undef,
5078 'Control tick mark formatting (deprecated; <axis>tics recommended instead)' ],
5079 'timestamp' => ['l','l',undef,undef,
5080 'creates a timestamp in the left margin of the plot (see docs)' ],
5081 0 ▶ 'timefmt' => [sub { carp "Warning: timefmt doesn't work well in formats other than '%s'. Proceed with caution!\n"
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[1] and $_[1] ne "%s" 0 0 0
Condition0%0/3
defined $_[1] and $_[1] ne "%s"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_[1] and $_[1] ne "%s"
defined $_[1] $_[1] ne "%s"
Truth table0%0/3
A and B
A= defined $_[1]B= $_[1] ne "%s"
ABresult
0X0
100
111
5082 if( defined($_[1]) and $_[1] ne '%s');
5083 0 ▶ return ( (defined $_[1]) ? "$_[1]" : undef );
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] ? : 0 0 0
5084 },'q',undef,undef,
5085 'Sets format for interpreting time data (leave as "%s"; see docs)' ],
5086 'title' => ['l','ql',undef,undef,
5087 'Set title for the plot. See docs for size/color/font options' ],
5088 'tmargin' => ['s','s',undef,undef,
5089 'top margin (chars); tmargin=>"at screen <frac>" for pane-rel. size' ],
5090 'trange' => ['lr','range',undef,undef,
5091 'range for indep. variable in parametric plots: trange=>[<min>,<max>]' ],
5092 'urange' => ['lr','range',undef,undef,
5093 'range for indep. variable "u" in 3-d parametric plots: [<min>,<max>]' ],
5094 0 ▶ 'view' => ['l', sub { my($k,$v,$h)=@_;
Subroutine __ANON__: not called CC=11 SCAR=48.8
5095 0 ▶ return "" unless defined($v);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
5096 0 ▶ return "set view 60,30,1.0,1.0\nset view noequal\n" unless( ref $v eq 'ARRAY' ); # default value from manual
Branch: 1 branch
BranchTrueFalseTotal
unless ref $v eq "ARRAY" 0 0 0
5097 0 my @numbers = ();
5098 0 my @v = @$v;
5099  
5100 0 ▶ while( @v && (($v[0]//"") =~ m/^(\s*\-?((\d+\.?\d*)|(\d*\.\d+))([eE][\+\-]\d*)?\s*)?$/ )) {
Branch: 1 branch
BranchTrueFalseTotal
if (@v and ($v[0] // "") =~ /^(\s*\-?((\d+\.?\d*)|(\d*\.\d+))([eE][\+\-]\d*)?\s*)?$/) 0 0 0
Condition0%0/5
@v and ($v[0] // "") =~ /^(\s*\-?((\d+\.?\d*)|(\d*\.\d+))([eE][\+\-]\d*)?\s*)?$/
!ll&&!rl&&r
000
$v[0] // ""
l!l
00
MC/DC0%0/2
@v and ($v[0] // "") =~ /^(\s*\-?((\d+\.?\d*)|(\d*\.\d+))([eE][\+\-]\d*)?\s*)?$/
@v $v[0]
Truth table0%0/3
A and B
A= @vB= $v[0]
ABresult
0X0
100
111
5101 0 ▶ push @numbers, shift(@v)//"";
Condition0%0/2
shift @v // ""
l!l
00
MC/DC0%0/1
shift @v // ""
shift @v
Truth table0%0/2
A
A= shift @v
Aresult
11
00
5102 }
5103 0 my $s = "";
5104 0 ▶ $s .= "set view ".join(",",@numbers)."\n" if(@numbers);
Branch: 1 branch
BranchTrueFalseTotal
if @numbers 0 0 0
5105 0 ▶ while(@v) {
Branch: 1 branch
BranchTrueFalseTotal
if (@v) 0 0 0
5106 0 ▶ if($v[0] eq 'equal' and $v[1] =~ m/xyz?/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v[0] eq 'equal' and $v[1] =~ /xyz?/) { } 0 0 0
Condition0%0/3
$v[0] eq "equal" and $v[1] =~ /xyz?/
!ll&&!rl&&r
000
MC/DC0%0/2
$v[0] eq "equal" and $v[1] =~ /xyz?/
$v[0] eq "equal" $v[1] =~ /xyz?/
Truth table0%0/3
A and B
A= $v[0] eq "equal"B= $v[1] =~ /xyz?/
ABresult
0X0
100
111
5107 0 $s .= sprintf("set view %s %s\n",splice(@v,0,2));
5108 } else {
5109 0 $s .= sprintf("set view %s\n",shift @v);
5110 }
5111 }
5112 0 return $s;
5113 },
5114 undef,undef,
5115 '3-d view: [r_x, r_z, scale, sc_z,"map","noequal","equal (xy|xyz)"]' ],
5116 'vrange' => ['lr','range',undef,undef,
5117 'range for indep. variable "v" in 3-d parametric plots: [<min>,<max>]' ],
5118 'x2data' => ['s','bt',undef,undef,
5119 'x2data=>"time" to use time stamps on X2 axis (see timefmt)' ],
5120 'x2dtics' => ['b','b',undef,undef,
5121 'x2dtics=>1 to use days-of-week tick labels on X2 axis' ],
5122 'x2label' => ['l','ql',undef,undef,
5123 'sets label for the X2 axis. See docs for size/color/font options' ],
5124 'x2mtics' => ['b','b',undef,undef,
5125 'x2mtics=>1 to use months-of-year tick labels on the X2 axis' ],
5126 0 ▶ 'x2min' => [sub { my($o,$n,$h)=@_; $h->{x2range}->[0]=$n; return undef},sub{''},undef,undef,
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
5127 'sets minimum end of x2range' ],
5128 0 ▶ 'x2max' => [sub { my($o,$n,$h)=@_; $h->{x2range}->[1]=$n; return undef},sub{''},undef,undef,
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
5129 'sets maximum end of x2range' ],
5130 'x2range' => ['lr','range',undef,undef,
5131 'set range of X2 axis: x2range=>[<min>,<max>]' ],
5132 'x2tics' => ['lt','lt',undef,undef,
5133 'Control tick mark formatting (X2 axis; see docs)' ],
5134 'x2zeroaxis'=> ['l','l',undef,undef,
5135 'If set, draw a vertical line at X2=0; see docs for formatting' ],
5136 'xdata' => ['s','bt',undef,undef,
5137 'xdata=>"time" to use time stamps on X axis (see timefmt)' ],
5138 'xdtics' => ['b','b',undef,undef,
5139 'xdtics=>1 to use days-of-week tick labels on X axis' ],
5140 'xlabel' => ['l','ql',undef,undef,
5141 'sets label for the X axis. See docs for size/color/font options' ],
5142 'xmtics' => ['b','b',undef,undef,
5143 'xmtics=>1 to use months-of-year tick labels on the X axis' ],
5144 8 ▶ 'xmin' => [sub { my($o,$n,$h)=@_; $h->{xrange}->[0]=$n; return undef},sub{''},undef,undef,
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
5145 'sets minimum end of xrange' ],
5146 0 ▶ 'xmax' => [sub { my($o,$n,$h)=@_; $h->{xrange}->[1]=$n; return undef},sub{''},undef,undef,
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
5147 'sets maximum end of xrange' ],
5148 'xrange' => ['lr','range',undef,undef,
5149 'set range of X axis: xrange=>[<min>,<max>]' ],
5150 'xtics' => ['lt','lt',undef,undef,
5151 'Control tick mark formatting (X axis; see docs)' ],
5152 'xyplane' => ['l','l',undef,undef,
5153 'Sets location of the XY plane in 3-D plots; see docs' ],
5154 'xzeroaxis' => ['l','l',undef,undef,
5155 'if set, draw a vertical line at X=0; see docs for formatting' ],
5156 'y2data' => ['s','bt',undef,undef,
5157 'y2data=>"time" to use time stamps on Y2 axis (see timefmt)' ],
5158 'y2dtics' => ['b','b',undef,undef,
5159 'y2dtics=>1 to use days-of-week tick labels on Y2 axis' ],
5160 'y2label' => ['l','ql',undef,undef,
5161 'sets label for the Y2 axis. See docs for size/color/font options' ],
5162 'y2mtics' => ['b','b',undef,undef,
5163 'y2mtics=>1 to use months-of-year tick labels on Y2 axis' ],
5164 0 ▶ 'y2min' => [sub { my($o,$n,$h)=@_; $h->{y2range}->[0]=$n; return undef},sub{''},undef,undef,
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
5165 'sets minimum end of y2range' ],
5166 0 ▶ 'y2max' => [sub { my($o,$n,$h)=@_; $h->{y2range}->[1]=$n; return undef},sub{''},undef,undef,
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
5167 'sets maximum end of y2range' ],
5168 'y2range' => ['lr','range',undef,undef,
5169 'set range of Y2 axis: y2range=>[<min>,<max>]' ],
5170 'y2tics' => ['lt','lt',undef,undef,
5171 'Control tick mark formatting (Y2 axis; see docs)' ],
5172 'y2zeroaxis'=> ['l','l',undef,undef,
5173 'if set, draw a horizontal line at Y2=0; see docs for formatting' ],
5174 'ydata' => ['s','bt',undef,undef,
5175 'ydata=>"time" to use time stamps on Y axis (see timefmt)' ],
5176 'ydtics' => ['b','b',undef,undef,
5177 'ydtics=>1 to use days-of-week tick labels on Y axis' ],
5178 'ytics' => ['lt','lt',undef,undef,
5179 'Control tick mark formatting (Y axis; see docs)' ],
5180 'ylabel' => ['l','ql',undef,undef,
5181 'sets label for the Y axis. See docs for size/color/font options' ],
5182 'ymtics' => ['b','b',undef,undef,
5183 'ymticks=>1 to use months-of-year tick labels on Y axis' ],
5184 0 ▶ 'ymin' => [sub { my($o,$n,$h)=@_; $h->{yrange}->[0]=$n; return undef},sub{''},undef,undef,
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
5185 'sets minimum end of yrange' ],
5186 0 ▶ 'ymax' => [sub { my($o,$n,$h)=@_; $h->{yrange}->[1]=$n; return undef},sub{''},undef,undef,
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
5187 'sets maximum end of yrange' ],
5188 'yrange' => ['lr','range',undef,undef,
5189 'set range of Y axis: yrange=>[<min>,<max>]' ],
5190 'yzeroaxis' => ['l','l',undef,undef,
5191 'if set, draw a horizontal line at Y=0; see docs for formatting' ],
5192 'zdata' => ['s','bt',undef,undef,
5193 'zdata=>"time" to use time stamps on Z axis (see timefmt)' ],
5194 'zdtics' => ['b','b',undef,undef,
5195 'zdtics=>1 to use days-of-week tick labels on Z axis' ],
5196 'zlabel' => ['l','ql',undef,undef,
5197 'sets label for the Z axis. See docs for size/color/font options' ],
5198 'zmtics' => ['b','b',undef,undef,
5199 'zmtics=>1 to use months-of-year tick labels on Z axis' ],
5200 0 ▶ 'zmin' => [sub { my($o,$n,$h)=@_; $h->{zrange}->[0]=$n; return undef},sub{''},undef,undef,
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
5201 'sets minimum end of zrange' ],
5202 0 ▶ 'zmax' => [sub { my($o,$n,$h)=@_; $h->{zrange}->[1]=$n; return undef},sub{''},undef,undef,
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
5203 3 'sets maximum end of zrange' ],
5204 'zrange' => ['lr','range',undef,undef,
5205 'set range of Z axis: zrange=>[<min>,<max>]' ],
5206 'zzeroaxis' => ['l','l',undef,undef,
5207 'if set, draw a line through (X=0,Y=0) on a 3-D plot. See docs' ],
5208 'zero' => ['s','s',undef,undef,
5209 'Sets the default threshold for values approaching 0.0' ],
5210 'ztics' => ['lt','lt',undef,undef,
5211 'Control tick mark formatting (Z axis; see docs)' ]
5212 };
5213 3 our $pOptionsAbbrevs = _gen_abbrev_list(keys %$pOptionsTable);
5214 3 $pOptionsAbbrevs->{'term'} = ['terminal']; # frequently-used case
5215 3 $pOptionsAbbrevs->{'time'} = ['timestamp']; # compat. with gnuplot's alt. spelling
5216 3 $pOptionsAbbrevs->{'pc'} = ['pseudocolor'];
5217 3 $pOptionsAbbrevs->{'pcp'} = ['perceptual'];
5218  
5219 3 $pOpt = [$pOptionsTable, $pOptionsAbbrevs, "plot option"];
5220  
5221  
5222 ##########
5223 # cOptionsTable - describes valid curve options and their allowed value types
5224 #
5225 # The output types are different so that they can all be interpolated into the same
5226 # master table. Curve option output routines have a 'c' in front of the name.
5227 #
5228  
5229 our $cOptionsTable = {
5230 # data is here so that it gets sorted properly into each chunk -- but it doesn't get specified this way.
5231 # the output string just specifies STDIN. The magic output string gets replaced post facto with the test and
5232 # real output format specifiers.
5233 1 ▶ 'cdims' => [sub { my $s = $_[1] // 0; # Number of dimensions in a column
Subroutine __ANON__: called CC=5 SCAR=20.1
Condition50%1/2
$_[1] // 0
l!l
10
MC/DC0%0/1
$_[1] // 0
$_[1]
Truth table50%1/2
A
A= $_[1]
Aresult
11
00
5234 1 ▶ barf "Curve option 'cdims' must be one of 0, 1, or 2\n" unless $s==0 or $s==1 or $s==2;
Branch: 1 branch
BranchTrueFalseTotal
unless $s == 0 or $s == 1 or $s == 2 0 1 1
Condition33%2/6
$s == 0 or $s == 1 or $s == 2
l!l&&r!l&&!r
100
$s == 0 or $s == 1
l!l&&r!l&&!r
010
MC/DC0%0/3
$s == 0 or $s == 1 or $s == 2
$s == 0 $s == 1 $s == 2
Truth table25%1/4
A or B or C
A= $s == 0B= $s == 1C= $s == 2
ABCresult
1XX1
01X1
0011
0000
5235 1 return $s;
5236 },
5237 1 ▶ sub { return ""}],
Subroutine __ANON__: called CC=1 SCAR=0.0
5238 0 ▶ 'data' => [sub { barf "mustn't specify data as a curve option...\n" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
5239 92 ▶ sub { return " $cmdFence "; },
Subroutine __ANON__: called CC=1 SCAR=0.0
5240 undef,5
5241 ],
5242 'using' => ['l','cl',undef,6], # using clauses in order (straight passthrough)
5243 # legend is a special case -- it gets parsed as a list but emitted as a quoted scalar.
5244 92 ▶ 'legend' => ['ln', sub { if(defined($_[1]) and defined $_[1][0]) {return "title \"$_[1][0]\"";} else {return "notitle"}},
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1] and defined $_[1][0]) { } 2 90 92
Condition100%3/3
defined $_[1] and defined $_[1][0]
!ll&&!rl&&r
8552
MC/DC100%2/2
defined $_[1] and defined $_[1][0]
defined $_[1] defined $_[1][0]
Truth table100%3/3
A and B
A= defined $_[1]B= defined $_[1][0]
ABresult
0X0
100
111
5245 undef, 7],
5246 'axes' => [['(x[12])(y[12])'],'cs',undef,8],
5247 'smooth' => ['s','cs',undef,8.1],
5248 'with' => ['l', 'cl', undef, 9],
5249  
5250 # The next curve options are "with" modifiers. They have to be sorted
5251 # after 'with' to be treated properly. They should probably have some
5252 # sort of filter built in to ensure we don't feed gnuplot a curve
5253 # option that is inappropriate for the particular type of curve we are
5254 # plotting - but gnuplot does seem to catch that case and throw an error,
5255 # so the only benefit would be delivering a cleaner error message.
5256 'linestyle'=> ['s', 'cs', undef, 10],
5257 'linetype' => ['s', 'cs', undef, 11],
5258 'dashtype' => ['dt', 'dt', undef, 11.5], # dashtype is new with Gnuplot 5
5259 'linewidth'=> ['s', 'css', undef, 12],
5260 'linecolor'=> ['l', 'ccolor', undef, 13],
5261 'textcolor'=> ['l', 'ccolor', undef, 14],
5262 0 ▶ 'below' => [ 'l', sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
5263 0 ▶ return "$_[0] $_[1][0]" if (defined $_[1] and defined $_[1][0]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[1] and defined $_[1][0] 0 0 0
Condition0%0/3
defined $_[1] and defined $_[1][0]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_[1] and defined $_[1][0]
defined $_[1] defined $_[1][0]
Truth table0%0/3
A and B
A= defined $_[1]B= defined $_[1][0]
ABresult
0X0
100
111
5264 0 return "";
5265 }, undef, 9.2],
5266 0 ▶ 'above' => [ 'l', sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
5267 0 ▶ return "$_[0] $_[1][0]" if (defined $_[1] and defined $_[1][0]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[1] and defined $_[1][0] 0 0 0
Condition0%0/3
defined $_[1] and defined $_[1][0]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_[1] and defined $_[1][0]
defined $_[1] defined $_[1][0]
Truth table0%0/3
A and B
A= defined $_[1]B= defined $_[1][0]
ABresult
0X0
100
111
5268 0 return "";
5269 }, undef, 9.3],
5270 'fillcolor'=> ['l', 'ccolor', ['above', 'below'], 14.5],
5271 'pointtype'=> ['s', 'cs', undef, 15],
5272 'pointsize'=> ['s', 'css', undef, 16],
5273 'fillstyle'=> ['l', 'cl', undef, 17],
5274 'nohidden3d'=>['b', 'cff', undef, 18],
5275 'nohidden3d'=>['b', 'cff', undef, 19],
5276 'nocontours'=>['b', 'cff', undef, 20],
5277 'nosurface' =>['b', 'cff', undef, 21],
5278 'palette' =>['b', 'cff', undef, 22],
5279  
5280 0 ▶ 'tuplesize'=> ['s',sub { return ""}], # set tuplesize explicitly (not a gnuplot option)
Subroutine __ANON__: not called CC=1 SCAR=6.9
5281 2 ▶ 'resample' => [sub { my ($k, $v, $h) = @_; # for FITS
Subroutine __ANON__: called CC=7 SCAR=20.7
5282 2 ▶ return if !$v;
Branch: 1 branch
BranchTrueFalseTotal
unless $v 0 2 2
5283 2 ▶ return [1024,1024] if !ref $v;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $v 1 1 2
5284 1 ▶ barf "Curve option 'resample' given non-array ref '$v'" if ref $v ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $v ne "ARRAY" 0 1 1
5285 1 ▶ barf "Curve option 'resample' given array-ref with no values" if !@$v;
Branch: 1 branch
BranchTrueFalseTotal
unless @$v 0 1 1
5286 1 ▶ barf "Curve option 'resample' given array-ref with too many values" if @$v > 2;
Branch: 1 branch
BranchTrueFalseTotal
if @$v > 2 0 1 1
5287 1 ▶ @$v == 1 ? [@$v[0,0]] : $v;
Branch: 1 branch
BranchTrueFalseTotal
@$v == 1 ? : 0 1 1
5288 },
5289 2 ▶ sub {""}],
Subroutine __ANON__: called CC=1 SCAR=0.0
5290 };
5291  
5292 3 our $cOptionsAbbrevs = _gen_abbrev_list(keys %$cOptionsTable);
5293 #### Gnuplot official abbreviations for the "with"-modifying curve options
5294 {
5295 3 my $officialAbbrevs = {
5296 lt => ["linetype"],
5297 dt => ["dashtype"],
5298 ls => ["linestyle"],
5299 lw => ["linewidth"],
5300 lc => ["linecolor"],
5301 pt => ["pointtype"],
5302 ps => ["pointsize"],
5303 fs => ["fillstyle"],
5304 fc => ["fillcolor"],
5305 };
5306 3 for my $k(%$officialAbbrevs){
5307 54 $cOptionsAbbrevs->{$k} = $officialAbbrevs->{$k};
5308 }
5309 }
5310  
5311  
5312 3 $cOpt = [$cOptionsTable, $cOptionsAbbrevs, "curve option"];
5313  
5314  
5315  
5316 ##########
5317 # $plotStyleProps
5318 #
5319 # This table describes the types of input expected by the various
5320 # plot styles. Each entry should be an array ref. The colums are:
5321 #
5322 # 0: "ts" Tuple sizes (columns of data) that are allowed by this plot style for
5323 # ordinary 2-D plots. (We let gnuplot interpret the columns; this just
5324 # keeps track of the different numbers of columns that are allowed). If
5325 # a plot style isn't allowed in 2-D, then this entry should be a false value.
5326 # Negative values get the "array" rather than the "record" specifier (for autogen
5327 # of coordinates)
5328 #
5329 # 1: "3dts" Tuple sizes (columns of data) that are allowed by this plot style for
5330 # 3-D plots (with the gnuplot "plots" command). If this plot style doesn't
5331 # work in 3-D, then the entry should be a false value instead.
5332 #
5333 # 2: img This is a flag indicating whether it is an image format plot (which accepts
5334 # 2-D matrix data in each "column"). If false, the column is a 1-D collection
5335 # of values.
5336 #
5337 # 3: bin 0/1/undef - 0: ASCII data required for this plot type; 1: binary data required.
5338 #
5339 # 4: frob if present, pointer to a prefrobnication routine to prepare the data.
5340 # Currently, fits images are handled that way because of gnuplot's problem
5341 # dealing with proper coordinate grids -- the fits image is sampled into
5342 # scientific coordinates using PDL::Transform. The prefrobnicator should accept:
5343 # * the 'with' option array ref,
5344 # * the main plot object (for access to plot options)
5345 # * the plot chunk (for access to curve options),
5346 # * all the data passed in for that curve.
5347 # It should return the new data ndarray list, and modify the chunk 'with' list and curve options in place.
5348 # While it has access to plot options, it probably shouldn't modify them.
5349  
5350 3 our $plotStyleProps ={
5351 ### key ts 3dts img bin prefrobnicator
5352 boxerrorbars => [ [3,4,5], 0, 0, undef ],
5353 boxes => [ [2,3], 0, 0, undef ],
5354 boxxyerrorbars => [ [4,6], 0, 0, undef ],
5355 candlesticks => [ [5,6], 0, 0, undef ],
5356 circles => [ [2,3], 0, 0, undef ],
5357 dots => [ [-1,2], [3], 0, undef ],
5358 ellipses => [ [2,3,4,5],0, 0, undef ],
5359 filledcurves => [ [2,3], 0, 0, undef ],
5360 financebars => [ [5], 0, 0, undef ],
5361 fsteps => [ [-1,2], 0, 0, undef ],
5362 histeps => [ [-1,2], 0, 0, undef ],
5363 histogram => [ [1..99], 0, 0, undef ],
5364 newhistogram => [ [1..99], 0, 0, undef ],
5365 fits => [ [-1], [-1], 1, 1 , \&_with_fits_prefrobnicator ],
5366 image => [ [-1,3], [-1,4], 1, 1 ],
5367 impulses => [ [-1,2,3], [-1,-2,3,4], 0, undef ],
5368 labels => [ [3], [4], 0, 0 ],
5369 lines => [ [-1,2], [-1,3], 0, undef ],
5370 linespoints => [ [-1,2], [-1,3], 0, undef ],
5371 points => [ [-1,2], [-1,3], 0, undef ],
5372 rgbalpha => [ [-4,6], [-4,7], 1, 1 ],
5373 rgbimage => [ [-3,5], [-3,6], 1, 1 ],
5374 steps => [ [-1,2], 0, 0, undef ],
5375 vectors => [ [4], [6], 0, undef ],
5376 xerrorbars => [ [-2,3,4], 0, 0, undef ],
5377 xyerrorbars => [ [-3,4,6], 0, 0, undef ],
5378 yerrorbars => [ [-2,3,4], 0, 0, undef ],
5379 xerrorlines => [ [-3,4], 0, 0, undef ],
5380 xyerrorlines => [ [-4,6], 0, 0, undef ],
5381 yerrorlines => [ [-3,4], 0, 0, undef ],
5382 pm3d => [ 0, [-1,3,4], 1, 1 ]
5383 };
5384  
5385 ##############################
5386 # plotStyleDocs - just a one-line string for summarizing each plot style.
5387 # These are not (yet) used but should be incorporated into a documentation schema.
5388 3 our $plotStyleSyntax = 'Tuple columns are listed for each style. "[]": optional. "{}": 3-D style';
5389 3 our $plotStyleDocs ={
5390 boxerrorbars => ["boxes on X axis", "x, y, dy, [dx]; x, y, ylo, yhi, dx"],
5391 boxes => ["boxes sitting on X axis", "x, y, [dx]"],
5392 boxxyerrorbars => ["XY errorbars as rectangles", "x, y, dx, dy; x, y, xlo, xhi, ylo, yhi"],
5393 candlesticks => ["box-and-errorbar plots", "x, blo, wlo, whi, bhi,"],
5394 circles => ["circles", "x, y, [r]"],
5395 dots => ["Tiny dots (scatterplot)", "[x], y; {x, y, z}"],
5396 ellipses => ["ellipses", "x, y, [dmaj, [dmin, [ang]]]"],
5397 filledcurves => ["fill polygon, to axis, or topoint", "x, y; x, y1, y2"],
5398 financebars => ["financial stem plot", "x, open, lo, hi, close"],
5399 fsteps => ["steps (Y first; cf histeps, steps)", "[x], y"],
5400 histeps => ["steps (centered; cf fsteps, steps)", "[x], y"],
5401 histograms => ["histogram (set tuplesize if >99 cols)", "y, [y1, [y2, [...]]]"],
5402 newhistogram => ["histogram (set tuplesize if >99 cols)", "y, [y1, [y2, [...]]]"],
5403 fits => ["FITS image with WCS info in header", "[x, y], i; {[x, y, z], i}"],
5404 image => ["I (WxH), RGB (WxHx3) or RGBA (WxHx4)", "[x, y], i; {[x, y, z], i}"],
5405 impulses => ["Vert lines from y=0 or z=0 to point", "[x], y; {[x, y], z}"],
5406 labels => ["Text at given location", "x, y, str; {x, y, z, str}"],
5407 lines => ["Simple line plot", "[x], y; {[x, y], z}"],
5408 linespoints => ["Lines with symbols at points", "[x], y; {[x, y], z}"],
5409 points => ["Small symbol at each point", "[x], y; {[x, y], z}"],
5410 rgbimage => ["RGB image: 2D with R,G,B", "[x, y], r,g,b; {[x, y, z], r,g,b}"],
5411 rgbalpha => ["RGBA image: 2D with R,G,B,A", "[x, y], r,g,b,a; {[x, y, z], r,g,b,a}"],
5412 steps => ["steps (Y last; cf fsteps, histeps)", "[x], y"],
5413 vectors => ["Plot a vector field", "x, y, dx, dy; {x, y, z, dx, dy, dz}"],
5414 xerrorbars => ["Whisker errorbars in X", "x, y, dx; x, y, xlo, xhi"],
5415 xyerrorbars => ["Whisker errorbars in X & Y", "x, y, dx, dy; x, y, xlo, xhi, ylo, yhi"],
5416 yerrorbars => ["Whisker errorbars in Y", "x, y, dy; x, y, ylo, yhi"],
5417 xerrorlines => ["Whisker errorbars in X, connected", "x, y, dx; x, y, xlo, xhi"],
5418 xyerrorlines => ["Whisker errorbars in X & Y, connected", "x, y, dx, dy; x, y, xlo, xhi, ylo, yhi"],
5419 yerrorlines => ["Whisker errorbars in Y, connected", "x, y, dy; x, y, ylo, yhi"],
5420 pm3d => ["Colored 3-D surface plot", "{[x,y,z],[i]}"]
5421 };
5422  
5423  
5424 3 our $plotStyleAbbrevs = _gen_abbrev_list(keys %$plotStyleProps);
5425 # Make some tweaks to the abbreviations...
5426 3 map { $plotStyleAbbrevs->{$_} = 'lines' } qw/ li lin line lines /;
5427 3 $plotStyleAbbrevs->{box} = 'boxes';
5428 3 $plotStyleAbbrevs->{lp} = 'linespoints';
5429 3 map { $plotStyleAbbrevs->{$_} = 'histeps' } qw/ hs hi his hist /;
5430  
5431  
5432 ##############################
5433 # palettesTab - this is a table mapping palette names to rgb specifications in gnuplot, together
5434 # with the color model they support.
5435 #
5436 # From gnuplot's "show palette rgbformulae" command, there are 37 different available rgb color mapping formulae;
5437 # these are used where possible, but defined palettes can also be used.
5438 #
5439 # These codes are used in the parser/emitter codes for the "clut" pseudo-option.
5440 #
5441 # Each value is an array ref containing (color model),(palette string).
5442 #
5443 # For reference, the formulae in the 'rgbformulae' option, at least in Gnuplot 4.4, are:
5444 #
5445 # 0: 0 1: 0.5 2: 1
5446 # 3: x 4: x^2 5: x^3
5447 # 6: x^4 7: sqrt(x) 8: sqrt(sqrt(x))
5448 # 9: sin(90x) 10: cos(90x) 11: |x-0.5|
5449 # 12: (2x-1)^2 13: sin(180x) 14: |cos(180x)|
5450 # 15: sin(360x) 16: cos(360x) 17: |sin(360x)|
5451 # 18: |cos(360x)| 19: |sin(720x)| 20: |cos(720x)|
5452 # 21: 3x 22: 3x-1 23: 3x-2
5453 # 24: |3x-1| 25: |3x-2| 26: (3x-1)/2
5454 # 27: (3x-2)/2 28: |(3x-1)/2| 29: |(3x-2)/2|
5455 # 30: x/0.32-0.78125 31: 2*x-0.84 32: 4x;1;-2x+1.84;x/0.08-11.5
5456 # 33: |2*x - 0.5| 34: 2*x 35: 2*x - 0.5
5457 # 36: 2*x - 1
5458  
5459 3 $palettesTab = {
5460 default => [ undef, undef, "default palette assigned by Gnuplot" ],
5461 grey => [ undef, 'gray', "gray" ],
5462 gray => [ undef, 'gray', "gray" ],
5463 sepia => [ 'RGB', 'color rgbformulae 7,3,4', "a simple sepiatone" ],
5464 grepia => [ 'RGB', 'color rgbformulae 3,7,4', "a simple sepiatone, in green" ],
5465 blepia => [ 'RGB', 'color rgbformulae 4,3,7', "a simple sepiatone, in cyan/blue"],
5466 vepia => [ 'RGB', 'color rgbformulae 3,4,7', "a simple sepiatone, in violet" ],
5467 pm3d => [ 'RGB', 'color rgbformulae 7,5,15', "black-blue-red-yellow" ],
5468 grv => [ 'RGB', 'color rgbformulae 3,11,6', "green-red-violet" ],
5469 ocean => [ 'RGB', 'color rgbformulae 23,28,3', "green-blue-white" ],
5470 gback => [ 'RGB', 'color rgbformulae 31,31,32', "printable on a gray background" ],
5471 rainbow => [ 'RGB', 'color rgbformulae -33,-13,-10',"Rainbow red-yellow-green-blue" ],
5472 heat1 => [ 'RGB', 'color rgbformulae 21,22,23', "heat-map: black-red-yellow-white" ],
5473 heat2 => [ 'RGB', 'color rgbformulae 34, 35, 36', "heat-map (AFM): black-red-yellow-white" ],
5474 wheel => [ 'HSV', 'color rgbformulae 3,2,2', "hue map: color wheel" ],
5475 rgb => [ 'RGB', 'color rgbformulae 10,13,9', "red-green-blue fade" ],
5476 dop => [ 'RGB', "defined (0 '#ff0000', 0.5 '#ffffff', 1.0 '#0000ff')", "red-white-blue fade" ],
5477 dop2 => [ 'RGB', "defined (0 '#ff0000', 0.5 '#000000', 1.0 '#0000ff')", "red-black-blue fade" ],
5478 dop3 => [ 'RGB', "defined (0 '#ff9090', 0.4 '#503030', 0.5 '#000000', 0.6 '#303050', 1.0 '#9090ff')", "red-black-blue fade (gentler)" ],
5479 };
5480  
5481  
5482 ##############################
5483 # _parseOptHash
5484 #
5485 # Internal routine to parse a collection of options, given a collection of syntax
5486 # definitions and either an options hash ref or a listified hash.
5487 # Used for parsing/adding plot options...
5488 #
5489 # Call with the options hash to be written to, then with the Opt array ref (e.g. $pOpt global above),
5490 # then with the arguments. The $me is needed to feed to special-handling subs in the
5491 # OptionsTable.
5492  
5493 # _pOHTable: helper for _parseOptHash - handles the individual cases. Each sub
5494 # gets ($oldval, $param, $opts) and returns the parsed value (or barfs).
5495  
5496 3 our $_pOHInputs; # table of parser code snippets (declared at bottom)
5497  
5498 203 ▶sub _parseOptHash {
Subroutine _parseOptHash: called CC=16 SCAR=32.0
5499 203 ▶ my($options) = shift || {};
Condition100%2/2
shift() || {}
l!l
1994
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
5500 203 my($OptTable, $AbbrevTable, $name) = @{shift()};
5501 203 my @opts = @_;
5502  
5503 # Parse arguments one at a time. If the first one is a hash ref then
5504 # unpack it inline.
5505 203 ▶ opt: while(@opts) {
Branch: 1 branch
BranchTrueFalseTotal
if (@opts) 208 185 393
5506 # Pull the next key. If it turns out to be a hash, interpolate the hash into the list
5507 # of parameters. If it turns out to be a list, do likewise. Note that array refs that are
5508 # in a value slot are *not* interpolated.
5509 208 my $k = shift @opts;
5510 208 ▶ if(ref $k eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $k eq 'HASH') { } 62 146 208
elsif (ref $k eq 'ARRAY') { } 11 135 146
5511 62 unshift(@opts,%$k);
5512 62 $k = shift @opts;
5513 } elsif(ref $k eq 'ARRAY') {
5514 11 unshift(@opts,@$k);
5515 11 $k = shift @opts;
5516 }
5517  
5518 208 ▶ last opt unless defined($k);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $k 2 206 208
5519  
5520 # now pull the value.
5521 206 my $v = shift @opts;
5522  
5523 # Expand abbreviations and get the table entry for the option
5524 # (throws an exception on failure)
5525 206 my ($kk,$knum) = _expand_abbrev($k, $AbbrevTable, $name); # throws exception on failure
5526  
5527 # Evil DWIMmery. 'N' type parameters take a numeric argument that is
5528 # allowed to trail the keyword itself in the keyword part of the specifier.
5529 # So if we got a number we have to check that the corresponding keyword
5530 # in fact is 'N' type - else we leave the number in the keyword itself and
5531 # revalidate.
5532 192 ▶ if(defined $knum) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $knum) 1 191 192
5533 1 ▶ if($OptTable->{$kk}->[0] eq 'N') { # HARDWIRED-N parsing
Branch: 1 branch
BranchTrueFalseTotal
if ($OptTable->{$kk}[0] eq 'N') { } 1 0 1
5534 1 ▶ if(ref $v eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v eq 'ARRAY') { } 1 0 1
5535 1 unshift(@$v, $knum);
5536 } else {
5537 0 $v = [$knum, $v];
5538  
5539 }
5540 } else {
5541 0 $kk = "$kk$knum";
5542 0 $knum = undef;
5543 0 ▶ unless($AbbrevTable->{$kk}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($AbbrevTable->{$kk}) 0 0 0
5544 0 barf "Error: $name '$k' expanded to '$kk', which isn't a known keyword.\n";
5545 }
5546 }
5547 }
5548  
5549 192 my $TableEntry = $OptTable->{$kk};
5550  
5551 # Grab a parser code ref...
5552 192 my $parser = $TableEntry->[0];
5553 192 ▶ unless(ref $parser) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $parser) { } 38 154 192
if (do { ref $parser eq "ARRAY" }) 4 34 38
5554 154 my $p = $_pOHInputs->{$parser};
5555 154 ▶ unless(ref $p eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $p eq "CODE") 0 154 154
5556 0 barf "Unknown input type '$parser' found in option table entry for $kk! This is a bug.";
5557 }
5558 154 $parser = $p;
5559 0 } elsif(ref $parser eq 'ARRAY') {
5560 # If the parser entry is an array ref with one non-ref element only, it is a regexp to match
5561 # for successful enumeration. If it has more than one element, it is an enum list that
5562 # can be abbreviated.
5563 4 ▶ if(ref($parser->[0])) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $parser->[0]) { } 0 4 4
elsif (0 + @$parser == 1) { } 0 4 4
5564 0 barf("HELP! Parser is confused. This is a bug, please report it.\n");
5565 } elsif ( 0+@$parser == 1 ) {
5566 # An array ref with a single element - it's a regexp to match
5567 0 my $a = $parser->[0];
5568 0 ▶ $parser = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
5569 0 my ($old, $newparam, $hash) = @_;
5570 0 ▶ barf("Unknown field $newparam (must match m/$a/)\n") if $newparam !~ m/$a/;
Branch: 1 branch
BranchTrueFalseTotal
unless $newparam =~ /$a/ 0 0 0
5571 0 return $newparam;
5572 0 };
5573 } else {
5574 # An array ref with multiple elements - they are enums.
5575 # Make a temporary abbrev list for 'em.
5576 4 my $abbrevs = _gen_abbrev_list( @$parser );
5577 4 ▶ my $p = sub {
Subroutine __ANON__: called CC=2 SCAR=8.1
5578 4 my($old, $newparam, $hash) = @_;
5579 4 my $k = eval { _expand_abbrev($newparam, $abbrevs, "enumerated $kk option"); };
5580 4 ▶ if($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 4 4
5581 0 my $s = $@;
5582 0 undef $@;
5583 0 barf($s);
5584 }
5585 4 return $k;
5586 4 };
5587 4 $parser = $p;
5588 }
5589 }
5590  
5591 192 ▶ unless(ref $parser eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $parser eq "CODE") 0 192 192
5592 0 barf "HELP!";
5593 }
5594  
5595 192 $options->{$kk} = &$parser($options->{$kk}, $v, $options, $kk);
5596 }
5597 187 return $options;
5598 }
5599  
5600 ##############################
5601 #
5602 # Parse table
5603 #
5604 # $_pOHInputs describes input parsing from argument lists. Each key
5605 # is a code for a particular type of input; the value is a subroutine
5606 # that accepts ($old_value, $new_input, $options_hash, $fieldname) and returns the
5607 # parsed new value. Most of the parsers ignore fieldname, but it's passed in
5608 # so that, e.g., 'lt' can parse both major and minor tick values.
5609  
5610 3 our $footicsAbbrevs = _gen_abbrev_list(qw/axis border mirror in out scale rotate offset left right center autofreq locations labels format font rangelimited textcolor/ );
5611  
5612 $_pOHInputs = {
5613 ## Simple cases - boolean, number, scalar
5614 11 ▶ b => sub {return $_[1] if !defined $_[1]; $_[1] ? 1 : 0 },
Subroutine __ANON__: called CC=3 SCAR=11.1
Branch: 2 branches
BranchTrueFalseTotal
unless defined $_[1] 0 11 11
$_[1] ? : 6 5 11
5615 0 ▶ n => sub {return $_[1] if !defined $_[1]; $_[1] + 0 },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[1] 0 0 0
5616 26 ▶ s => sub {return $_[1] if !defined $_[1]; "$_[1]" },
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[1] 0 26 26
5617  
5618 ## one-line list (can also be boolean)
5619 66 ▶ l => sub { return $_[1] if !defined $_[1] or !length $_[1] or ref $_[1] eq 'ARRAY';
Subroutine __ANON__: called CC=6 SCAR=18.3
Branch: 1 branch
BranchTrueFalseTotal
if not defined $_[1] && length $_[1] or ref $_[1] eq "ARRAY" 3 63 66
Condition66%4/6
not defined $_[1] && length $_[1] or ref $_[1] eq "ARRAY"
l!l&&r!l&&!r
3063
defined $_[1] && length $_[1]
!ll&&!rl&&r
0363
MC/DC33%1/3
not defined $_[1] && length $_[1] or ref $_[1] eq "ARRAY"
defined $_[1] length $_[1] ref $_[1] eq "ARRAY"
Truth table50%2/4
not(A && B) or C
A= defined $_[1]B= length $_[1]C= ref $_[1] eq "ARRAY"
ABCresult
0XX1
10X1
1111
1100
5620 63 ▶ return $_[1] if !ref($_[1]) && "$_[1]" =~ m/^\s*\-?\d+\s*$/; # nonzero integers yield true
Branch: 1 branch
BranchTrueFalseTotal
if not ref $_[1] and "$_[1]" =~ /^\s*\-?\d+\s*$/ 2 61 63
Condition66%2/3
not ref $_[1] and "$_[1]" =~ /^\s*\-?\d+\s*$/
!ll&&!rl&&r
0612
MC/DC50%1/2
not ref $_[1] and "$_[1]" =~ /^\s*\-?\d+\s*$/
not ref $_[1] "$_[1]" =~ /^\s*\-?\d+\s*$/
Truth table66%2/3
not(A) and B
A= not ref $_[1]B= "$_[1]" =~ /^\s*\-?\d+\s*$/
ABresult
0X0
100
111
5621 # Not setting a boolean value - it's a list (or a trivial list).
5622 # anything that's not an array ref (and not a number) gets put in the array
5623 61 return [$_[1]];
5624 },
5625  
5626 ## one-line list (no booleanity: scalars always get copied to the list)
5627 21 ▶ ln => sub { return $_[1] if !defined $_[1] or !length $_[1] or ref $_[1] eq 'ARRAY';
Subroutine __ANON__: called CC=4 SCAR=14.9
Branch: 1 branch
BranchTrueFalseTotal
if not defined $_[1] && length $_[1] or ref $_[1] eq "ARRAY" 19 2 21
Condition50%3/6
not defined $_[1] && length $_[1] or ref $_[1] eq "ARRAY"
l!l&&r!l&&!r
0192
defined $_[1] && length $_[1]
!ll&&!rl&&r
0021
MC/DC33%1/3
not defined $_[1] && length $_[1] or ref $_[1] eq "ARRAY"
defined $_[1] length $_[1] ref $_[1] eq "ARRAY"
Truth table50%2/4
not(A && B) or C
A= defined $_[1]B= length $_[1]C= ref $_[1] eq "ARRAY"
ABCresult
0XX1
10X1
1111
1100
5628 2 return [$_[1]];
5629 },
5630  
5631 ## one-line list (can also be boolean or hash)
5632 2 ▶ lh => sub { return $_[1] if !defined $_[1] or !length $_[1]
Subroutine __ANON__: called CC=7 SCAR=31.2
Branch: 1 branch
BranchTrueFalseTotal
if not defined $_[1] && length $_[1] or ref $_[1] eq "ARRAY" or ref $_[1] eq "HASH" or not ref $_[1] and "$_[1]" =~ /^\s*\-?\d+\s*$/ 2 0 2
Condition26%4/15
not defined $_[1] && length $_[1] or ref $_[1] eq "ARRAY" or ref $_[1] eq "HASH" or not ref $_[1] and "$_[1]" =~ /^\s*\-?\d+\s*$/
l!l&&r!l&&!r
200
not defined $_[1] && length $_[1] or ref $_[1] eq "ARRAY" or ref $_[1] eq "HASH"
l!l&&r!l&&!r
020
not defined $_[1] && length $_[1] or ref $_[1] eq "ARRAY"
l!l&&r!l&&!r
002
defined $_[1] && length $_[1]
!ll&&!rl&&r
002
not ref $_[1] and "$_[1]" =~ /^\s*\-?\d+\s*$/
!ll&&!rl&&r
000
MC/DC0%0/6
not defined $_[1] && length $_[1] or ref $_[1] eq "ARRAY" or ref $_[1] eq "HASH" or not ref $_[1] and "$_[1]" =~ /^\s*\-?\d+\s*$/
defined $_[1] length $_[1] ref $_[1] eq "ARRAY" ref $_[1] eq "HASH" not ref $_[1] "$_[1]" =~ /^\s*\-?\d+\s*$/
Truth table14%1/7
not(A && B) or C or D or not(E) and F
A= defined $_[1]B= length $_[1]C= ref $_[1] eq "ARRAY"D= ref $_[1] eq "HASH"E= not ref $_[1]F= "$_[1]" =~ /^\s*\-?\d+\s*$/
ABCDEFresult
0XXXXX1
10XXXX1
111XXX1
1101XX1
1100111
11000X0
1100100
5633 or ref $_[1] eq 'ARRAY' or ref $_[1] eq 'HASH'
5634 or ((!ref($_[1])) && "$_[1]" =~ m/^\s*\-?\d+\s*$/); # nonzero integers yield true
5635 # Not setting a boolean value - it's a list (or a trivial list).
5636 0 return [$_[1]];
5637 },
5638  
5639 ## list or 2-PDL for a range parameter
5640 22 ▶ lr => sub { return $_[1] if !defined $_[1] or !length $_[1]
Subroutine __ANON__: called CC=9 SCAR=25.5
Branch: 1 branch
BranchTrueFalseTotal
if not defined $_[1] && length $_[1] or not ref $_[1] and "$_[1]" =~ /^\s*\-?\d+\s*$/ or ref $_[1] eq "ARRAY" 20 2 22
Condition41%5/12
not defined $_[1] && length $_[1] or not ref $_[1] and "$_[1]" =~ /^\s*\-?\d+\s*$/ or ref $_[1] eq "ARRAY"
l!l&&r!l&&!r
0202
not defined $_[1] && length $_[1] or not ref $_[1] and "$_[1]" =~ /^\s*\-?\d+\s*$/
l!l&&r!l&&!r
0022
defined $_[1] && length $_[1]
!ll&&!rl&&r
0022
not ref $_[1] and "$_[1]" =~ /^\s*\-?\d+\s*$/
!ll&&!rl&&r
2200
MC/DC20%1/5
not defined $_[1] && length $_[1] or not ref $_[1] and "$_[1]" =~ /^\s*\-?\d+\s*$/ or ref $_[1] eq "ARRAY"
defined $_[1] length $_[1] not ref $_[1] "$_[1]" =~ /^\s*\-?\d+\s*$/ ref $_[1] eq "ARRAY"
Truth table28%2/7
not(A && B) or not(C) and D or E
A= defined $_[1]B= length $_[1]C= not ref $_[1]D= "$_[1]" =~ /^\s*\-?\d+\s*$/E= ref $_[1] eq "ARRAY"
ABCDEresult
0XXXX1
10XXX1
1111X1
110X11
111011
110X00
111000
5641 or ((!ref($_[1])) && "$_[1]" =~ m/^\s*\-?\d+\s*$/) # nonzero integers yield true
5642 # Not setting a boolean value - it's a list (or a trivial list).
5643 or ref $_[1] eq 'ARRAY';
5644 2 ▶ return [$_[1]] if !$_[1]->$_isa('PDL');
Branch: 1 branch
BranchTrueFalseTotal
unless $_[1]->$PDL::Graphics::Gnuplot::_isa("PDL") 0 2 2
5645 2 ▶ barf "PDL::Graphics::Gnuplot: range parser found a PDL, but it wasn't a 2-PDL (max,min)"
Branch: 1 branch
BranchTrueFalseTotal
unless $_[1]->dims == 1 and $_[1]->nelem == 2 1 1 2
Condition66%2/3
$_[1]->dims == 1 and $_[1]->nelem == 2
!ll&&!rl&&r
011
MC/DC50%1/2
$_[1]->dims == 1 and $_[1]->nelem == 2
$_[1]->dims == 1 $_[1]->nelem == 2
Truth table66%2/3
A and B
A= $_[1]->dims == 1B= $_[1]->nelem == 2
ABresult
0X0
100
111
5646 unless( $_[1]->dims==1 and $_[1]->nelem==2 );
5647 1 return [$_[1]->list];
5648 },
5649  
5650 ## cumulative list (delete on "undef")
5651 0 ▶ C => sub { return $_[1] if !defined $_[1];
Subroutine __ANON__: not called CC=7 SCAR=40.3
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[1] 0 0 0
5652 0 ▶ return 0 unless($_[1]); # false value yields false
Branch: 1 branch
BranchTrueFalseTotal
unless $_[1] 0 0 0
5653 0 ▶ return 1 if( $_[1] && "$_[1]" =~ m/^\s*-?\d+\s*$/); # nonzero integers yield true
Branch: 1 branch
BranchTrueFalseTotal
if $_[1] and "$_[1]" =~ /^\s*-?\d+\s*$/ 0 0 0
Condition0%0/3
$_[1] and "$_[1]" =~ /^\s*-?\d+\s*$/
!ll&&!rl&&r
000
MC/DC0%0/2
$_[1] and "$_[1]" =~ /^\s*-?\d+\s*$/
$_[1] "$_[1]" =~ /^\s*-?\d+\s*$/
Truth table0%0/3
A and B
A= $_[1]B= "$_[1]" =~ /^\s*-?\d+\s*$/
ABresult
0X0
100
111
5654 # Not setting a boolean value - it's a list, so append it.
5655 0 ▶ my $out = (ref $_[0] eq 'ARRAY') ? $_[0] : [];
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 0 0 0
5656 0 ▶ push @$out, ref $_[1] eq 'ARRAY' ? $_[1] : [ split ( /\s+/, $_[1] ) ];
Branch: 1 branch
BranchTrueFalseTotal
ref $_[1] eq 'ARRAY' ? : 0 0 0
5657 0 return $out;
5658 },
5659  
5660 ## set hash values
5661 0 ▶ H => sub { return $_[1] if !defined $_[1];
Subroutine __ANON__: not called CC=8 SCAR=42.8
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[1] 0 0 0
5662 0 ▶ my $out = (ref $_[0] eq 'HASH') ? $_[0] : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
5663 0 my $in = $_[1];
5664 0 ▶ $in = {@$in} if ref $in eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $in eq "ARRAY" 0 0 0
5665 0 ▶ if (ref($in) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $in eq 'HASH') { } 0 0 0
5666 0 for my $k (keys %{$_[1]}) {
5667 0 $out->{$k} = $_[1]->{$k};
5668 }
5669 } else {
5670 # scalar or <mumble>...
5671 0 ▶ if ( $in =~ m/([^\s]+)\s+(.*)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in =~ /([^\s]+)\s+(.*)$/) { } 0 0 0
5672 # key/value found
5673 0 $out->{$1} = $2;
5674 } else {
5675 # at most a key found. If nothing, clear the hash
5676 0 ▶ return undef unless($in =~ s/^\s*([^\s]+)\s*$/$1/);
Branch: 1 branch
BranchTrueFalseTotal
unless $in =~ s/^\s*([^\s]+)\s*$/$1/ 0 0 0
5677 # A key was found. Set a nonempty value so that "set foo $k" gets emitted
5678 0 $out->{$1} = " ";
5679 }
5680 }
5681 0 return $out;
5682 },
5683  
5684 ## number-indexed list
5685 ##
5686 2 ▶ N => sub { my($old,$new,$h) = @_;
Subroutine __ANON__: called CC=10 SCAR=25.7
5687 2 ▶ return $_[1] if !defined $_[1];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[1] 0 2 2
5688 2 ▶ my $out = (ref($old) eq 'ARRAY') ? $old : [];
Branch: 1 branch
BranchTrueFalseTotal
ref $old eq 'ARRAY' ? : 0 2 2
5689  
5690 # Split strings into lists if necessary.
5691 2 ▶ $new = [ split(/\s+/,$new) ] unless(ref($new) eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $new eq "ARRAY" 0 2 2
5692  
5693 # Check for nested lists -- multiple specs.
5694 2 ▶ if(ref($new->[0]) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $new->[0] eq 'ARRAY') { } 1 1 2
5695 1 my $o = [];
5696 1 for my $l(@$new) {
5697 1 ▶ unless(ref $l eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $l eq "ARRAY") 0 1 1
5698 0 die "Markup option: nested lists must contain only array refs\n";
5699 }
5700 1 push(@$o, [@$l]);
5701 }
5702 1 $out = $o;
5703 } else {
5704 # not a nested list - look for an index number at the start.
5705 1 my $dex;
5706 1 ▶ if($new->[0] =~ m/^\s*(\d+)\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new->[0] =~ /^\s*(\d+)\s*$/) { } 1 0 1
5707 1 $dex = 0 + shift(@$new);
5708 } else {
5709 0 ▶ $dex = scalar(@$out) || 1;
Condition0%0/2
scalar @$out || 1
l!l
00
MC/DC0%0/1
scalar @$out || 1
scalar @$out
Truth table0%0/2
A
A= scalar @$out
Aresult
11
00
5710 }
5711 1 ▶ if(@$new) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$new) { } 1 0 1
5712 1 $out->[$dex] = $new;
5713 } else {
5714 0 $out->[$dex] = undef;
5715 }
5716 }
5717 2 return $out;
5718 },
5719  
5720 ## <foo>tics option list
5721 ## (For valid hash keys, see footicsAbbrevs definition above)
5722 4 ▶ lt => sub { my($old, $new, $h, $fieldname) = @_;
Subroutine __ANON__: called CC=14 SCAR=29.9
5723 4 ▶ return $_[1] if !defined $_[1];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[1] 0 4 4
5724 4 ▶ return 0 unless($new);
Branch: 1 branch
BranchTrueFalseTotal
unless $new 1 3 4
5725 3 ▶ if ( ref($new) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $new eq "HASH") 1 2 3
5726 1 my %h = ();
5727 1 for my $k(keys %$new) {
5728 0 my $k2 = _expand_abbrev($k, $footicsAbbrevs, "<foo>tics option");
5729 barf "Error: '$k' expanded to '$k2', which already exists in <foo>tics option"
5730 0 ▶ if exists $h{$k2};
Branch: 1 branch
BranchTrueFalseTotal
if exists $h{$k2} 0 0 0
5731 0 $h{$k2} = $new->{$k};
5732 }
5733 1 return \%h;
5734 }
5735 2 ▶ barf "Error: <foo>tics options require a scalar or a hash ref"
Branch: 1 branch
BranchTrueFalseTotal
if ref $new and ref $new ne "ARRAY" 0 2 2
Condition66%2/3
ref $new and ref $new ne "ARRAY"
!ll&&!rl&&r
110
MC/DC0%0/2
ref $new and ref $new ne "ARRAY"
ref $new ref $new ne "ARRAY"
Truth table66%2/3
A and B
A= ref $newB= ref $new ne "ARRAY"
ABresult
0X0
100
111
5736 if ref($new) and ref($new) ne 'ARRAY';
5737 2 ▶ my @list = ref($new) ? @$new : map { s/^\s+//; s/\s+$//; split /\s*[\s\,]\s*/ } $new;
Branch: 1 branch
BranchTrueFalseTotal
ref $new ? : 1 1 2
5738 2 ▶ return {} if !@list;
Branch: 1 branch
BranchTrueFalseTotal
unless @list 1 1 2
5739 # We don't fully parse gnuplot lines -- but we do
5740 # check for the simple numeric case -- if it's correct,
5741 # turn the array ref into a hash for future manipulability.
5742 1 ▶ if(@list > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (@list > 3) 0 1 1
5743 0 carp "Warning - explicit string or array refs are deprecated in tic specs\n";
5744 0 return [@list];
5745 }
5746 1 my $num_ok = 0;
5747 1 for my $i(0..$#list) {
5748 1 ▶ $num_ok++ if($list[$i] =~ s/^(\-?\d+(\.\d*)?([eE][\+\-]?\d+)?)(\s*\,\s*)?$/$1/);
Branch: 1 branch
BranchTrueFalseTotal
if $list[$i] =~ s/^(\-?\d+(\.\d*)?([eE][\+\-]?\d+)?)(\s*\,\s*)?$/$1/ 1 0 1
5749 }
5750 1 ▶ return {locations=>\@list} if $num_ok == @list; # Hashify if possible
Branch: 1 branch
BranchTrueFalseTotal
if $num_ok == @list 1 0 1
5751 0 carp "Warning - explicit list or string gnuplot commands are deprecated in tic specs\n";
5752 0 return \@list;
5753 },
5754  
5755 ## dashtype option
5756 0 ▶ dt => sub { my($old, $new, $h, $fieldname) = @_;
Subroutine __ANON__: not called CC=4 SCAR=30.0
5757 0 ▶ if($gp_version < 5.0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PDL::Graphics::Gnuplot::gp_version < 5) 0 0 0
5758 0 carp "WARNING: 'dashtype' is not supported by your <5.0 gnuplot. Ignoring...\n";
5759 0 return $old;
5760 }
5761 0 ▶ barf "Error: dashtype curve option requires a scalar or an array ref"
Branch: 1 branch
BranchTrueFalseTotal
if ref $new and ref $new ne "ARRAY" 0 0 0
Condition0%0/3
ref $new and ref $new ne "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $new and ref $new ne "ARRAY"
ref $new ref $new ne "ARRAY"
Truth table0%0/3
A and B
A= ref $newB= ref $new ne "ARRAY"
ABresult
0X0
100
111
5762 if ref $new and ref $new ne 'ARRAY';
5763 0 return $new;
5764 },
5765 3 };
5766  
5767  
5768 ##############################
5769 # _emitOpts
5770 #
5771 # Accepts an options table as a single hash ref, and emits a corresponding
5772 # string that is suitable for passing on to gnuplot. Curve options and
5773 # plot options use different output specifiers and can therefore both be
5774 # handled by one routine.
5775 #
5776 # Because curve and plot options have different parse tables, you have to
5777 # pass in the parse table ref appropriate to the type of option you're emitting.
5778  
5779 208 ▶sub _emitOpts {
Subroutine _emitOpts: called CC=13 SCAR=26.3
5780 208 my ($options, $tab, $this) = @_;
5781 208 my $table = $tab->[0];
5782 208 our $_OptionEmitters;
5783  
5784 # Sort the keys into options table order -- this is so that keys that are supposed
5785 # to be up top go up top; keys with no particular order defined in the parse table
5786 # are allowed to stay in random order.
5787 #
5788 # Keys that are supposed to be at bottom (if any in future) can be
5789 # placed there by the expedient of assigning them sort values in excess of 1,000.
5790 #
5791 208 ▶ my @keys = sort { ((defined $table->{$a}->[3])?($table->{$a}->[3]): 999) <=> ((defined $table->{$b}->[3])?($table->{$b}->[3]):999) or
Branch: 2 branches
BranchTrueFalseTotal
defined $table->{$a}[3] ? : 1013 815 1828
defined $table->{$b}[3] ? : 1004 824 1828
Condition66%2/3
(defined $table->{$a}[3] ? $table->{$a}[3] : 999) <=> (defined $table->{$b}[3] ? $table->{$b}[3] : 999) || $a cmp $b
l!l&&r!l&&!r
12156130
MC/DC0%0/2
(defined $table->{$a}[3] ? $table->{$a}[3] : 999) <=> (defined $table->{$b}[3] ? $table->{$b}[3] : 999) || $a cmp $b
(defined $table->{$a}[3] ? $table->{$a}[3] : 999) <=> (defined $table->{$b}[3] ? $table->{$b}[3] : 999) $a cmp $b
Truth table66%2/3
A || B
A= (defined $table->{$a}[3] ? $table->{$a}[3] : 999) <=> (defined $table->{$b}[3] ? $table->{$b}[3] : 999)B= $a cmp $b
ABresult
1X1
011
000
5792 ($a cmp $b)
5793 } keys %$options;
5794  
5795 208 my $s = "";
5796  
5797  
5798 # Loop over the keys and emit.
5799 208 ▶ key: while(@keys) {
Branch: 1 branch
BranchTrueFalseTotal
if (@keys) 1102 208 1310
5800 1102 my $k = shift @keys;
5801  
5802 1102 my $tableEntry = $table->{$k};
5803 1102 ▶ if(!defined($tableEntry)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tableEntry) 0 1102 1102
5804 0 barf "_emitOpts: bad table entry for keyword '$k'";
5805 }
5806  
5807 ## Cheesy ordering logic here -- if the parse table indicates that we have to go after
5808 ## a particular option, walk back from the end until we find one of them or get to the
5809 ## front of the queue. If we find a match, we splice the current one back there and move
5810 ## on to the next key.
5811 1102 ▶ if($tableEntry->[2]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tableEntry->[2]) 24 1078 1102
5812 24 my %h = (map { ($_, 1) } @{$tableEntry->[2]}); # make a hash of later-than keywords, with 1 in each entry
5813 24 for my $i(reverse 0..$#keys) {
5814 129 ▶ if($h{$keys[$i]}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h{$keys[$i]}) 2 127 129
5815 2 splice(@keys,$i+1,0,$k);
5816 2 next key;
5817 }
5818 }
5819 }
5820  
5821 ## Rubber meets the road -- call the corresponding output function
5822 1100 ▶ my $emitter = $tableEntry->[1] || " ";
Condition50%1/2
$tableEntry->[1] || ' '
l!l
11000
MC/DC0%0/1
$tableEntry->[1] || ' '
$tableEntry->[1]
Truth table50%1/2
A
A= $tableEntry->[1]
Aresult
11
00
5823 1100 ▶ unless(ref $emitter) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $emitter) { } 490 610 1100
if (do { ref $emitter ne "CODE" }) 0 490 490
5824 610 my $o = $_OptionEmitters->{$emitter};
5825 610 ▶ unless( ref $o eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $o eq "CODE") 0 610 610
5826 0 barf "Unknown output type '$emitter' found in option table entry for $k!";
5827 }
5828 610 $emitter = $o;
5829 0 } elsif(ref $emitter ne 'CODE') {
5830 0 barf 'PLEH!';
5831 }
5832  
5833 1100 $s .= &$emitter($k, $options->{$k}, $options, $this)
5834 }
5835  
5836 208 return $s;
5837 }
5838  
5839  
5840 ##############################
5841 # Emitter table folows. Colorspecs are so
5842 # complicated that they get their own helper routine,
5843 # _emit_colorspec.
5844 #
5845 0 ▶sub _emit_colorspec {
Subroutine _emit_colorspec: not called CC=10 SCAR=47.0
5846 0 my $v = shift;
5847  
5848 0 my @words;
5849 0 ▶ unless(ref($v)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $v) { } 0 0 0
if (do { ref $v eq 'ARRAY' }) { } 0 0 0
5850 0 $v =~ s/^\s+//;
5851 0 $v =~ s/\s+$//;
5852 0 @words = split /\s+/, $v;
5853 } elsif(ref($v) eq 'ARRAY') {
5854 0 ▶ if(@$v > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$v > 1) { } 0 0 0
5855 0 @words = @$v;
5856 } else {
5857 0 $v->[0] =~ s/^\s+//;
5858 0 $v->[0] =~ s/\s+$//;
5859 0 @words = split /\s+/, $v->[0];
5860 }
5861 } else {
5862 0 die "colorspec: only scalar and ARRAY values are supported for colors";
5863 }
5864  
5865 0 my $s = "";
5866 0 ▶ $s .= shift @words if(lc($words[0]) eq 'rgb');
Branch: 1 branch
BranchTrueFalseTotal
if lc $words[0] eq "rgb" 0 0 0
5867  
5868 0 ▶ if( $words[0] =~ s/\"?(\#[0-9a-fA-F]{6})\"?/\"$1\"/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($words[0] =~ s/\"?(\#[0-9a-fA-F]{6})\"?/"$1"/) 0 0 0
5869 0 ▶ $s .= " rgb " unless($s =~ m/rgb/);
Branch: 1 branch
BranchTrueFalseTotal
unless $s =~ /rgb/ 0 0 0
5870 0 $s .= " ".join(" ",@words);
5871 0 return $s;
5872 }
5873 0 ▶ if($PDL::Graphics::Gnuplot::colornames->{lc($words[0])}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$PDL::Graphics::Gnuplot::colornames{lc $words[0]}) 0 0 0
5874 0 ▶ $s .= " rgb " unless($s =~ m/rgb/);
Branch: 1 branch
BranchTrueFalseTotal
unless $s =~ /rgb/ 0 0 0
5875 0 $s .= " \"$words[0] \" ";
5876 0 shift @words;
5877 0 $s .= join(" ",@words)." ";
5878 0 return $s;
5879 }
5880 0 ▶ return join(" ",($s,@words,"")) if $words[0] =~ m/(^[0-9]+$)|(variable)|(palette)/;
Branch: 1 branch
BranchTrueFalseTotal
if $words[0] =~ /(^[0-9]+$)|(variable)|(palette)/ 0 0 0
5881 0 die <<"EOD";
5882 0 PDL::Graphics::Gnuplot: Unknown color spec '@{[join(" ",@words)]}'.
5883 Use an integer, an '#RRGGBB' spec, 'variable', 'palette', or a name from
5884 the list in \@PDL::Graphics::Gnuplot::colornames.
5885 EOD
5886 }
5887  
5888 ##############################
5889 #
5890 # Emission table
5891 #
5892 # $_OptionEmitters describes how to emit stored parameters. Each
5893 # key is a code for a particular type of output; the value is a subroutine
5894 # that returns the outputted parameter as a string.
5895 #
5896 # Different codes emit whole lines (e.g. for setting plot options) or
5897 # space-delimited words (e.g. for setting curve options). Curve
5898 # option emitters have codes that start with 'c'.
5899 #
5900 # Although most of the emitters take just (keyword, value, options-hash),
5901 # they may take a fourth parameter containing the complete object.
5902 # That's useful for things like "crange", which needs to know the global
5903 # options state to know how to emit itself.
5904  
5905 our $_OptionEmitters = {
5906 #### Default output -- a collection of terms with spaces between them as a plot option
5907 0 ▶ ' ' => sub { my($k,$v,$h) = @_;
Subroutine __ANON__: not called CC=4 SCAR=30.0
5908 0 ▶ return "" unless(defined($v));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
5909 0 ▶ join(" ","set",$k,
Branch: 2 branches
BranchTrueFalseTotal
ref $v eq 'ARRAY' ? : 0 0 0
ref $v eq 'HASH' ? : 0 0 0
5910 ref $v eq 'ARRAY' ? (grep defined, @$v) :
5911 ref $v eq 'HASH' ? %$v : $v
5912 )."\n";
5913 },
5914  
5915 #### nomulti -- a default style plot option that is ignored in multiplot mode
5916 89 ▶ 'nomulti' => sub { my($k,$v,$h) = @_;
Subroutine __ANON__: called CC=5 SCAR=16.8
5917 89 ▶ return "" unless((defined($v)) and !($h->{multiplot}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v and not $h->{"multiplot"} 4 85 89
Condition66%2/3
defined $v and not $h->{"multiplot"}
!ll&&!rl&&r
0485
MC/DC50%1/2
defined $v and not $h->{"multiplot"}
defined $v not $h->{"multiplot"}
Truth table66%2/3
A and not(B)
A= defined $vB= not $h->{"multiplot"}
ABresult
0X0
100
111
5918 85 ▶ join(" ","set",$k,
Branch: 2 branches
BranchTrueFalseTotal
ref $v eq 'ARRAY' ? : 0 85 85
ref $v eq 'HASH' ? : 0 85 85
5919 ref $v eq 'ARRAY' ? (grep defined, @$v) :
5920 ref $v eq 'HASH' ? %$v : $v
5921 )."\n";
5922 },
5923  
5924 #### Empty output - return nothing.
5925 23 ▶ '-' => sub { "" },
Subroutine __ANON__: called CC=1 SCAR=0.0
5926  
5927 #### A quoted scalar value as a plot option
5928 3 ▶ 'q' => sub { my($k,$v,$h) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.3
5929 3 ▶ return "" unless(defined($v));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 3 3
5930 3 ▶ return "unset $k\n" unless(length($v));
Branch: 1 branch
BranchTrueFalseTotal
unless length $v 0 3 3
5931 3 $v = quote_escape($v);
5932 3 return "set $k \"$v\"\n";
5933 },
5934  
5935 #### A quoted scalar value as a plot option, not emitted in multiplot mode
5936 0 ▶ 'qnm' => sub { my($k,$v,$h) = @_;
Subroutine __ANON__: not called CC=4 SCAR=30.0
5937 0 ▶ return "" unless((defined($v) and !($h->{multiplot})));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v and not $h->{"multiplot"} 0 0 0
Condition0%0/3
defined $v and not $h->{"multiplot"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $v and not $h->{"multiplot"}
defined $v not $h->{"multiplot"}
Truth table0%0/3
A and not(B)
A= defined $vB= not $h->{"multiplot"}
ABresult
0X0
100
111
5938 0 ▶ return "unset $k\n" unless(length($v));
Branch: 1 branch
BranchTrueFalseTotal
unless length $v 0 0 0
5939 0 $v = quote_escape($v);
5940 0 return "set $k \"$v\"\n";
5941 },
5942  
5943 #### A quoted scalar value as a curve option
5944 0 ▶ 'cq' => sub { my($k,$v,$h) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
5945 0 ▶ return "" unless(defined($v));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
5946 0 my($vv) = quote_escape($v);
5947 0 return " $k \"$vv\" ";
5948 },
5949  
5950 #### A quoted scalar font value as a curve option.
5951 #### This differs from cq alone in that it parses font size,
5952 #### scaling it for anti-aliasing as necessary.
5953 #### the 'aa' parameter is passed in $h since this is called
5954 #### by the term option emitter in output().
5955 0 ▶ 'cqf' => sub { my($k,$v,$h) = @_;
Subroutine __ANON__: not called CC=4 SCAR=30.0
5956 0 ▶ return "" unless(defined($v));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
5957 0 ▶ if($h->{aa} && $v =~ m/(.*)\,(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h->{"aa"} and $v =~ /(.*)\,(.*)/) 0 0 0
Condition0%0/3
$h->{"aa"} and $v =~ /(.*)\,(.*)/
!ll&&!rl&&r
000
MC/DC0%0/2
$h->{"aa"} and $v =~ /(.*)\,(.*)/
$h->{"aa"} $v =~ /(.*)\,(.*)/
Truth table0%0/3
A and B
A= $h->{"aa"}B= $v =~ /(.*)\,(.*)/
ABresult
0X0
100
111
5958 0 my ($name,$size) = ($1,$2);
5959 0 $size *= $h->{aa};
5960 0 $v = "$name,$size";
5961 }
5962 0 my($vv) = quote_escape($v);
5963 0 return " $k \"$vv\" ";
5964 },
5965  
5966 #### A value with no associated keyword
5967 0 ▶ 'cv' => sub { my($k,$v,$h) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
5968 0 ▶ return " $v " if(defined($v));
Branch: 1 branch
BranchTrueFalseTotal
if defined $v 0 0 0
5969 0 return "";
5970 },
5971  
5972 #### A nonquoted scalar value as a plot option
5973 4 ▶ 's' => sub { my($k,$v,$h) = @_;
Subroutine __ANON__: called CC=4 SCAR=14.6
5974 4 ▶ return "" unless(defined($v));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 4 4
5975 4 ▶ return "unset $k\n" unless(length($v));
Branch: 1 branch
BranchTrueFalseTotal
unless length $v 0 4 4
5976 4 ▶ return "set $k" if($v eq ' ');
Branch: 1 branch
BranchTrueFalseTotal
if $v eq " " 0 4 4
5977 4 return "set $k $v\n";
5978 },
5979  
5980 #### A nonquoted scalar value as a curve option
5981 0 ▶ 'cs' => sub { my($k,$v,$h) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
5982 0 ▶ return "" unless(defined($v));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
5983 0 return " $k $v ";
5984 },
5985  
5986 #### A nonquoted antialias-scaled scalar value as a curve option
5987 3 ▶ 'css' => sub { my($k,$v,$h,$this) = @_;
Subroutine __ANON__: called CC=4 SCAR=16.4
5988 3 ▶ return "" unless(defined($v));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 3 3
5989 3 ▶ if($this->{aa} && $v=~m/^[\+\-0-9,.E]+$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"aa"} and $v =~ /^[\+\-0-9,.E]+$/i) 0 3 3
Condition33%1/3
$this->{"aa"} and $v =~ /^[\+\-0-9,.E]+$/i
!ll&&!rl&&r
030
MC/DC0%0/2
$this->{"aa"} and $v =~ /^[\+\-0-9,.E]+$/i
$this->{"aa"} $v =~ /^[\+\-0-9,.E]+$/i
Truth table33%1/3
A and B
A= $this->{"aa"}B= $v =~ /^[\+\-0-9,.E]+$/i
ABresult
0X0
100
111
5990 0 $v *= $this->{aa};
5991 }
5992 3 return " $k $v ";
5993 },
5994  
5995  
5996 #### The dashtype curve option
5997 #### Supports an INVALID value for "with" types that have to suppress dt emission.
5998 #### This is because some "withs" (e.g. "lines") must have dt specifiers for the correct behavior,
5999 #### but other "withs" (e.g. "labels") barf if dt is specified.
6000 92 ▶ 'dt' => sub { my($k,$v,$h, $w) = @_;
Subroutine __ANON__: called CC=10 SCAR=33.9
6001 92 ▶ return "" unless($gp_numversion >= 5.0);
Branch: 1 branch
BranchTrueFalseTotal
unless $PDL::Graphics::Gnuplot::gp_numversion >= 5 0 92 92
6002 92 ▶ return "" if(($v//"") eq 'INVALID');
Branch: 1 branch
BranchTrueFalseTotal
if ($v // "") eq "INVALID" 1 91 92
Condition100%2/2
$v // ""
l!l
191
MC/DC100%1/1
$v // ""
$v
Truth table100%2/2
A
A= $v
Aresult
11
00
6003 91 ▶ unless($v) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($v) 91 0 91
6004 91 ▶ if($w->{options}{terminal} =~ m/dashed/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($w->{'options'}{'terminal'} =~ /dashed/) { } 0 91 91
6005 0 ▶ $w->{last_dashtype} //= 0;
Condition0%0/2
$w->{"last_dashtype"} //= 0
l!l
00
MC/DC0%0/1
$w->{"last_dashtype"} //= 0
$w->{"last_dashtype"}
Truth table0%0/2
A
A= $w->{"last_dashtype"}
Aresult
11
00
6006 0 return " dt ".(++$w->{last_dashtype})." ";
6007 } else {
6008 91 return " dt solid ";
6009 }
6010 }
6011 0 ▶ return " dt solid " unless($v);
Branch: 1 branch
BranchTrueFalseTotal
unless $v 0 0 0
6012 0 ▶ return " dt (".(join(@$v,",")).") " if(ref($v) eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if ref $v eq "ARRAY" 0 0 0
6013 0 ▶ return " dt $v " if($v=~ m/\d+/);
Branch: 1 branch
BranchTrueFalseTotal
if $v =~ /\d+/ 0 0 0
6014 0 $v = quote_escape($v);
6015 0 return " dt \"$v\" ";
6016 },
6017  
6018 ### A curve flag in one word
6019 0 ▶ 'cf' => sub { my($k,$v,$h) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
6020 0 ▶ return "" unless(defined($v));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
6021 0 ▶ return " no$k " unless($v);
Branch: 1 branch
BranchTrueFalseTotal
unless $v 0 0 0
6022 0 return " $k ";
6023 },
6024 1 ▶ 'cff'=> sub { my($k, $v, $h) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.1
6025 1 ▶ return "" unless($v);
Branch: 1 branch
BranchTrueFalseTotal
unless $v 0 1 1
6026 1 return " $k ";
6027 },
6028  
6029 ### A size specification (used in terminal options in the constructor, see $termTab)
6030 ### generally a list with (width, height, [units]) in it. Should have been parsed as an 'l'.
6031 15 ▶ 'csize'=> sub { my($k, $v, $h) = @_;
Subroutine __ANON__: called CC=9 SCAR=23.5
6032 15 our $lConv; # unit conversion hash (see below)
6033 15 ▶ return "" unless($v and @$v);
Branch: 1 branch
BranchTrueFalseTotal
unless $v and @$v 0 15 15
Condition33%1/3
$v and @$v
!ll&&!rl&&r
0015
MC/DC0%0/2
$v and @$v
$v @$v
Truth table33%1/3
A and B
A= $vB= @$v
ABresult
0X0
100
111
6034 15 my @v = @$v;
6035 15 my $conv = 1;
6036 15 ▶ if($h->{__unit__}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h->{"__unit__"}) 15 0 15
6037 die "Uh-oh -- csize parser found an error -- table says default units are '$h->{__unit__}' but that's no unit!\n"
6038 15 ▶ if !$lConv->{$h->{__unit__}};
Branch: 1 branch
BranchTrueFalseTotal
unless $$PDL::Graphics::Gnuplot::lConv{$h->{"__unit__"}} 0 15 15
6039 15 $conv *= $lConv->{$h->{__unit__}};
6040 }
6041 # If there's a unit spec at the end, pop if off and accumulate the conversion factor
6042 15 ▶ if($lConv->{$v[$#v]}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$PDL::Graphics::Gnuplot::lConv{$v[$#v]}) 10 5 15
6043 10 $conv /= $lConv->{ pop @v };
6044 }
6045 15 ▶ if(@v==1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@v == 1) 1 14 15
6046 1 @v = ($v[0],$v[0]);
6047 }
6048 15 ▶ if(@v > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@v > 2) 0 15 15
6049 0 die "Too many values, or an unrecognized unit, in size spec '".join(",",@$v)."'\n";
6050 }
6051 # Deal with anti-aliasing: oversize the window if aa exists.
6052 15 ▶ if($h->{aa}){
Branch: 1 branch
BranchTrueFalseTotal
if ($h->{"aa"}) 0 15 15
6053 0 $conv *= $h->{aa};
6054 }
6055 15 return( " size ".($v[0]*$conv).",".$v[1]*$conv." " );
6056  
6057 },
6058  
6059 ### A color specification as a curve option
6060 0 ▶ 'ccolor' => sub { my($k,$v,$h) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
6061 0 ▶ return "" unless($v);
Branch: 1 branch
BranchTrueFalseTotal
unless $v 0 0 0
6062 0 return " $k "._emit_colorspec($v);
6063 },
6064  
6065  
6066 #### A boolean value as a plot option
6067 0 ▶ 'b' => sub { my($k,$v,$h) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
6068 0 ▶ return "" unless defined($v);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
6069 0 ▶ return $v ? "set $k\n" : "unset $k\n";
Branch: 1 branch
BranchTrueFalseTotal
$v ? : 0 0 0
6070 },
6071  
6072 #### A boolean value as an inline option (e.g. curve, terminal)
6073 0 ▶ 'byn' => sub { my($k,$v,$g) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
6074 0 ▶ return "" unless defined($v);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
6075 0 ▶ return $v ? " $k " : " no$k ";
Branch: 1 branch
BranchTrueFalseTotal
$v ? : 0 0 0
6076 },
6077  
6078 #### A boolean or 'time' (for <foo>data plot options)
6079 3 ▶ 'bt' => sub { my($k,$v,$h) = @_;
Subroutine __ANON__: called CC=3 SCAR=13.3
6080 3 ▶ return "set $k\n" unless ($v and $v=~m/^t/i);
Branch: 1 branch
BranchTrueFalseTotal
unless $v and $v =~ /^t/i 0 3 3
Condition33%1/3
$v and $v =~ /^t/i
!ll&&!rl&&r
003
MC/DC0%0/2
$v and $v =~ /^t/i
$v $v =~ /^t/i
Truth table33%1/3
A and B
A= $vB= $v =~ /^t/i
ABresult
0X0
100
111
6081 0 return "set $k $v\n";rxt hel
6082 },
6083  
6084 #### A space-separated collection of terms as a plot option
6085 87 ▶ 'l' => sub { my($k,$v,$h) = @_;
Subroutine __ANON__: called CC=5 SCAR=16.7
6086 87 ▶ return "" unless(defined($v));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 87 87
6087 87 ▶ return "set $k ".join(" ",@$v)."\n" if ref($v) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $v eq "ARRAY" 85 2 87
6088 2 ▶ barf "hash value found for comma-separated list option '$k' -- not allowed" if ref($v) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $v eq "HASH" 0 2 2
6089 2 ▶ return $v ? "set $k\n" : "unset $k\n";
Branch: 1 branch
BranchTrueFalseTotal
$v ? : 2 0 2
6090 },
6091  
6092 #### Special emitter for ticks that can deal with hashes
6093 4 ▶ 'lt' => sub { my($k,$v,$h) = @_;
Subroutine __ANON__: called CC=46 SCAR=57.7
6094 4 ▶ return "" unless(defined($v));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 4 4
6095 4 my @l = ();
6096 4 my @l2= ();
6097  
6098 4 ▶ return $v ? "set $k $v\n" : "unset $k\n" unless ref $v;
Branch: 2 branches
BranchTrueFalseTotal
unless ref $v 1 3 4
$v ? : 0 1 1
6099 3 ▶ if(ref($v) eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $v eq 'ARRAY') { } 0 3 3
elsif (ref $v ne 'HASH') { } 0 3 3
6100 0 @l = @$v;
6101 } elsif(ref($v) ne 'HASH') {
6102 0 die "<foo>tics spec must be scalar or hash\n";
6103 }
6104 3 my %h = %$v;
6105 3 ▶ push(@l, 'axis') if($h{axis}); delete $h{axis};
Branch: 1 branch
BranchTrueFalseTotal
if $h{"axis"} 0 3 3
6106 3 ▶ push(@l, 'border') if($h{border}); delete $h{border};
Branch: 1 branch
BranchTrueFalseTotal
if $h{"border"} 0 3 3
6107 3 ▶ push(@l, $h{mirror}?'mirror':'nomirror') if(defined($h{mirror})); delete $h{mirror};
Branch: 2 branches
BranchTrueFalseTotal
if defined $h{"mirror"} 0 3 3
$h{'mirror'} ? : 0 0 0
6108 3 ▶ if($h{in} && $h{out}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h{"in"} and $h{"out"}) 0 3 3
Condition33%1/3
$h{"in"} and $h{"out"}
!ll&&!rl&&r
300
MC/DC0%0/2
$h{"in"} and $h{"out"}
$h{"in"} $h{"out"}
Truth table33%1/3
A and B
A= $h{"in"}B= $h{"out"}
ABresult
0X0
100
111
6109 0 barf("<foo>tics: you set both the 'in' and 'out' options. Oops.");
6110 }
6111 3 ▶ push(@l, 'in') if delete $h{in};
Branch: 1 branch
BranchTrueFalseTotal
if delete $h{"in"} 0 3 3
6112 3 ▶ push(@l, 'out') if delete $h{out};
Branch: 1 branch
BranchTrueFalseTotal
if delete $h{"out"} 0 3 3
6113  
6114 3 ▶ unless($k =~ m/^m/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($k =~ /^m/) 2 1 3
6115 2 push(@l, 'scale');
6116 2 ▶ if( defined( my $v = delete $h{scale} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $v = delete $h{'scale'})) { } 0 2 2
6117 0 ▶ push @l, ref($v) eq 'ARRAY' ? join(",",@$v) : $v;
Branch: 1 branch
BranchTrueFalseTotal
ref $v eq 'ARRAY' ? : 0 0 0
6118 } else {
6119 2 push(@l, 'default');
6120 }
6121 2 ▶ if( defined( my $v = delete $h{rotate} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $v = delete $h{"rotate"})) 0 2 2
6122 0 ▶ push @l, $v ? "rotate by $v" : 'norotate';
Branch: 1 branch
BranchTrueFalseTotal
$v ? : 0 0 0
6123 }
6124 }
6125 3 ▶ if( defined( my $v = delete $h{offset} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $v = delete $h{"offset"})) 0 3 3
6126 0 ▶ barf "<foo>tics option: 'offset' suboption must be an array ref or false"
Branch: 1 branch
BranchTrueFalseTotal
if $v and ref $v ne "ARRAY" 0 0 0
Condition0%0/3
$v and ref $v ne "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
$v and ref $v ne "ARRAY"
$v ref $v ne "ARRAY"
Truth table0%0/3
A and B
A= $vB= ref $v ne "ARRAY"
ABresult
0X0
100
111
6127 if $v and ref($v) ne 'ARRAY';
6128 0 ▶ push @l, $v ? ("offset", join(",",@$v)) : 'nooffset';
Branch: 1 branch
BranchTrueFalseTotal
$v ? : 0 0 0
6129 }
6130  
6131 barf("<foo>tics: you set two or more of 'left','right', and 'center'. Oops.")
6132 3 ▶ if( defined($h{left}) + defined($h{right}) + defined($h{center}) > 1 );
Branch: 1 branch
BranchTrueFalseTotal
if defined($h{"left"}) + defined($h{"right"}) + defined($h{"center"}) > 1 0 3 3
6133  
6134 3 ▶ push(@l,'left') if delete $h{left};
Branch: 1 branch
BranchTrueFalseTotal
if delete $h{"left"} 0 3 3
6135 3 ▶ push(@l,'right') if delete $h{right};
Branch: 1 branch
BranchTrueFalseTotal
if delete $h{"right"} 0 3 3
6136 3 ▶ push(@l,'center') if delete $h{center};
Branch: 1 branch
BranchTrueFalseTotal
if delete $h{"center"} 0 3 3
6137  
6138  
6139 ##############################
6140 # Deal with complex add/labels/locations logic.
6141 # If you specify locations *or* labels then that style gets
6142 # emitted. if you specify both, then the labels get appended
6143 # to the end of the plot command as a *separate* "set <foo>tics"
6144 # gnuplot command with "add" marked.
6145  
6146 3 ▶ if(defined( my $v = $h{locations} )) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $v = $h{"locations"})) 1 2 3
6147 1 ▶ barf "<foo>tics: 'locations' elements must be scalar or array ref"
Branch: 1 branch
BranchTrueFalseTotal
if ref $v and ref $v ne "ARRAY" 0 1 1
Condition33%1/3
ref $v and ref $v ne "ARRAY"
!ll&&!rl&&r
010
MC/DC0%0/2
ref $v and ref $v ne "ARRAY"
ref $v ref $v ne "ARRAY"
Truth table33%1/3
A and B
A= ref $vB= ref $v ne "ARRAY"
ABresult
0X0
100
111
6148 if ref($v) and ref($v) ne 'ARRAY';
6149 1 ▶ if(ref($v) eq 'ARRAY'){
Branch: 2 branches
BranchTrueFalseTotal
if (ref $v eq 'ARRAY') { } 1 0 1
elsif (not ref $v) { } 0 0 0
6150 1 ▶ push @l, @$v ? join(',', @$v) : 'autofreq';
Branch: 1 branch
BranchTrueFalseTotal
@$v ? : 1 0 1
6151 } elsif(!ref($v)) {
6152 0 ▶ push @l, $v || 'autofreq';
Condition0%0/2
$v || 'autofreq'
l!l
00
MC/DC0%0/1
$v || 'autofreq'
$v
Truth table0%0/2
A
A= $v
Aresult
11
00
6153 }
6154 # Workaround for bug in gnuplot parser (documented in xtics section of gnuplot manual):
6155 # if the first number in the start/incr/end sequence is negative, subtract it from 0
6156 # to avoid problems with binary subtraction.
6157 1 $l[$#l] =~ s/^\s*\-/0\-/;
6158 }
6159 3 ▶ if(defined( my $v = $h{labels} )) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $v = $h{"labels"})) 0 3 3
6160 0 ▶ barf "<foo>tics: 'labels' elements must be array refs containing [label, val, flag]"
Branch: 1 branch
BranchTrueFalseTotal
if ref $v ne "ARRAY" 0 0 0
6161 if ref($v) ne 'ARRAY';
6162 0 ▶ barf "<foo>tics: labels list elements must be duals or triples as array refs"
Branch: 1 branch
BranchTrueFalseTotal
if grep((ref $_ ne "ARRAY"), @$v) 0 0 0
6163 if grep ref() ne 'ARRAY', @$v;
6164 0 ▶ my $line = "(".
Condition0%0/6
$_->[0] // ""
l!l
00
$_->[1] // 0
l!l
00
$_->[2] // ""
l!l
00
MC/DC0%0/1
$_->[0] // ""
$_->[0]
MC/DC0%0/1
$_->[1] // 0
$_->[1]
MC/DC0%0/1
$_->[2] // ""
$_->[2]
Truth table0%0/2
A
A= $_->[0]
Aresult
11
00
Truth table0%0/2
A
A= $_->[1]
Aresult
11
00
Truth table0%0/2
A
A= $_->[2]
Aresult
11
00
6165 join(", ",
6166 map sprintf('"%s" %s %s', $_->[0]//"", $_->[1]//0, $_->[2]//""),
6167 @$v
6168 ).
6169 ")"
6170 ;
6171 0 ▶ if(defined($h{locations})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $h{'locations'}) { } 0 0 0
6172 0 push(@l2, "\nset $k add ",$line);
6173 } else {
6174 0 push(@l, $line);
6175 }
6176 }
6177 3 delete $h{locations};
6178 3 delete $h{labels};
6179  
6180 3 ▶ push(@l,'format',"\"".quote_escape($h{format})."\"") if(defined($h{format})); delete $h{format};
Branch: 1 branch
BranchTrueFalseTotal
if defined $h{"format"} 0 3 3
6181  
6182 3 ▶ if( defined( my $v = delete $h{font} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $v = delete $h{"font"})) 0 3 3
6183 0 ▶ push @l, "font", '"'.join(',', ref($v) eq 'ARRAY' ? @$v : $v).'"';
Branch: 1 branch
BranchTrueFalseTotal
ref $v eq 'ARRAY' ? : 0 0 0
6184 }
6185  
6186 3 ▶ push(@l,'rangelimited') if defined(delete $h{rangelimited});
Branch: 1 branch
BranchTrueFalseTotal
if defined delete $h{"rangelimited"} 0 3 3
6187  
6188 3 ▶ if(defined( my $v = delete $h{textcolor})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $v = delete $h{"textcolor"})) 0 3 3
6189 0 push(@l,"textcolor", _emit_colorspec($v));
6190 }
6191  
6192 3 push(@l, @l2);
6193 3 return "set $k ".join(" ",@l)."\n";
6194  
6195 },
6196  
6197 ## one-line list with leading quoted string (e.g. for titles)
6198 'ql' =>
6199 21 ▶ sub { my($k,$v,$h) = @_;
Subroutine __ANON__: called CC=4 SCAR=14.0
6200 21 ▶ return "" unless defined($v);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 21 21
6201 21 ▶ unless(ref $v eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $v eq "ARRAY") 3 18 21
6202 3 $v = quote_escape($v);
6203 3 ▶ return ( (length($v) eq 0) ? "unset $k\n" : "set $k \"$v\"\n");
Branch: 1 branch
BranchTrueFalseTotal
length $v eq 0 ? : 3 0 3
6204 }
6205 18 my $quoted = quote_escape($v->[0]);
6206 18 return sprintf('set %s "%s" %s%s',$k,$quoted,join(" ",@{$v}[1..$#$v]),"\n");
6207 },
6208  
6209 #### A space-separated collection of terms as a curve option
6210 188 ▶ 'cl' => sub { my($k,$v,$h) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.0
6211 188 ▶ return "" unless defined($v);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 188 188
6212 188 ▶ return " $k $v " unless(ref $v eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $v eq "ARRAY" 96 92 188
6213 92 return join(" ",("",$k,@$v,""));
6214 },
6215  
6216 #### A comma-separated (rather than space-separated) collection of terms
6217 0 ▶ ',' => sub { my($k,$v,$h) = @_;
Subroutine __ANON__: not called CC=5 SCAR=34.0
6218 0 ▶ return "" unless(defined($v));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
6219 0 ▶ barf "hash value found for comma-separated list option '$k' -- not allowed"
Branch: 1 branch
BranchTrueFalseTotal
if ref $v eq "HASH" 0 0 0
6220 if ref $v eq 'HASH';
6221 0 ▶ if(ref $v eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v eq 'ARRAY') { } 0 0 0
6222 0 return "set $k ".join(",",@$v)."\n";
6223 } else {
6224 0 ▶ return $v ? "set $k\n" : "unset $k\n";
Branch: 1 branch
BranchTrueFalseTotal
$v ? : 0 0 0
6225 }
6226 },
6227  
6228 #### A comma-separated collection of terms as a curve option
6229 0 ▶ 'c,' => sub { my($k,$v,$h) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
6230 0 ▶ return "" unless(defined($v));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
6231 0 ▶ return " ".join(",", ref($v) eq 'ARRAY' ? @$v : $v)." ";
Branch: 1 branch
BranchTrueFalseTotal
ref $v eq 'ARRAY' ? : 0 0 0
6232 },
6233  
6234 #### A collection of values, reported one per line
6235 0 ▶ '1' => sub { my($k,$v,$h) = @_;
Subroutine __ANON__: not called CC=6 SCAR=37.4
6236 0 ▶ return "" unless(defined $v);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
6237 0 ▶ barf "hash value found for one-per-line list option '$k' -- not allowed"
Branch: 1 branch
BranchTrueFalseTotal
if ref $v eq "HASH" 0 0 0
6238 if ref $v eq 'HASH';
6239 0 ▶ if((ref $v) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v eq 'ARRAY') { } 0 0 0
6240 0 ▶ return join("", map { defined($_) ? "set $k $_\n" : "" } @$v);
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
6241 } else {
6242 0 ▶ return $v ? "set $k\n" : "unset $k\n";
Branch: 1 branch
BranchTrueFalseTotal
$v ? : 0 0 0
6243 }
6244 },
6245  
6246 #### A set of sub-keywords each of which may contain a list of terms
6247 0 ▶ "H" => sub { my($k,$v,$h) = @_;
Subroutine __ANON__: not called CC=10 SCAR=47.0
6248 0 ▶ return "" unless(defined $v);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
6249 0 ▶ if(ref $v eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $v eq 'ARRAY') { } 0 0 0
elsif (ref $v eq 'HASH') { } 0 0 0
6250 # Note list form doesn't allow unsetting. Such is life - lists are deprecated in most contexts.
6251 0 ▶ return join("", map { defined($_) ? "set $k $_\n" : "" } @$v);
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
6252 } elsif(ref($v) eq 'HASH') {
6253 0 ▶ return "set $k\n" unless(keys(%$v));
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$v 0 0 0
6254 0 return join("", map { my $l = "";
6255 0 ▶ if(defined($v->{$_})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v->{$_}) 0 0 0
6256 0 ▶ unless($v->{$_}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($v->{$_}) { } 0 0 0
if (do { ref $v->{$_} eq 'ARRAY' }) { } 0 0 0
elsif (ref $v->{$_} eq 'HASH') { } 0 0 0
6257 0 $l = "unset $k $_\n";
6258 } elsif(ref $v->{$_} eq 'ARRAY') {
6259 0 $l = "set $k $_ ".join(" ",@{$v->{$_}})."\n";
6260 } elsif(ref $v->{$_} eq 'HASH') {
6261 0 barf "Nested hashes not allowed in hash option '$k'";
6262 } else {
6263 0 $l = "set $k $_ $v->{$_}\n";
6264 }
6265 }
6266 0 $l;
6267 }
6268 sort keys %$v
6269 );
6270 } else {
6271 0 barf "scalar value '$v' not allowed for hash option '$k'";
6272 }
6273 },
6274  
6275 #### A set of sub-keywords each of which may contain a list of terms, sort-of.
6276 #### This is used for autoscale -- there's no space between keyword and value, and a missing hash causes "unset" to be emitted.
6277 2 ▶ "H2" => sub { my($k,$v,$h) = @_;
Subroutine __ANON__: called CC=9 SCAR=26.5
6278 2 ▶ return "unset $k\n" unless $v;
Branch: 1 branch
BranchTrueFalseTotal
unless $v 0 2 2
6279 0 ▶ return join("", map { defined($_) ? "set $k $_\n" : "" } @$v)
Branch: 2 branches
BranchTrueFalseTotal
if ref $v eq "ARRAY" 0 2 2
defined $_ ? : 0 0 0
6280 if ref $v eq 'ARRAY'; # Note list form doesn't allow unsetting. Such is life - lists are deprecated in most contexts.
6281 2 ▶ barf "scalar value '$v' not allowed for hash option '$k'"
Branch: 1 branch
BranchTrueFalseTotal
if ref $v ne "HASH" 0 2 2
6282 if ref($v) ne 'HASH';
6283 2 ▶ return "set $k\n" unless(keys(%$v));
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$v 1 1 2
6284 1 ▶ barf "Nested hashes not allowed in hash option '$k'" if grep ref() eq 'HASH', values %$v;
Branch: 1 branch
BranchTrueFalseTotal
if grep((ref $_ eq "HASH"), values %$v) 0 1 1
6285 return join("", map
6286 !$v->{$_} ? "unset $k $_\n" :
6287 ref $v->{$_} ne 'ARRAY' ? "set $k $_$v->{$_}\n" :
6288 0 "set $k $_ ".join(" ",@{$v->{$_}})."\n",
6289 1 ▶ grep defined($v->{$_}),
Branch: 2 branches
BranchTrueFalseTotal
!$v->{$_} ? : 0 1 1
ref $v->{$_} ne 'ARRAY' ? : 1 0 1
6290 sort keys %$v
6291 );
6292 },
6293  
6294 #### Terminal options hash
6295 4 ▶ "HNM" => sub { my($k,$v,$h) = @_;
Subroutine __ANON__: called CC=9 SCAR=40.4
6296 4 ▶ return "" unless((defined $v) and !($h->{multiplot}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v and not $h->{"multiplot"} 4 0 4
Condition33%1/3
defined $v and not $h->{"multiplot"}
!ll&&!rl&&r
400
MC/DC0%0/2
defined $v and not $h->{"multiplot"}
defined $v not $h->{"multiplot"}
Truth table33%1/3
A and not(B)
A= defined $vB= not $h->{"multiplot"}
ABresult
0X0
100
111
6297 0 ▶ barf "array value found for hash option '$k' -- not allowed"
Branch: 1 branch
BranchTrueFalseTotal
if ref $v eq "ARRAY" 0 0 0
6298 if ref $v eq 'ARRAY';
6299 0 ▶ barf "scalar value '$v' not allowed for hash option '$k'"
Branch: 1 branch
BranchTrueFalseTotal
if ref $v ne "HASH" 0 0 0
6300 if ref($v) ne 'HASH';
6301 0 ▶ return "set $k\n" unless(keys(%$v));
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$v 0 0 0
6302 0 ▶ barf "Nested hashes not allowed in hash option '$k'" if grep ref() eq 'HASH', values %$v;
Branch: 1 branch
BranchTrueFalseTotal
if grep((ref $_ eq "HASH"), values %$v) 0 0 0
6303 return join("", map
6304 !$v->{$_} ? "unset $k $_\n" :
6305 ref $v->{$_} ne 'ARRAY' ? "set $k $_ $v->{$_}\n" :
6306 0 "set $k $_ ".join(" ",@{$v->{$_}})."\n",
6307 0 ▶ grep defined($v->{$_}),
Branch: 2 branches
BranchTrueFalseTotal
!$v->{$_} ? : 0 0 0
ref $v->{$_} ne 'ARRAY' ? : 0 0 0
6308 sort keys %$v
6309 );
6310 },
6311  
6312 #### A collection of numbered specifiers (e.g. "arrow"), each with a collection of terms
6313 0 ▶ "N" => sub { my($k,$v,$h) = @_;
Subroutine __ANON__: not called CC=6 SCAR=37.4
6314 0 ▶ return "" unless(defined $v);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
6315 0 ▶ barf "non-array value '$v' found for numeric-indexed option '$k' -- not allowed"
Branch: 1 branch
BranchTrueFalseTotal
if ref $v ne "ARRAY" 0 0 0
6316 if ref $v ne 'ARRAY';
6317 return join "", map
6318 !defined($v->[$_]) ? "unset $k $_\n" :
6319 "set $k $_ " .
6320 join(" ",
6321 0 ▶ ref $v->[$_] eq 'ARRAY' ? @{$v->[$_]} :
Branch: 1 branch
BranchTrueFalseTotal
ref $v->[$_] eq 'HASH' ? : 0 0 0
6322 0 ▶ ref $v->[$_] eq 'HASH' ? %{$v->[$_]} : $v->[$_]
Branch: 2 branches
BranchTrueFalseTotal
!defined($v->[$_]) ? : 0 0 0
ref $v->[$_] eq 'ARRAY' ? : 0 0 0
6323 ) .
6324 "\n",
6325 1..$#$v;
6326 },
6327  
6328 #### A collection of numbered specifiers for "object" types - requires a special case for
6329 #### "set object polygon"
6330 0 ▶ "NO" => sub { my($k,$v,$h) = @_;
Subroutine __ANON__: not called CC=8 SCAR=42.8
6331 0 ▶ return "" unless(defined $v);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
6332 0 ▶ barf "non-array value '$v' found for numeric-indexed option '$k' -- not allowed"
Branch: 1 branch
BranchTrueFalseTotal
if ref $v ne "ARRAY" 0 0 0
6333 if ref $v ne 'ARRAY';
6334 my $s = join "", map
6335 !defined($v->[$_]) ? "unset $k $_\n" :
6336 "set $k $_ " .
6337 join(" ",
6338 0 ▶ ref $v->[$_] eq 'ARRAY' ? @{$v->[$_]} :
Branch: 1 branch
BranchTrueFalseTotal
ref $v->[$_] eq 'HASH' ? : 0 0 0
6339 0 ▶ ref $v->[$_] eq 'HASH' ? %{$v->[$_]} : $v->[$_]
Branch: 2 branches
BranchTrueFalseTotal
!defined($v->[$_]) ? : 0 0 0
ref $v->[$_] eq 'ARRAY' ? : 0 0 0
6340 ) .
6341 "\n",
6342 1..$#$v;
6343 #Split polygon lines after the polygon spec - yuck.
6344 0 my @s = split ("\n",$s);
6345 0 for my $i(0..$#s){
6346 0 ▶ if($s[$i] =~ s/((set +\w+ +\d+) +p(o(l(y(g(o(n)?)?)?)?)?)? +from +-?\d+(\.\d+)?([eE]?\-?\d+)?\,-?\d+(\.\d+)?([eE]?\-?\d+)?( +to +-?\d+(\.\d+)?([eE]?\-?\d+)?\,-?\d+(\.\d+)?([eE]?\-?\d+)?)+ +)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s[$i] =~ s/((set +\w+ +\d+) +p(o(l(y(g(o(n)?)?)?)?)?)? +from +-?\d+(\.\d+)?([eE]?\-?\d+)?\,-?\d+(\.\d+)?([eE]?\-?\d+)?( +to +-?\d+(\.\d+)?([eE]?\-?\d+)?\,-?\d+(\.\d+)?([eE]?\-?\d+)?)+ +)//) 0 0 0
6347 0 $s[$i] = $1."\n".$2." ".$s[$i];
6348 }
6349 }
6350 0 return join("\n",@s,"");
6351 },
6352  
6353 #### A collection of numbered specifiers, the first word of which is quoted (for labels).
6354 2 ▶ "NL" => sub { my($k,$v,$h) = @_;
Subroutine __ANON__: called CC=8 SCAR=23.4
6355 2 ▶ return "" unless(defined $v);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 2 2
6356 2 ▶ barf "non-array value '$v' found for numeric-indexed option '$k' -- not allowed"
Branch: 1 branch
BranchTrueFalseTotal
if ref $v ne "ARRAY" 0 2 2
6357 if ref $v ne 'ARRAY';
6358 return join "", map
6359 !defined($v->[$_]) ? "unset $k $_\n" :
6360 "set $k ".($_+1)." " .
6361 join(" ",
6362 ref $v->[$_] eq 'ARRAY' ? (
6363 map ref($_) eq 'ARRAY' ? join(",",@$_) : $_, # Nested arrays get connected with ','
6364 $v->[$_][0] !~ m/^\".*\"$/ # unless already quoted
6365 ? "\"".quote_escape($v->[$_][0])."\"" : # quote the first element
6366 $v->[$_][0],
6367 2 ▶ @{$v->[$_]}[1..$#{$v->[$_]}]
Branch: 1 branch
BranchTrueFalseTotal
ref $v->[$_] eq 'HASH' ? : 0 0 0
6368 ) :
6369 0 ▶ ref $v->[$_] eq 'HASH' ? %{$v->[$_]} : $v->[$_]
Branch: 4 branches
BranchTrueFalseTotal
!defined($v->[$_]) ? : 2 2 4
ref $v->[$_] eq 'ARRAY' ? : 2 0 2
ref $_ eq 'ARRAY' ? : 2 5 7
!($v->[$_][0] =~ /^\".*\"$/) ? : 2 0 2
6370 ) .
6371 "\n",
6372 0..$#$v;
6373 },
6374  
6375 #### Ranges can either be given as a list, the first two elements
6376 #### of which are the range and the rest of which are options, or
6377 #### as a list, the first element of which is a gnuplot range
6378 #### specifier and the rest of which are options, or as a string
6379 #### that combines everything.
6380 ####
6381 #### The job is complicated by the fact that the 'restore' keyword
6382 #### can replace the normal range specifier.
6383 ####
6384 #### Note: we don't try to do a perfect job of parsing, only to
6385 #### decide which parse fixing-up style is needed to send
6386 #### something reasonable to gnuplot in the correct case. Gnuplot
6387 #### is expected to throw an error if something is broken.
6388  
6389 69 ▶ "range" => sub { my($k,$v,$h) = @_;
Subroutine __ANON__: called CC=18 SCAR=38.5
6390 69 ▶ return "" unless(defined $v);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 69 69
6391  
6392 # scalar -- treat it as a string containing the whole command.
6393 69 ▶ return "set $k $v\n" if(ref $v ne 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if ref $v ne "ARRAY" 0 69 69
6394  
6395  
6396 #looks like 'set <foo>range restore' (only way 'r' can be the first char)
6397 69 ▶ return "set $k ".join(" ",@$v)."\n" if ($v->[0]//'') =~ m/^\s*r/i;
Branch: 1 branch
BranchTrueFalseTotal
if ($v->[0] // "") =~ /^\s*r/i 0 69 69
Condition50%1/2
$v->[0] // ""
l!l
690
MC/DC0%0/1
$v->[0] // ""
$v->[0]
Truth table50%1/2
A
A= $v->[0]
Aresult
11
00
6398  
6399  
6400 # first element is an empty range specifier - emit.
6401 69 ▶ return "set $k ".join(" ",@$v)."\n" if ($v->[0]//'') =~ m/\s*\[\s*\]/;
Branch: 1 branch
BranchTrueFalseTotal
if ($v->[0] // "") =~ /\s*\[\s*\]/ 0 69 69
Condition50%1/2
$v->[0] // ""
l!l
690
MC/DC0%0/1
$v->[0] // ""
$v->[0]
Truth table50%1/2
A
A= $v->[0]
Aresult
11
00
6402  
6403 69 my $c = substr($k,0,1);
6404 69 ▶ my $tfmt = ( $h->{$c."data"} // "" ) =~ m/time/;
Condition100%2/2
$$h{$c . 'data'} // ""
l!l
267
MC/DC100%1/1
$$h{$c . 'data'} // ""
$$h{$c . 'data'}
Truth table100%2/2
A
A= $$h{$c . 'data'}
Aresult
11
00
6405  
6406 # first element has a nonempty range specifier (naked or not).
6407 69 ▶ if( ($v->[0] // '') =~ m/\:/) {
Branch: 1 branch
BranchTrueFalseTotal
if (($v->[0] // "") =~ /\:/) 0 69 69
Condition50%1/2
$v->[0] // ""
l!l
690
MC/DC0%0/1
$v->[0] // ""
$v->[0]
Truth table50%1/2
A
A= $v->[0]
Aresult
11
00
6408 0 $v->[0]=~ s/^\s*((.*[^\s])?)\s*$/$1/; # trim leading and trailing whitespace if present
6409  
6410 0 ▶ unless($v->[0] =~ m/^\[/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($v->[0] =~ /^\[/) 0 0 0
6411 # the first char was not a '['; assume it is a naked range and patch accordingly.
6412 0 $v->[0] = "[$v->[0]]";
6413 }
6414  
6415 0 ▶ if($tfmt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tfmt) 0 0 0
6416 # Make sure we have quotes as necessary
6417 0 $v->[0] =~ s/\[([^\"\:\*]+)\:/\[\"$1\"\:/;
6418 0 $v->[0] =~ s/\:([^\"\:\*]+)\]/\:\"$1\"\]/;
6419 }
6420 0 my $s = join(" ",@$v);
6421 0 $s =~ s/\[\:/\[*\:/;
6422 0 $s =~ s/\:\]/\:*\]/;
6423  
6424 0 return "set $k $s\n";
6425 }
6426 # If we got here, the first element has no ':'. Treat the first two elements as numbers and make a range
6427 # specifier out of 'em, then emit.
6428 # Here's a little fillip: gnuplot requires quotes around time ranges
6429 # if the corresponding axes are time data. Handle that bizarre case.
6430 69 ▶ if( ($h->{$c."data"} // "") =~ m/time/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($$h{$c . 'data'} // "") =~ /time/) 2 67 69
Condition100%2/2
$$h{$c . 'data'} // ""
l!l
267
MC/DC100%1/1
$$h{$c . 'data'} // ""
$$h{$c . 'data'}
Truth table100%2/2
A
A= $$h{$c . 'data'}
Aresult
11
00
6431 2 ▶ return sprintf("set %s [%s:%s]\n",$k, ((defined $v->[0])?"\"$v->[0]\"":"*"), ((defined $v->[1])?"\"$v->[1]\"":"*"));
Branch: 2 branches
BranchTrueFalseTotal
defined $v->[0] ? : 2 0 2
defined $v->[1] ? : 2 0 2
6432 }
6433  
6434 67 ▶ return sprintf("set %s [%s:%s] %s\n", $k, ((defined $v->[0])?$v->[0]:"*"), ((defined $v->[1])?$v->[1]:"*"), join(" ",@{$v}[2..$#$v]));
Branch: 2 branches
BranchTrueFalseTotal
defined $v->[0] ? : 67 0 67
defined $v->[1] ? : 65 2 67
6435 },
6436  
6437 0 ▶ "crange" => sub { my($k,$v,$h, $this) = @_;
Subroutine __ANON__: not called CC=11 SCAR=48.8
6438 0 ▶ return "" unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
6439 0 ▶ return "$v" if ref $v ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $v ne "ARRAY" 0 0 0
6440 0 my $of = 946684800.0;
6441 # Here's a little fillip: gnuplot requires quotes around time ranges
6442 # if the corresponding axes are time data. Handle that bizarre case.
6443 0 my $c = substr($k,0,1);
6444  
6445 0 ▶ if( ($this and $this->{options} and $this->{options}{$c."data"} // "") =~ m/time/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($this && $this->{"options"} && ($this->{"options"}{$c . 'data'} // "")) =~ /time/) 0 0 0
Condition0%0/8
$this && $this->{'options'} && ($this->{'options'}{$c . 'data'} // '')
!ll&&!rl&&r
000
$this and $this->{"options"}
!ll&&!rl&&r
000
$this->{"options"}{$c . 'data'} // ""
l!l
00
MC/DC0%0/3
$this && $this->{'options'} && ($this->{'options'}{$c . 'data'} // '')
$this $this->{"options"} $this->{"options"}{$c . 'data'}
Truth table0%0/4
A and B && C
A= $thisB= $this->{"options"}C= $this->{"options"}{$c . 'data'}
ABCresult
0XX0
10X0
1100
1111
6446 0 carp "WARNING: gnuplot-4.6.1 date range bug triggered. Check the date scale.\n";
6447 0 ▶ return sprintf(" [%s:%s] ",((defined $v->[0])?"\"$v->[0]\"":""), ((defined $v->[1])?"\"$v->[1]\"":""));
Branch: 2 branches
BranchTrueFalseTotal
defined $v->[0] ? : 0 0 0
defined $v->[1] ? : 0 0 0
6448 }
6449 0 ▶ return sprintf(" [%s:%s] ",((defined $v->[0])?$v->[0]:""), ((defined $v->[1])?$v->[1]:""));
Branch: 2 branches
BranchTrueFalseTotal
defined $v->[0] ? : 0 0 0
defined $v->[1] ? : 0 0 0
6450 },
6451  
6452 3 };
6453  
6454 ##############################
6455 # termTab - list of supported terminals and their arguments
6456 # Each entry is a hash ref containing:
6457 # opt - specification hash for the options for this terminal
6458 # unit - native unit in which size is specified for this terminal
6459 # desc - a one-line description of the terminal
6460 # default_output - an optional format string with the name of the default output plot for that device.
6461 #
6462 # Since there are so many terminal types, with so many slightly
6463 # different syntaxes, we store them in shorthand here. The
6464 # $termTab_types table contains commonly used parameter keywords,
6465 # together with partial hash parser table entries. The
6466 # actual terminal descriptions then refer to those keywords
6467 # wherever possible rather than repeating the whole definition.
6468 #
6469 # The default_output is there because some gnuplot devices have sensible default outputs, while others
6470 # do not. For example, "wxt"'s default is to put stuff in a window, but "png"'s default is to
6471 # send the png file to stdout, which makes no sense. In cases where there is no sensible default built in to gnuplot,
6472 # we provide one.
6473 #
6474  
6475 0 ▶my $emit_enh = sub { my ($k,$v,$h) = @_; return " ".($v?"":"no")."enhanced "; };
Subroutine __ANON__: not called CC=2 SCAR=14.0
Branch: 1 branch
BranchTrueFalseTotal
$v ? : 0 0 0
6476  
6477 3 our $lConv = {
6478 inch => 1,
6479 inc => 1,
6480 in => 1,
6481 i => 1,
6482 char => 6,
6483 cha => 6,
6484 ch => 6,
6485 c => 6,
6486 pt => 72,
6487 points=> 72,
6488 point => 72,
6489 poin => 72,
6490 poi => 72,
6491 po => 72,
6492 px => 100,
6493 pixels=> 100,
6494 pixel => 100,
6495 pixe => 100,
6496 pix => 100,
6497 pi => 100,
6498 p => 100,
6499  
6500 mm => 25.4,
6501 cm => 2.54
6502 };
6503  
6504 # These are keyed descriptors for options that are used in at least two devices. They are invoked by name in the
6505 # $termTab_source table below, which describes all the known gnuplot device specification options.
6506 our $termTab_types = {
6507 0 ▶ aa => ['n',sub{''}, "Anti-aliasing factor"], # implemented in output(), plot(), close(), and DESTROY().
Subroutine __ANON__: not called CC=1 SCAR=1.2
6508 output => ['s','q', "File name for output"], # autocopied to a plot option when present for a device
6509 output_ => ['s','cv', "Window number for persistent windows"], # trailing '_' prevents autocopy to a plot option
6510 title => ['s','cq', "Window title"],
6511 size => ['ln','csize', "Window size (default unit is %u)"],
6512 font => ['s','cqf', "Font to use ('<fontname>,<size>')"],
6513 fontsize => ['s','css', "Font size (points)"], # use for devices that use no keyword for font size
6514 enhanced => ['b','cf', "Enable or disable gnuplot enhanced text escapes for markup"],
6515 color => ['b','cff', "Generate a color plot (see 'monochrome') if true"],
6516 monochrome => ['b','cff', "Generate a B/W plot (see 'color') if true"],
6517 solid => ['b','cff', "Plot only solid lines (see 'dashed') if true"],
6518 dashed => ['b','cff', "Plot dashed lines (see 'solid') if true"],
6519 rotate => ['b','cf', "Enable or disable true rotated text (90 degrees)"],
6520 linewidth => ['s','css', "Multiplier on line width (typ. default 1 pt)"],
6521 dashlength => ['s','cs', "Multiplier on dash length for dashed plots"],
6522 standalone => ['b','cff', "Generate postscript that can render alone (see 'input')"], # for LaTeX devices
6523 input => ['b','cff', "Generate postscript to be combined with LaTeX output"], # for LaTeX devices
6524 level1 => ['b','cff', "Generate Level 1 Postscript (see 'leveldefault')"], # for PostScript devices
6525 leveldefault=>['b','cff', "Generate full-featured Postscript (see 'level1')"], # for PostScript devices
6526 rounded => ['b','cff', "Generate rounded ends on lines (see 'butt')"],
6527 butt => ['b','cff', "Generate butt-ends on lines (see 'rounded')"],
6528 clip => ['b','cf', "Clip output to bounding box (or not)"], # for PostScript devices
6529 landscape => ['b','cff', "Set landscape orientation (see 'portrait')"],
6530 portrait => ['b','cff', "Set portrait orientation (see 'landscape')"],
6531 tiny => ['b','cff', "Set tiny preset plot size (see also 'size')"],
6532 small => ['b','cff', "Set small preset plot size (see also 'size')"],
6533 medium => ['b','cff', "Set medium preset plot size (see also 'size')"],
6534 big => ['b','cff', "Set big preset plot size (see also 'size')"],
6535 large => ['b','cff', "Set large preset plot size (see also 'size')"],
6536 giant => ['b','cff', "Set giant preset plot size (see also 'size')"],
6537 transparent=> ['b','cf', "Enable or disable transparency for the background"],
6538 background => ['s','cv', "Background color in xRRGGBB format ('x' literal)"],
6539 interlace => ['s','cf', "Enable or disable interlaced encoding of image"], # JPEG and PNG
6540 crop => ['b','cf', "Enable or disable autocropping to first drawn pixel"],
6541 oldstyle => ['b','cff', "Force old-style text spacing (deprecated)"],
6542 newstyle => ['b','cff', "Force new-style text spacing (default; see 'oldstyle')"],
6543 auxfile => ['b','cf', "Generate (or not) an auxiliary .aux file for LaTeX"],
6544 persist => ['b','cf', 'enable (or disable) persistence after plotting is done'],
6545 raise => ['b','cf', 'enable (or disable) raising the display window to the top'],
6546 };
6547  
6548 # This table includes all terminals named in the gnuplot 4.4 documentation. Unsupported terminals have
6549 # only a description string; supported terminals get a hash that contains:
6550 # - unit (default size unit for the terminal)
6551 # - desc (description string)
6552 # - opt (array ref containing option descriptors in order).
6553 # - default_output (optional -- if present, contains a printf format string containing the default output name)
6554 # Each option descriptor is one of:
6555 # * a string indexing the descriptor in $termTab_types, above, or
6556 # * an array ref containing:
6557 # -name
6558 # -input parser (as for $pOptionsTable)
6559 # -output parser (as for $pOptionsTable)
6560 # -description string
6561 #
6562 # To enable anti-aliasing on a given terminal:
6563 # - make sure that the "standard" 'aa' option is one of the options it takes
6564 # - make sure that the 'font' or 'fontsize' option scales with aa (the 'cqf' option type does this)
6565 # - set the "image_format" key in the terminal description hash (see 'pngcairo' as an example)
6566 # (the image_format must be one of the formats recognized by PDL::IO::Pic)
6567 #
6568  
6569 our $termTabSource = {
6570 'aed767' => "AED graphics terminal [NS: ancient]",
6571 'aifm' => "Adobe Illustrator [NS: obsolete (use pdf)]",
6572 'amiga' => "Amiga terminal driver [NS: ancient]",
6573 'apollo' => "Apollo terminal driver [NS: ancient]",
6574 'aqua' => { unit=>'pt', desc=> 'Aqua terminal program on MacOS X (MacOS default device)', int=>1, ok=>1, disp=>1,
6575 opt=>[ qw/ output_ title size font enhanced / ]},
6576 'be' => "BeOS/X11 (Ah, Be, how we miss thee) [NS: ancient]",
6577 'cairolatex'=> { unit=>'in', desc=>'Cairo support for .eps or .pdf output with LaTeX text rendering',
6578 opt=> [
6579 ['mode', 's', 'cv', 'terminal mode: set to "eps" or "pdf"'],
6580 ['textmode', 's', 'cv', 'text mode: set to "black" or "color"'],
6581 0 ▶ ['header', 's', sub { $_[1] ? " header '$_[1]' " : " noheader " },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[1] ? : 0 0 0
6582 "LaTeX source for header text"
6583 ],
6584 "color",
6585 "monochrome",
6586 "transparent",
6587 ['crop', 'b', 'byn', "Set TRUE to crop output", ],
6588 "background",
6589 ['font', 's', 'cq','Font ("<fontname>,<size>") - NOT system fonts - see manual for list'],
6590 ['scale', 'n', 'cs','Font scale beyond the size in the font option'],
6591 ['linewidth', 'n', 'cs','Line width in points'],
6592 ['endstyle', 's', 'cv','Line end style (set to "rounded", "butt", or "square")'],
6593 'size'
6594 ],
6595 default_output=>'%s%d-cairolatex.eps'},
6596 'canvas' => { unit=>'pt', desc=> "Output Javascript Canvas rendering code.",
6597 opt=>[ 'size',
6598 # custom line shields user from "fsize/fontsize"
6599 0 ▶ ['fontsize', 's', sub { " fsize $_[1] "}, "Font size (points)"],
Subroutine __ANON__: not called CC=1 SCAR=6.9
6600 'enhanced',
6601 'linewidth',
6602 ['standalone', 'b','cff', "Generate a standalone html page (default) (see 'name')"],
6603 ['mousing', 'b','cff', "Make a mouse-tracking box underneath the plot"],
6604 ['name', 's','cq', "Generate a javascript subroutine named 'name'"],
6605 ['jsdir', 's','cq', "URL of directory where javascripts are found"],
6606 'title'],
6607 default_output=>'%s%d.js'},
6608 'cgm' => { unit=>'pt', desc=> "Computer Graphic Metafile format (ANSI X3.122-1986)",
6609 opt=>[ qw/ color monochrome solid dashed rotate /,
6610 0 ▶ ['size', 'l', sub { my( $k, $v, $h) = @_;
Subroutine __ANON__: not called CC=5 SCAR=34.0
6611 0 my $conv = 1;
6612 0 ▶ if(@$v > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$v > 2) 0 0 0
6613 0 carp "Warning: cgm device ignores height spec; using width only.";
6614 }
6615 0 ▶ if(@$v >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$v >= 2) 0 0 0
6616 0 ▶ if($lConv->{$v->[$#$v]}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($$PDL::Graphics::Gnuplot::lConv{$$v[$v->$#*]}) { } 0 0 0
elsif ($v > 2) { } 0 0 0
6617 0 $conv = $lConv->{ $v->[$#$v] } / $lConv->{ 'pt' };
6618 } elsif( $v>2 ) {
6619 0 die "cgm device: 3-element size spec must end with a unit spec";
6620 }
6621 }
6622 0 return " ".($v->[0] * $conv)." ";
6623 },
6624 "Window size (default unit is pt; height is ignored)"
6625 ],
6626 'linewidth',
6627 ['font', 's','cq','Font ("<fontname>,<size>") - NOT system fonts - see manual for list'],
6628 "background",
6629 'output'],
6630 default_output=>'%s%d.cgm'
6631 },
6632 'context'=> "ConTeXt: Metapost macros for TeX [NS: TBD]",
6633 'corel' => "Corel Draw [NS: ancient]",
6634 'debug' => "Gnuplot internal debugging mode [NS: not useful]",
6635 'dumb' => {
6636 unit=>'char',desc=>"dumb terminal (ASCII output)",ok=>1,
6637 opt=>[ ['feed','b','cf',"Issue (or not) a formfeed at the end of each plot"],
6638 qw/ size enhanced output /],
6639 default_output=>'%s%d.txt'
6640 },
6641 'dxf' => {unit=>'pt', desc=>"AutoCad 10.x interchange files",
6642 opt=>[ 'output' ]},
6643 'dxy800a'=> "Roland DXY800A Plotter [NS: obsolete]",
6644 'eepic' => {unit=>'in',desc=>"LaTeX picture (alternative w/ epic.sty & eepic.sty)",
6645 opt=>[ qw/ color dashed rotate small tiny /,
6646 ['fontsize','s','cv','Font size (points)'], # special entry 'coz eepic wants no "fontsize" keyword
6647 'output'],
6648 default_output=>'%s-epic-%d.tex'
6649 },
6650 'emf' => {unit=>'pt',desc=>"Microsoft Windows Enhanced Metafile Format",
6651 opt=>[ qw/ color monochrome solid dashed enhanced /,
6652 ['noproportional','b','cff',"(only with 'enhanced') - disable proportional font spacing"],
6653 qw/ linewidth dashlength size background font output /],
6654 default_output=>'%s%d.emf'
6655 },
6656 'emxvga' => "EMXVGA terminal [NS: bizarre]",
6657 'emxvesa'=> "EMXVESA terminal [NS: bizarre]",
6658 'epscairo'=>{unit=>'in',desc=>"Encapsulated Postscript output via Cairo 2-D plotting library",ok=>1,
6659 opt=>[ 'enhanced',
6660 0 ▶ ['monochrome','b', sub{return $_[1]?" mono ":""},
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[1] ? : 0 0 0
6661 "Generate a B/W plot (see 'color') if true"], # shield user from mono/monochrome
6662 qw/color solid dashed font linewidth rounded butt dashlength background size output/ ],
6663 default_output=>'%s%d.eps'
6664 },
6665 'epslatex'=>{unit=>'in',desc=>"Encapsulated PostScript with LaTeX text segments",
6666 opt=>[ qw/standalone input oldstyle newstyle level1 leveldefault color monochrome/,
6667 qw/solid dashed background dashed dashlength linewidth rounded butt clip size font output/],
6668 default_output=>'%s%d-latex.eps'
6669 },
6670 'epson_180dpi' => "Epson 180dpi amily of 9-pin printers [NS: ancient]",
6671 'excl' => "Talaris printer support [NS: ancient]",
6672 'fig' => {unit=>'in',desc=>"Fig graphics language output",
6673 opt=>[ qw/ color monochrome landscape portrait small big size /,
6674 ['pointsmax', 's','cs', "maximum number of points per polyline (default 2000)"],
6675 qw/ solid dashed /,
6676 0 ▶ ['font','s', sub { my($k,$v,$h)=@_; # special entry to allow standard format
Subroutine __ANON__: not called CC=3 SCAR=24.8
6677 0 my($f,$fs)=split /,/,$v; # (fig requires breaking font name and
6678 0 ▶ my($s) = $f ? " font $f " : ""; # size out into different keywords)
Branch: 1 branch
BranchTrueFalseTotal
$f ? : 0 0 0
6679 0 ▶ $s .= "fontsize $fs " if ($fs);
Branch: 1 branch
BranchTrueFalseTotal
if $fs 0 0 0
6680 0 return $s;
6681 },
6682 "Font to use ('<fontname>,<size>')"],
6683 'fontsize',
6684 ['textnormal', 'b','cff','turn off all special text flags (default)'],
6685 ['textspecial','b','cff','use LaTeX special text'],
6686 ['texthidden', 'b','cff','use hidden text'],
6687 ['textrigid', 'b','cff','set the postscript "rigid" flag'],
6688 'linewidth',
6689 ['depth', 's','cs', 'set PostScript rendering depth'],
6690 ['version', 's','cs', '(not documented in gnuplot manual)'],
6691 'output'],
6692 default_output=>'%s%d.fig'
6693 },
6694 'ggi' => "X or SVGAlib output via GGIlib [NS: obsolete]",
6695 'gif' => {unit=>'px',desc=>"Graphics Interchange Format (venerable but supported)",ok=>1,
6696 opt=>[ qw/ transparent rounded butt linewidth dashlength font enhanced size crop /,
6697 ['animate','l','cl',"syntax: animate=>[delay=>\$d, loop=>\$n, (no)?optimize]"],
6698 qw/ aa background output / ],
6699 default_output=>'%s%d.gif',
6700 image_format=>'GIF'
6701 },
6702 'excl' => "Talaris printer support [NS: ancient]",
6703 'gnugraph'=>"Gnu plotutils metalanguage output [NS: obsolete]",
6704 'gpic' => "UNIX groff(1) output [NS: prehistoric]",
6705 'gpr' => "Apollo Graphics Primitive Resource [NS: ancient]",
6706 'grass' => {unit=>'px',desc=>"GRASS GIS file output",
6707 opt=>['output'],
6708 default_output=>'%s%d.grass'
6709 },
6710 'hercules'=>"PC graphics card with autodetection [NS: obsolete]",
6711 'hp2623a'=> "HP 2623A terminal [NS: ancient]",
6712 'hp2648' => "HP2647 and HP2648 terminals [NS: ancient]",
6713 'hp500c' => "HP500C terminal [NS: ancient]",
6714 'hpgl' => "HPGL output (e.g. HP7475 plotter) [NS: ancient]",
6715 'hpljii' => "HP Laserjet Series II [NS: obsolete]",
6716 'hppj' => "HP PaintJet and HP3630 printers [NS: obsolete]",
6717 'imagen' => "Imagen laser printers [NS: obsolete]",
6718 'jpeg' => {unit=>"px",desc=>"JPEG image file output",ok=>1,
6719 opt=>[ qw/aa interlace linewidth dashlength rounded butt font enhanced size crop background output /],
6720 default_output=>'%s%d.jpg',
6721 image_format=>"JPEG"
6722 },
6723 'kyo' => "Kyocera laserprinter native format [NS: obsolete]",
6724 'latex' => {unit=>'in',desc=>"EPS output tailored for LaTeX (see also 'epslatex')",
6725 opt=>[ ['default', 'b','cff','accept whatever font is in the embedding document'],
6726 ['courier', 'b','cff','force font to Courier'],
6727 ['roman', 'b','cff','force font to Roman style (e.g. Times)'],
6728 ['fontsize','s','cv', 'set font size (in points)'], # special entry 'coz latex wants no "fontsize" keyword.
6729 qw/size rotate output/],
6730 default_output=>'%s%d.tex'
6731 },
6732 'linux' => "Render to a Linux display dev (non-X) [NS: obsolete]",
6733 'lua' => "Lua script output [NS: bizarre]",
6734 'macintosh'=>"Direct rendered MacOS < 10 window [NS: ancient]",
6735 'mf' => "Metafont output (plot as TeX glyph) [NS: crazy]",
6736 'mif' => "FrameMaker MIF format v3.0 [NS: obsolete]",
6737 'mp' => "MetaPost metaformat for graphice [NS: obsolete]",
6738 'next' => "NeXT (NeXTstep) file format (RIP Jobs) [NS: ancient]",
6739 'openstep'=> "Openstep (NeXTStep followon) [NS: obsolete]",
6740 'pbm' => {unit=>"px",desc=>"Portable BitMap format output",
6741 opt=>[ ['fontsize','s','cv','font size (in pixels/points)'],
6742 qw/monochrome color size output/],
6743 default_output=>'%s%d.pbm'},
6744 'pdf' => {unit=>'in',desc=>"Portable Document Format output",ok=>1,
6745 opt=>[ qw/monochrome color enhanced font linewidth rounded butt solid dashed dashlength size output/ ],
6746 default_output=>'%s%d.pdf'
6747 },
6748 'pdfcairo'=>{unit=>'in',desc=>"PDF output via Cairo 2-D plotting library",ok=>1,
6749 opt=>[ 'enhanced',
6750 0 ▶ ['monochrome','b', sub{return $_[1]?" mono ":""},
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[1] ? : 0 0 0
6751 "Generate a B/W plot (see 'color') if true"], # shield user from mono/monochrome
6752 qw/color solid dashed font linewidth rounded butt dashlength background size output/ ],
6753 default_output=>'%s%d.c.pdf'
6754 },
6755 'pm' => "OS/2 presentation manager [NS: ancient]",
6756 'png' => {unit=>"px",desc=>"PNG image output",ok=>1,
6757 opt=>[ qw/transparent interlace/,
6758 ['truecolor','b','cf','Enable or disable true color (RGB) output'],
6759 qw/aa rounded butt linewidth dashlength tiny small medium large giant font enhanced size crop background output/],
6760 default_output=>'%s%d.png',
6761 image_format=>'PNG'
6762 },
6763 'pngcairo'=>{unit=>'px',desc=>"PNG image output via Cairo 2-D plotting library",ok=>1,
6764 opt=>[ 'enhanced',
6765 0 ▶ ['monochrome','b',sub{return $_[1]?" mono ":""},
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[1] ? : 0 0 0
6766 "Generate a B/W plot (see 'color') if true"], # shield user from mono/monochrome
6767 qw/aa color solid dashed transparent crop background font linewidth rounded butt dashlength size output/ ],
6768 default_output=>'%s%d.c.png',
6769 image_format=>'PNG',
6770 },
6771 'postscript'=>{unit=>'in',desc=>"Postscript file output",ok=>1,
6772 opt=>[qw/landscape portrait/,
6773 ['eps', 'b','cff','Select encapsulated output (neither landscape nor portrait)'],
6774 'enhanced',
6775 ['simplex', 'b','cff','single sided printing'],
6776 ['duplex', 'b','cff','double sided printing'],
6777 ['defaultplex','b','cff','accept printer default for 1/2 sided printing'],
6778 0 ▶ ['fontfile', 's',sub { my ($k,$v)=@_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
6779 0 return " $k add \"$v\" "}
6780 3 , 'add font file to prologue'],
6781 ['adobeglyphnames','b','cf','enable or disable Adobe style glyph names'],
6782 qw/level1 leveldefault color monochrome background solid dashed dashlength linewidth rounded butt clip size/,
6783 ['blacktext', 'b','cff','force text to be B/W even in color plots (see "colortext")'],
6784 ['colortext', 'b','cff','force text to be color even in B/W plots (see "blacktext")'],
6785 'font','output'],
6786 default_output=>'%s%d.ps'
6787 },
6788 'pslatex' => {unit=>'in',desc=>"Postscript file tailored for inclusion in LaTeX documents",
6789 opt=>[ qw/rotate oldstyle newstyle auxfile level1 leveldefault color monochrome /,
6790 qw/solid dashed dashlength linewidth rounded butt clip size fontsize output/],
6791 default_output=>'%s%d-latex.ps'
6792 },
6793 'pstex' => {unit=>'in',desc=>"Postscript file tailored for inclusion in raw TeX documents",
6794 opt=>[ qw/rotate oldstyle newstyle auxfile level1 leveldefault color monochrome background /,
6795 qw/solid dashed dashlength linewidth rounded butt clip size fontsize output/],
6796 default_output=>'%s%d-tex.ps'
6797 },
6798 'pstricks'=>"Output for pstricks.sty LaTeX macros [NS: obsolete]",
6799 'qms' =>"QMS/QUIC laser printer native format [NS: ancient]",
6800 'qt' =>{unit=>'px',desc=>'QT X windows display',mouse=>1,ok=>1,disp=>2,
6801 opt=>['output_',
6802 ['title','s','cq','Window title (in title bar)'],
6803 qw/enhanced font linewidth solid dashed persist raise/,
6804 ['ctrlq', 'b', 'cf', 'enable (or disable) control-Q to quit window'],
6805 'size']}, # no default (goes to screen)
6806 'regis' =>"REGIS graphics language output [NS: obsolete]",
6807 'rgip' =>"RGIP metafiles [NS: obsolete]",
6808 'sun' =>"SUNView window system window [NS: ancient]",
6809 'svg' =>{unit=>'in',desc=>"Scalable Vector Graphics (SVG) output",ok=>1,
6810 opt=>[ qw/size enhanced font/,
6811 ['fontfile','s','cq','Font file to copy into the <defs> section of the SVG'],
6812 qw/rounded butt solid dashed linewidth background output/],
6813 default_output=>'%s%d.svg'
6814 },
6815 'svga' =>"Output direct to a PC SVGA screen [NS: obsolete]",
6816 'tek40' =>"Tektronix 40xx plotting terminals [NS: ancient]",
6817 'tek410x' =>"Tektronix 410x plotting terminals [NS: ancient]",
6818 'texdraw' =>{unit=>'in',desc=>"TexDraw environment for LaTeX",
6819 opt=>[ 'output' ],
6820 default_output=>'%s%d-texdraw.tex'
6821 },
6822 'tgif' =>"TGIF X11-based drawing tool [NS: obsolete]",
6823 'tikz' =>"TikZ package via Lua [NS: obsolete]",
6824 'tkcanvas'=>"Tcl/Tk canvas widget design [NS: weird]",
6825 'tpic' =>"Latex picture (use 'latex' or 'eepic') [NS: obsolete]",
6826 'unknown' =>"Unknown term (gnuplot final default) [NS: not a terminal]",
6827 'unixpc' =>"AT&T 3b1 and AT&T 7300 UNIX PC display [NS: ancient]",
6828 'unixplot'=>"UNIX plot(1) language (non-GNU version)[NS: obsolete]",
6829 'vgagl' =>"Output to a VGA screen under linux [NS: obsolete]",
6830 'vws' =>"VAX Windowing System [NS: ancient]",
6831 'vx384' =>"Vectrix 384 and Tandy color printers [NS: ancient]",
6832 'windows' =>{unit=>"px",desc=>"Microsoft Windows display window",
6833 opt=>[ qw/color monochrome font background title size/,
6834 ['position','l','csize','pixel location of the window'],
6835 'output']},
6836 'wxt' =>{unit=>"px", desc=>"WxWidgets display", mouse=>1,ok=>1,disp=>2,int=>1,
6837 opt=>[ qw/size background enhanced font title dashed solid dashlength persist raise/,
6838 ['ctrl', 'b','cf','enable (or disable) control-Q to quit window'],
6839 ['close', 'b','cf','close window on completion?']
6840 ]},
6841 'x11' =>{unit=>"px",desc=>"X Windows display", mouse=>1,ok=>1,disp=>2,
6842 opt=>[ 'output_',
6843 ['title','s','cq','Window title (in title bar)'],
6844 qw/enhanced font linewidth solid dashed persist raise/,
6845 ['ctrlq', 'b','cf','enable (or disable) control-Q to quit window'],
6846 'size']},
6847 'xlib' =>"Xlib command file (for debugging X11) [NS: useless here]",
6848 'vgal'=> "VGAL terminal [NS: bizarre]",
6849 };
6850  
6851 ##############################
6852 # Generate the termTab from termTabSource.
6853 #
6854 # Each entry in termTab gets the description string and unit, and a
6855 # list with the same structure as the $pOpt global for parse options --
6856 # except that the abbrevs table is not prepopulated for all devices
6857 # (it is calculated on the fly within the constructor).
6858 #
6859 # Unsupported entries are left to rot in the termTabSource structure.
6860  
6861 3 $termTab = {};
6862  
6863 3 for my $k(keys %$termTabSource) {
6864 252 ▶ next unless(ref(my $v = $termTabSource->{$k})); # names aren't supported -- eliminate
Branch: 1 branch
BranchTrueFalseTotal
unless ref(my $v = $PDL::Graphics::Gnuplot::termTabSource->{$k}) 165 87 252
6865 87 my $terminalOpt = {}; #this will hold the _parseOptHash control structure we generate
6866 87 my $i = 1; #this is a sort order counter
6867  
6868 87 for my $n(@{$v->{opt}}) {
6869 987 my $name = $n;
6870 987 my $line;
6871 987 ▶ if(ref $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $name) { } 156 831 987
6872 156 $name = $n->[0];
6873 156 $line = [@$n[1..3]];
6874 } else {
6875 831 ▶ $line = $termTab_types->{$name}
Branch: 1 branch
BranchTrueFalseTotal
$line = $PDL::Graphics::Gnuplot::termTab_types->{$name} or die "Bug in parse table build! ('${name}' inside terminal '${k}')" 831 0 831
6876 or die "Bug in parse table build! ('$name' inside terminal '$k')";
6877 }
6878 987 $terminalOpt->{$name} = [ @$line[0, 1], undef, $i++, $line->[2]];
6879 }
6880 1 ▶ $terminalOpt->{"wait"} = [ 's' , sub { return "" }, undef, $i++, "wait time before throwing an error (default 5s)" ];
Subroutine __ANON__: called CC=1 SCAR=0.0
6881 87 my $desc = $v->{desc};
6882 87 $desc =~ s/\%u/$v->{unit}/;
6883 $termTab->{$k} = { desc => $desc,
6884 unit => $v->{unit},
6885 mouse => $v->{mouse} // 0,
6886 disp => $v->{disp} // 0,
6887 int => $v->{int} // 0,
6888 opt => [ $terminalOpt,
6889 undef, # This gets filled in on first use in the constructor.
6890 "$k terminal options"
6891 ],
6892 default_output=> $v->{default_output},
6893 ( exists $v->{image_format}
6894 ? ( image_format => $v->{image_format} )
6895 87 ▶ : () ),
Branch: 1 branch
BranchTrueFalseTotal
exists $v->{'image_format'} ? : 12 75 87
Condition100%6/6
$v->{"mouse"} // 0
l!l
978
$v->{"disp"} // 0
l!l
1275
$v->{"int"} // 0
l!l
681
MC/DC100%1/1
$v->{"mouse"} // 0
$v->{"mouse"}
MC/DC100%1/1
$v->{"disp"} // 0
$v->{"disp"}
MC/DC100%1/1
$v->{"int"} // 0
$v->{"int"}
Truth table100%2/2
A
A= $v->{"mouse"}
Aresult
11
00
Truth table100%2/2
A
A= $v->{"disp"}
Aresult
11
00
Truth table100%2/2
A
A= $v->{"int"}
Aresult
11
00
6896 };
6897 }
6898  
6899 =pod
6900  
6901 =head2 terminfo
6902  
6903 =for usage
6904  
6905 use PDL::Graphics::Gnuplot qw/terminfo/;
6906 terminfo(); # print info about all known terminals
6907 terminfo 'aqua'; # print info about the aqua terminal
6908  
6909 $w = gpwin();
6910 $w->terminfo();
6911  
6912 =for ref
6913  
6914 Print out information about gnuplot terminals and their custom option syntax.
6915  
6916 The "terminfo" routine is a reference tool to describe the Gnuplot
6917 terminal types and the options they accept. It's mainly useful in
6918 interactive sessions. It outputs information directly to the terminal.
6919  
6920 =cut
6921  
6922 0 ▶sub terminfo {
Subroutine terminfo: not called CC=37 SCAR=72.5
Pod documented
6923 0 my $this = _obj_or_global(\@_);
6924 0 ▶ my $terminal = shift() // '';
Condition0%0/2
shift() // ""
l!l
00
MC/DC0%0/1
shift() // ""
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
6925 0 my $brief_form = shift;
6926 0 my $dont_print = shift;
6927 0 my $s = "";
6928  
6929 0 ▶ if($termTabSource->{$terminal}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PDL::Graphics::Gnuplot::termTabSource->{$terminal}) 0 0 0
6930 0 ▶ if(ref $termTabSource->{$terminal}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $PDL::Graphics::Gnuplot::termTabSource->{$terminal}) { } 0 0 0
6931 0 ▶ my $ms = $termTabSource->{$terminal}{mouse} ? ", mouse input ok" : "";
Branch: 1 branch
BranchTrueFalseTotal
$PDL::Graphics::Gnuplot::termTabSource->{$terminal}{'mouse'} ? : 0 0 0
6932 0 $s = "Gnuplot terminal '$terminal': size default unit is '$termTabSource->{$terminal}->{unit}'$ms, options are:\n";
6933 0 my $tt = $termTab->{$terminal}->{opt}->[0];
6934 0 ▶ for my $name(sort { ($tt->{$a}[3] // 0) <=> ($tt->{$b}->[3] // 0) } keys %$tt) {
Condition0%0/4
$tt->{$a}[3] // 0
l!l
00
$tt->{$b}[3] // 0
l!l
00
MC/DC0%0/1
$tt->{$a}[3] // 0
$tt->{$a}[3]
MC/DC0%0/1
$tt->{$b}[3] // 0
$tt->{$b}[3]
Truth table0%0/2
A
A= $tt->{$a}[3]
Aresult
11
00
Truth table0%0/2
A
A= $tt->{$b}[3]
Aresult
11
00
6935 0 my @info = ($name, $tt->{$name}[4]);
6936 0 $info[0] =~ s/\_$//; #remove trailing underscore on "output_" hack
6937 0 ▶ if(defined($info[0]) and defined($info[1])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $info[0] and defined $info[1]) 0 0 0
Condition0%0/3
defined $info[0] and defined $info[1]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $info[0] and defined $info[1]
defined $info[0] defined $info[1]
Truth table0%0/3
A and B
A= defined $info[0]B= defined $info[1]
ABresult
0X0
100
111
6938 0 my $ss = sprintf "%10s - %s\n",@info;
6939 0 $ss =~ s/\%u/$termTabSource->{$terminal}->{unit}/;
6940 0 $s .= $ss;
6941 }
6942 }
6943 } else {
6944 0 ▶ if($this->{unknown_terms}->{$terminal}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'unknown_terms'}{$terminal}) { } 0 0 0
6945 0 $s = "terminfo: terminal '$terminal' isn't supported, although your gnuplot has it:\n";
6946 0 $s .= " $terminal: $termTabSource->{$terminal}\n";
6947 } else {
6948 0 $s = "PDL::Graphics::Gnuplot doesn't support '$terminal'.\n $terminal: $termTabSource->{$terminal}\n";
6949 }
6950 }
6951 0 ▶ print STDERR $s unless($dont_print);
Branch: 1 branch
BranchTrueFalseTotal
unless $dont_print 0 0 0
6952 0 return $s;
6953 }
6954  
6955 0 ▶ if($terminal && $this->{unknown_terms}->{$terminal}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($terminal and $this->{"unknown_terms"}{$terminal}) 0 0 0
Condition0%0/3
$terminal and $this->{"unknown_terms"}{$terminal}
!ll&&!rl&&r
000
MC/DC0%0/2
$terminal and $this->{"unknown_terms"}{$terminal}
$terminal $this->{"unknown_terms"}{$terminal}
Truth table0%0/3
A and B
A= $terminalB= $this->{"unknown_terms"}{$terminal}
ABresult
0X0
100
111
6956 0 $s = "terminfo: terminal '$terminal' was reported by gnuplot but isn't supported.\n";
6957 0 $s .= " $terminal: $this->{unknown_terms}->{$terminal}\n";
6958 0 ▶ print STDERR $s unless($dont_print);
Branch: 1 branch
BranchTrueFalseTotal
unless $dont_print 0 0 0
6959 0 return $s;
6960 }
6961  
6962 0 ▶ if($terminal && $terminal ne 'all'){
Branch: 1 branch
BranchTrueFalseTotal
if ($terminal and $terminal ne "all") 0 0 0
Condition0%0/3
$terminal and $terminal ne "all"
!ll&&!rl&&r
000
MC/DC0%0/2
$terminal and $terminal ne "all"
$terminal $terminal ne "all"
Truth table0%0/3
A and B
A= $terminalB= $terminal ne "all"
ABresult
0X0
100
111
6963 0 $s = "terminfo: terminal '$terminal' isn't recognized. I'm listing all supported terminals instead.\n\n";
6964 0 $terminal = '';
6965 }
6966  
6967 0 ▶ if(!$terminal || $terminal eq 'all') {
Branch: 1 branch
BranchTrueFalseTotal
if (not $terminal or $terminal eq "all") 0 0 0
Condition0%0/3
not $terminal or $terminal eq "all"
l!l&&r!l&&!r
000
MC/DC0%0/2
not $terminal or $terminal eq "all"
not $terminal $terminal eq "all"
Truth table0%0/3
not(A) or B
A= not $terminalB= $terminal eq "all"
ABresult
1X1
011
000
6968  
6969 0 ▶ if(!$terminal && !$brief_form && !$dont_print) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($terminal or $brief_form or $dont_print) 0 0 0
Condition0%0/6
$terminal or $brief_form or $dont_print
l!l&&r!l&&!r
000
$terminal or $brief_form
l!l&&r!l&&!r
000
MC/DC0%0/3
$terminal or $brief_form or $dont_print
$terminal $brief_form $dont_print
Truth table0%0/4
A or B or C
A= $terminalB= $brief_formC= $dont_print
ABCresult
1XX1
01X1
0011
0000
6970 0 $s .= "('terminfo \"all\"' lists all known terminals, even those not supported)\n\n";
6971 }
6972  
6973 0 $s .= "Gnuplot terminals supported by PDL::Graphics::Gnuplot and your gnuplot:\n";
6974  
6975 0 $s .= "\n DISPLAY TERMINALS ([M] indicates mouse input is supported)\n";
6976 0 for my $k(sort keys %$termTab) {
6977 0 ▶ next unless($this->{valid_terms}->{$k});
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"valid_terms"}{$k} 0 0 0
6978 0 ▶ next unless($termTab->{$k}->{int} || $termTab->{$k}->{mouse});
Branch: 1 branch
BranchTrueFalseTotal
unless $PDL::Graphics::Gnuplot::termTab->{$k}{"int"} or $PDL::Graphics::Gnuplot::termTab->{$k}{"mouse"} 0 0 0
Condition0%0/3
$PDL::Graphics::Gnuplot::termTab->{$k}{"int"} or $PDL::Graphics::Gnuplot::termTab->{$k}{"mouse"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$PDL::Graphics::Gnuplot::termTab->{$k}{"int"} or $PDL::Graphics::Gnuplot::termTab->{$k}{"mouse"}
$PDL::Graphics::Gnuplot::termTab->{$k}{"int"} $PDL::Graphics::Gnuplot::termTab->{$k}{"mouse"}
Truth table0%0/3
A or B
A= $PDL::Graphics::Gnuplot::termTab->{$k}{"int"}B= $PDL::Graphics::Gnuplot::termTab->{$k}{"mouse"}
ABresult
1X1
011
000
6979 0 ▶ $s .= sprintf(" %10s: %s %s\n",$k,$termTab->{$k}->{mouse} ? "[M]" : " ", $termTab->{$k}->{desc});
Branch: 1 branch
BranchTrueFalseTotal
$PDL::Graphics::Gnuplot::termTab->{$k}{'mouse'} ? : 0 0 0
6980 }
6981  
6982 0 $s .= "\n\n FILE TERMINALS\n";
6983 0 for my $k(sort keys %$termTab) {
6984 0 ▶ next unless($this->{valid_terms}->{$k});
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"valid_terms"}{$k} 0 0 0
6985 0 ▶ next if($termTab->{$k}->{int} || $termTab->{$k}->{mouse});
Branch: 1 branch
BranchTrueFalseTotal
if $PDL::Graphics::Gnuplot::termTab->{$k}{"int"} or $PDL::Graphics::Gnuplot::termTab->{$k}{"mouse"} 0 0 0
Condition0%0/3
$PDL::Graphics::Gnuplot::termTab->{$k}{"int"} or $PDL::Graphics::Gnuplot::termTab->{$k}{"mouse"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$PDL::Graphics::Gnuplot::termTab->{$k}{"int"} or $PDL::Graphics::Gnuplot::termTab->{$k}{"mouse"}
$PDL::Graphics::Gnuplot::termTab->{$k}{"int"} $PDL::Graphics::Gnuplot::termTab->{$k}{"mouse"}
Truth table0%0/3
A or B
A= $PDL::Graphics::Gnuplot::termTab->{$k}{"int"}B= $PDL::Graphics::Gnuplot::termTab->{$k}{"mouse"}
ABresult
1X1
011
000
6986 0 $s .= sprintf(" %10.10s: %s %s\n",$k," ", $termTab->{$k}->{desc});
6987 }
6988  
6989 0 ▶ if($terminal eq 'all') {
Branch: 1 branch
BranchTrueFalseTotal
if ($terminal eq 'all') { } 0 0 0
6990 # Merge things gnuplot reported but we don't support, with things we support but
6991 # gnuplot didn't report...
6992 0 $s .= "\nThese terminals are supported by PDL::Graphics::Gnuplot but not your gnuplot:\n";
6993  
6994 0 for my $k(sort keys %{$termTab}) {
6995 0 ▶ next if($this->{valid_terms}->{$k});
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"valid_terms"}{$k} 0 0 0
6996 0 $s .= sprintf("%12s: %s\n", $k, $termTab->{$k}->{desc});
6997 }
6998  
6999 0 $s .= "\nThese terminals are supported by your gnuplot but not by PDL::Graphics::Gnuplot:\n";
7000 0 for my $k(sort keys %{$this->{unknown_terms}}) {
7001 0 $s .= sprintf("%12s: %s\n",$k,$this->{unknown_terms}->{$k});
7002 }
7003  
7004 } else {
7005 0 $s .= "\n(use terminfo('all') to see unsupported terminals as well)\n";
7006 }
7007 0 $s .= "\nRun PDL::Graphics::Gnuplot::terminfo( \$term_name ) for information on options.\n\n";
7008  
7009 0 ▶ $s .= (($this==$globalPlot) ? "The default P::G::G" : "This") . " window is currently using the '$this->{terminal}' terminal.\n\n";
Branch: 1 branch
BranchTrueFalseTotal
$this == $PDL::Graphics::Gnuplot::globalPlot ? : 0 0 0
7010  
7011 0 ▶ print STDERR $s unless($dont_print);
Branch: 1 branch
BranchTrueFalseTotal
unless $dont_print 0 0 0
7012 0 return $s;
7013 }
7014  
7015 }
7016  
7017 ######################################################################
7018 ######################################################################
7019 #####
7020 ##### I/O to Gnuplot
7021 #####
7022 ##### The following routines provide basic I/O to the underlying
7023 ##### Gnuplot process: starting Gnuplot, writing commands and/or data
7024 ##### to it, reading messages back, and ensuring synchronization.
7025 #####
7026 ##### Note: it is not a normal state of the object to NOT have a
7027 ##### Gnuplot (or dump interface) running. These are internal
7028 ##### methods because there is no checking elsewhere to make sure the
7029 ##### gnuplot is there to receive commands.
7030 #####
7031 #####
7032 ##### Communication strategy:
7033 #####
7034 ##### Since we're using open3() we have to be careful to avoid
7035 ##### deadlock. Also, gnuplot is a little brittle in some
7036 ##### situations. Fortunately, we don't keep much state in gnuplot
7037 ##### itself, so we can more or less treat the gnuplot process as
7038 ##### disposable. It's inconvenient to restart or reset it,
7039 ##### especially if there is a display device like x11, wxt, or aqua
7040 ##### in place, since that causes a new window to be launched. But
7041 ##### for most communication exceptions we can simply drop-kick the
7042 ##### subprocess and start it over.
7043 #####
7044 ##### POSIX IPC is pretty sane and we can use signals to control
7045 ##### what's going on. Unfortunately, not all supported platforms
7046 ##### are POSIX, so we have to switch some behavior based on the
7047 ##### $MS_io_braindamage flag.
7048 #####
7049 ##### Because not much data comes back from gnuplot over the pipe, we
7050 ##### are pretty careless about how we pull it through -- one
7051 ##### character at a time, which is pretty inefficient.
7052 #####
7053 ##### Dealing with exceptions and interrupts is difficult, since
7054 ##### gnuplot doesn't seem to respond well over the pipe in the most
7055 ##### common case (while receiving binary data). In that particular
7056 ##### case we simply dropkick gnuplot and restart it.
7057 #####
7058  
7059 ##############################
7060 ##############################
7061 ## _load_alien_gnuplot -- load up the local caches of terminal support and color names.
7062 ## This is necessary because Alien::Gnuplot doesn't know which terminals we support,
7063 ## and is in a separate subroutine so we can call it to reload the cached terminal
7064 ## database.
7065  
7066 3 _load_alien_gnuplot(); # Execute this during module load!
7067  
7068 3 ▶sub _load_alien_gnuplot {
Subroutine _load_alien_gnuplot: called CC=4 SCAR=13.9
7069 3 our %valid_terms = ();
7070 3 our $valid_terms = \%valid_terms;
7071 3 our $unknown_terms = {};
7072  
7073 3 for ( @Alien::Gnuplot::terms ) {
7074 78 ▶ if(exists($termTab->{$_})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDL::Graphics::Gnuplot::termTab->{$_}) { } 36 42 78
7075 36 $valid_terms->{$_} = 1;
7076 } else {
7077 42 ▶ $unknown_terms->{$_} = $termTabSource->{$_} // "Unknown but reported by gnuplot";
Condition100%2/2
$PDL::Graphics::Gnuplot::termTabSource->{$_} // "Unknown but reported by gnuplot"
l!l
2418
MC/DC100%1/1
$PDL::Graphics::Gnuplot::termTabSource->{$_} // "Unknown but reported by gnuplot"
$PDL::Graphics::Gnuplot::termTabSource->{$_}
Truth table100%2/2
A
A= $PDL::Graphics::Gnuplot::termTabSource->{$_}
Aresult
11
00
7078 }
7079 }
7080  
7081 3 our @colornames = @Alien::Gnuplot::colors;
7082 3 our %colornames = %Alien::Gnuplot::colors;
7083 3 our $colornames = \%colornames;
7084 }
7085  
7086  
7087  
7088  
7089  
7090  
7091 ##############################
7092 ##############################
7093 ## _startGnuplot - fire off a gnuplot process, and pull in some information from it about what it can do.
7094 ##
7095 sub _startGnuplot
7096 45 ▶{
Subroutine _startGnuplot: called CC=33 SCAR=52.6
7097 ## Object code handles gnuplot in-place.
7098 45 my $this = shift;
7099 45 ▶ my $suffix = shift || "main";
Condition50%1/2
shift() || 'main'
l!l
450
MC/DC0%0/1
shift() || 'main'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
7100  
7101 45 ▶ if($this->{"pid-$suffix"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$this{"pid-$suffix"}) 0 45 45
7102 0 _killGnuplot($this,$suffix);
7103 }
7104  
7105 45 $this->{options}{multiplot} = 0;
7106  
7107 45 ▶ if( $this->{options}{dump} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'options'}{'dump'}) { } 0 45 45
7108 0 $this->{"in-$suffix"} = \*STDOUT;
7109 0 $this->{"pid-$suffix"} = undef;
7110 0 $this->{dumping} = $this->{options}{dump};
7111 0 return $this;
7112 } else {
7113 45 $this->{dumping} = 0;
7114 }
7115  
7116 # We don't actually want the --persist option, but gnuplot crashes on some platforms without it.
7117 # (I'm looking at you, Microsoft Windows...)
7118 # Instead, we default the "persist" plot option to be 0, if unspecified.
7119 45 ▶ my @gnuplot_options = $gnuplotFeatures{persist} ? qw(--persist) : ();
Branch: 1 branch
BranchTrueFalseTotal
$PDL::Graphics::Gnuplot::gnuplotFeatures{'persist'} ? : 45 0 45
7120  
7121 45 my $in = gensym();
7122 45 my $err = gensym();
7123  
7124 45 my $XDG_RUNTIME_DIR_global = $ENV{XDG_RUNTIME_DIR};
7125 45 local $ENV{XDG_RUNTIME_DIR} = $XDG_RUNTIME_DIR_global;
7126 45 ▶ if( exists $ENV{DISPLAY} && ! $XDG_RUNTIME_DIR_global ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{"DISPLAY"} and not $XDG_RUNTIME_DIR_global) 0 45 45
Condition33%1/3
exists $ENV{"DISPLAY"} and not $XDG_RUNTIME_DIR_global
!ll&&!rl&&r
4500
MC/DC0%0/2
exists $ENV{"DISPLAY"} and not $XDG_RUNTIME_DIR_global
exists $ENV{"DISPLAY"} not $XDG_RUNTIME_DIR_global
Truth table33%1/3
A and not(B)
A= exists $ENV{"DISPLAY"}B= not $XDG_RUNTIME_DIR_global
ABresult
0X0
100
111
7127 0 $this->{"_XDG_RUNTIME_DIR-tempdir-$suffix"} = File::Temp->newdir();
7128 0 $ENV{XDG_RUNTIME_DIR} = '' . $this->{"_XDG_RUNTIME_DIR-tempdir-$suffix"};
7129 }
7130 45 my $pid = open3($in,$err,$err, $Alien::Gnuplot::executable, @gnuplot_options);
7131  
7132 45 ▶ unless($pid) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pid) 0 45 45
7133 0 barf("PDL::Graphics::Gnuplot: Couldn't run the '$Alien::Gnuplot::executable' backend that was found by Alien::Gnuplot");
7134 }
7135  
7136 45 my $errSelector;
7137 45 $this->{"in-$suffix"} = $in;
7138 45 $this->{"err-$suffix"} = $err;
7139 45 $this->{"errSelector-$suffix"} = $errSelector = IO::Select->new($err);
7140 45 $this->{"pid-$suffix"} = $pid;
7141  
7142 ## Make sure the executable is working as expected. We do this by
7143 ## telling it to emit a version number. (Alien::Gnuplot did this at
7144 ## load time, so we can check both that the gnuplot works, and also
7145 ## that it is probably the same executable that Alien::Gnuplot reported.)
7146  
7147 45 my $s = "";
7148 45 our $gp_version;
7149 45 our $gp_pl;
7150  
7151 45 ▶ if(!$this->{dumping}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $this->{'dumping'}) { } 45 0 45
7152 45 print $in "show version\n\nprint \"FfFinished\"\n\n";
7153 45 my $byte;
7154 45 my $zcount = 0;
7155 45 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
($s =~ /^FfFinished$/m or $zcount > 100) or do { do { if ($errSelector->can_read(1) or $PDL::Graphics::Gnuplot::MS_io_braindamage) { sysread $err, $byte, 1; $s .= $byte; if (length $byte == 0) { ++$zcount; } else { $zcount = 0; } ; } else { carp("WARNING: Hmmm, gnuplot didn't respond promptly. I was expecting to read\n a version number. Carry on, but don't be surprised if it doesn't work.\n\n-\n $s\n-\n\n"); return $this; } } } 45 16335 16380
Condition66%2/3
$s =~ /^FfFinished$/m or $zcount > 100
l!l&&r!l&&!r
45016335
MC/DC50%1/2
$s =~ /^FfFinished$/m or $zcount > 100
$s =~ /^FfFinished$/m $zcount > 100
Truth table66%2/3
A or B
A= $s =~ /^FfFinished$/mB= $zcount > 100
ABresult
1X1
011
000
7156 16380 ▶ if($errSelector->can_read(1) or $MS_io_braindamage) {
Branch: 1 branch
BranchTrueFalseTotal
if ($errSelector->can_read(1) or $PDL::Graphics::Gnuplot::MS_io_braindamage) { } 16380 0 16380
Condition33%1/3
$errSelector->can_read(1) or $PDL::Graphics::Gnuplot::MS_io_braindamage
l!l&&r!l&&!r
1638000
MC/DC0%0/2
$errSelector->can_read(1) or $PDL::Graphics::Gnuplot::MS_io_braindamage
$errSelector->can_read(1) $PDL::Graphics::Gnuplot::MS_io_braindamage
Truth table33%1/3
A or B
A= $errSelector->can_read(1)B= $PDL::Graphics::Gnuplot::MS_io_braindamage
ABresult
1X1
011
000
7157 16380 sysread $err, $byte, 1;
7158 16380 $s .= $byte;
7159 16380 ▶ if(length($byte)==0) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $byte == 0) { } 0 16380 16380
7160 0 $zcount++;
7161 } else {
7162 16380 $zcount = 0;
7163 }
7164 } else {
7165 0 carp <<"EOM";
7166 WARNING: Hmmm, gnuplot didn\'t respond promptly. I was expecting to read
7167 a version number. Carry on, but don\'t be surprised if it doesn\'t work.
7168  
7169 -
7170 $s
7171 -
7172  
7173 EOM
7174 ;
7175 0 return $this;
7176 }
7177 } until($s =~ m/^FfFinished$/m || $zcount > 100);
7178  
7179 ##############################
7180 # Parse version number. If the version or pl changed, try reloading Alien::Gnuplot
7181 # to get them in sync.
7182 45 ▶ if( $s =~ m/Version ((\d+)\.(\d+)(\.(\d+))?) (patchlevel (\w+))?/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /Version ((\d+)\.(\d+)(\.(\d+))?) (patchlevel (\w+))?/i) { } 45 0 45
7183 45 $gp_version = $1;
7184 45 ▶ $gp_numversion = $2 + 0.001*$3 + 0.000001*($5||0);
Condition50%1/2
$5 || 0
l!l
045
MC/DC0%0/1
$5 || 0
$5
Truth table50%1/2
A
A= $5
Aresult
11
00
7185 45 $gp_pl = $7;
7186 45 $this->{gp_version} = $1;
7187 45 $this->{gp_numversion} = $gp_numversion;
7188 45 $this->{gp_pl} = $7;
7189 } else {
7190  
7191 # Something went wrong with i/o. See if the process still exists.
7192 0 ▶ unless($MS_io_braindamage) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDL::Graphics::Gnuplot::MS_io_braindamage) 0 0 0
7193 3 ▶ use POSIX ":sys_wait_h";
Subroutine BEGIN: called CC=1 SCAR=0.0
7194 0 my $wp = waitpid($pid, WNOHANG);
7195 0 ▶ if($wp == $pid) {
Branch: 2 branches
BranchTrueFalseTotal
if ($wp == $pid) { } 0 0 0
elsif ($wp < 0) { } 0 0 0
7196 0 ▶ if((($?+0) & 255)==11) {
Branch: 2 branches
BranchTrueFalseTotal
if (($? + 0 & 255) == 11) { } 0 0 0
elsif (($? + 0 & 255) == 7) { } 0 0 0
7197 0 die "ERROR: the gnuplot subprocess died with a segmentation fault!\n (Could happen before exec'ing '$Alien::Gnuplot::executable'...)\n";
7198 } elsif((($?+0) & 255)==7) {
7199 0 die "ERROR: the gnuplot subprocess died with a bus error!\n (Could happen before exec'ing '$Alien::Gnuplot::executable'...)\n";
7200 }
7201 0 die "ERROR: The gnuplot subprocess died! Its exit code was $?.\n I hope that helps.\n";
7202 } elsif($wp < 0) {
7203 0 die "ERROR: The gnuplot process mysteriously vanished and was also reaped.\nBizarre.\n";
7204 }
7205 }
7206  
7207 carp <<"EOM"
7208 WARNING: I couldn\'t parse a version number from gnuplot\'s output. I\'m
7209 returning the object anyway - but don\'t be surprised if it doesn\'t work.
7210 I\'m marking it with an internal \"obsolete\" flag, which may help.
7211 EOM
7212 0 ;
7213 0 $this->{early_gnuplot} = 1;
7214 0 $PDL::Graphics::Gnuplot::raw_output = $s;
7215 0 return $this;
7216 }
7217  
7218 45 ▶ if($gp_pl =~ m/[a-z]+/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PDL::Graphics::Gnuplot::gp_pl =~ /[a-z]+/) { } 0 45 45
7219 0 ▶ unless($PDL::Graphics::Gnuplot::non_numeric_patch_warned || $ENV{PGG_RC_OK}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDL::Graphics::Gnuplot::non_numeric_patch_warned or $ENV{"PGG_RC_OK"}) 0 0 0
Condition0%0/3
$PDL::Graphics::Gnuplot::non_numeric_patch_warned or $ENV{"PGG_RC_OK"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$PDL::Graphics::Gnuplot::non_numeric_patch_warned or $ENV{"PGG_RC_OK"}
$PDL::Graphics::Gnuplot::non_numeric_patch_warned $ENV{"PGG_RC_OK"}
Truth table0%0/3
A or B
A= $PDL::Graphics::Gnuplot::non_numeric_patch_warnedB= $ENV{"PGG_RC_OK"}
ABresult
1X1
011
000
7220 0 carp "WARNING: your gnuplot has a non-numeric patchlevel '$gp_pl'. Use with caution.\n(warning will not be repeated; set env. var. PGG_RC_OK to suppress)\n";
7221 0 $PDL::Graphics::Gnuplot::non_numeric_patch_warned = 1;
7222 }
7223 } else {
7224 45 $PDL::Graphics::Gnuplot::non_numeric_patch_warned = 0;
7225 45 ▶ if( $gp_version ne $Alien::Gnuplot::version or $gp_pl ne $Alien::Gnuplot::pl ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PDL::Graphics::Gnuplot::gp_version ne $Alien::Gnuplot::version or $PDL::Graphics::Gnuplot::gp_pl ne $Alien::Gnuplot::pl) 0 45 45
Condition33%1/3
$PDL::Graphics::Gnuplot::gp_version ne $Alien::Gnuplot::version or $PDL::Graphics::Gnuplot::gp_pl ne $Alien::Gnuplot::pl
l!l&&r!l&&!r
0045
MC/DC0%0/2
$PDL::Graphics::Gnuplot::gp_version ne $Alien::Gnuplot::version or $PDL::Graphics::Gnuplot::gp_pl ne $Alien::Gnuplot::pl
$PDL::Graphics::Gnuplot::gp_version ne $Alien::Gnuplot::version $PDL::Graphics::Gnuplot::gp_pl ne $Alien::Gnuplot::pl
Truth table33%1/3
A or B
A= $PDL::Graphics::Gnuplot::gp_version ne $Alien::Gnuplot::versionB= $PDL::Graphics::Gnuplot::gp_pl ne $Alien::Gnuplot::pl
ABresult
1X1
011
000
7226 0 carp <<"EOM";
7227 WARNING: we found gnuplot version '$gp_version' pl '$gp_pl' but Alien::Gnuplot reported
7228 a different version ('$Alien::Gnuplot::version' pl '$Alien::Gnuplot::pl'). Reloading Alien::Gnuplot...
7229 EOM
7230 0 Alien::Gnuplot::load_gnuplot();
7231 0 _load_alien_gnuplot();
7232 0 ▶ if( $gp_version ne $Alien::Gnuplot::version or $gp_pl ne $Alien::Gnuplot::pl ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PDL::Graphics::Gnuplot::gp_version ne $Alien::Gnuplot::version or $PDL::Graphics::Gnuplot::gp_pl ne $Alien::Gnuplot::pl) 0 0 0
Condition0%0/3
$PDL::Graphics::Gnuplot::gp_version ne $Alien::Gnuplot::version or $PDL::Graphics::Gnuplot::gp_pl ne $Alien::Gnuplot::pl
l!l&&r!l&&!r
000
MC/DC0%0/2
$PDL::Graphics::Gnuplot::gp_version ne $Alien::Gnuplot::version or $PDL::Graphics::Gnuplot::gp_pl ne $Alien::Gnuplot::pl
$PDL::Graphics::Gnuplot::gp_version ne $Alien::Gnuplot::version $PDL::Graphics::Gnuplot::gp_pl ne $Alien::Gnuplot::pl
Truth table0%0/3
A or B
A= $PDL::Graphics::Gnuplot::gp_version ne $Alien::Gnuplot::versionB= $PDL::Graphics::Gnuplot::gp_pl ne $Alien::Gnuplot::pl
ABresult
1X1
011
000
7233 0 carp <<"EOM"
7234 Hmmm, that\'s funny. Reloading Alien::Gnuplot gave version '$Alien::Gnuplot::version' pl '$Alien::Gnuplot::pl',
7235 which still doesn\'t match. Proceed with caution!
7236  
7237 EOM
7238 }
7239 }
7240  
7241 # On windows, gnuplot versions 4.6.5 and older echo back commands.
7242 45 ▶ if ( $gp_numversion <= '4.006' && $gp_pl <= 5 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PDL::Graphics::Gnuplot::gp_numversion <= "4.006" and $PDL::Graphics::Gnuplot::gp_pl <= 5) 0 45 45
Condition33%1/3
$PDL::Graphics::Gnuplot::gp_numversion <= "4.006" and $PDL::Graphics::Gnuplot::gp_pl <= 5
!ll&&!rl&&r
4500
MC/DC0%0/2
$PDL::Graphics::Gnuplot::gp_numversion <= "4.006" and $PDL::Graphics::Gnuplot::gp_pl <= 5
$PDL::Graphics::Gnuplot::gp_numversion <= "4.006" $PDL::Graphics::Gnuplot::gp_pl <= 5
Truth table33%1/3
A and B
A= $PDL::Graphics::Gnuplot::gp_numversion <= "4.006"B= $PDL::Graphics::Gnuplot::gp_pl <= 5
ABresult
0X0
100
111
7243 0 $echo_eating = 1;
7244 }
7245 }
7246  
7247 45 ▶ if( $gp_numversion < $gnuplot_dep_v and !$PDL::Graphics::Gnuplot::deprecated_this_session ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PDL::Graphics::Gnuplot::gp_numversion < $PDL::Graphics::Gnuplot::gnuplot_dep_v and not $PDL::Graphics::Gnuplot::deprecated_this_session) 0 45 45
Condition33%1/3
$PDL::Graphics::Gnuplot::gp_numversion < $PDL::Graphics::Gnuplot::gnuplot_dep_v and not $PDL::Graphics::Gnuplot::deprecated_this_session
!ll&&!rl&&r
4500
MC/DC0%0/2
$PDL::Graphics::Gnuplot::gp_numversion < $PDL::Graphics::Gnuplot::gnuplot_dep_v and not $PDL::Graphics::Gnuplot::deprecated_this_session
$PDL::Graphics::Gnuplot::gp_numversion < $PDL::Graphics::Gnuplot::gnuplot_dep_v not $PDL::Graphics::Gnuplot::deprecated_this_session
Truth table33%1/3
A and not(B)
A= $PDL::Graphics::Gnuplot::gp_numversion < $PDL::Graphics::Gnuplot::gnuplot_dep_vB= not $PDL::Graphics::Gnuplot::deprecated_this_session
ABresult
0X0
100
111
7248 0 $PDL::Graphics::Gnuplot::deprecated_this_session = 1;
7249 0 ▶ unless($ENV{GNUPLOT_DEPRECATED}){
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"GNUPLOT_DEPRECATED"}) 0 0 0
7250 0 carp <<"EOM";
7251  
7252 ***************************************************************************
7253 WARNING: Your gnuplot version ($gp_version) is deprecated and may cause
7254 plotting errors or random behavior. It is suggested you upgrade to v$gnuplot_dep_v.
7255 To silence this warning, set the GNUPLOT_DEPRECATED environment variable.
7256 ***************************************************************************
7257  
7258 EOM
7259 }
7260 0 $this->{early_gnuplot} = 1;
7261 }
7262  
7263  
7264 } else {
7265 0 carp <<"EOM"
7266 WARNING: Gnuplot commands are being dumped to stdout.
7267 EOM
7268 ;
7269 0 $this->{early_gnuplot} = 0;
7270 }
7271  
7272 ## Stash these in the object (legacy)
7273 45 our $valid_terms; # defined in _load_alien_gnuplot.
7274 45 our $unknown_terms; # ditto
7275 45 $this->{valid_terms} = $valid_terms;
7276 45 $this->{unknown_terms} = $unknown_terms;
7277  
7278 45 _checkpoint($this, "main");
7279  
7280 45 $this;
7281 }
7282  
7283 ##############################
7284 ##############################
7285 # _killGnuplot - clean up the mess!
7286  
7287 88 ▶sub _killGnuplot {
Subroutine _killGnuplot: called CC=12 SCAR=31.4
7288 88 my $this = shift;
7289 88 my $suffix = shift;
7290 88 my $kill_it_dead = shift;
7291  
7292 88 ▶ unless(defined($suffix)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $suffix) 44 44 88
7293 44 for my $k(keys %$this) {
7294 865 ▶ next unless $k =~ m/^pid\-(.*)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $k =~ /^pid\-(.*)$/ 821 44 865
7295 44 _killGnuplot($this,$1, $kill_it_dead);
7296 }
7297 44 return;
7298 }
7299  
7300 44 ▶ if( defined $this->{"pid-$suffix"})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$this{"pid-$suffix"}) 44 0 44
7301 {
7302 44 my $goner = $this->{"pid-$suffix"};
7303  
7304 44 my $z;
7305  
7306 44 ▶ if($kill_it_dead) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kill_it_dead) { } 0 44 44
7307 # Just want it dead.
7308 0 kill 'KILL', $goner;
7309 0 $z = waitpid($goner,0);
7310  
7311 } else {
7312 44 ▶ _printGnuplotPipe($this,$suffix,"unset multiplot\n") if $this->{options}{multiplot};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"options"}{"multiplot"} 1 43 44
7313 44 ▶ _printGnuplotPipe($this,$suffix,"set term qt 0 close\n") if ($this->{terminal}//'') eq 'qt';
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"terminal"} // "") eq "qt" 0 44 44
Condition50%1/2
$this->{"terminal"} // ""
l!l
440
MC/DC0%0/1
$this->{"terminal"} // ""
$this->{"terminal"}
Truth table50%1/2
A
A= $this->{"terminal"}
Aresult
11
00
7314 44 _printGnuplotPipe($this,$suffix,"exit\n");
7315  
7316 # Give it 2 seconds to quit, then interrupt it again.
7317 # If that doesn't work kill it dead.
7318 44 my $countdown = 2;
7319  
7320 # In case of ^C, give up and kill the process dead.
7321 0 ▶ local($SIG{INT}) = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
7322 0 kill 'KILL', $goner;
7323 0 alarm(0);
7324 0 $countdown = -5;
7325 44 };
7326  
7327 0 ▶ local($SIG{ALRM}) = sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
7328 0 $countdown--;
7329 0 ▶ if($countdown <= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($countdown <= 2) 0 0 0
7330 0 kill 'HUP',$goner;
7331 }
7332 0 ▶ if($countdown > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($countdown > 0) { } 0 0 0
7333 0 alarm(1);
7334 } else {
7335 0 ▶ kill 'KILL', $goner unless($countdown > 0 or $countdown < -4);
Branch: 1 branch
BranchTrueFalseTotal
unless $countdown > 0 or $countdown < -4 0 0 0
Condition0%0/3
$countdown > 0 or $countdown < -4
l!l&&r!l&&!r
000
MC/DC0%0/2
$countdown > 0 or $countdown < -4
$countdown > 0 $countdown < -4
Truth table0%0/3
A or B
A= $countdown > 0B= $countdown < -4
ABresult
1X1
011
000
7336 0 alarm(0);
7337 }
7338 44 };
7339 44 alarm(1);
7340  
7341 44 $z = waitpid($goner, 0);
7342 44 alarm(0);
7343 }
7344  
7345 44 ▶ unless($z == $goner) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($z == $goner) 0 44 44
7346 # If for some reason it didn't die, fire and forget.
7347 0 kill 'KILL', $goner;
7348 0 waitpid( $goner, 0 ) ;
7349 }
7350  
7351 # This clears the status bits from the killed process, so
7352 # we don't report anomalous error when we finally exit.
7353 44 $? = 0;
7354 }
7355  
7356 44 for (map { $_."-$suffix" } qw/in err errSelector pid/) {
7357 176 ▶ delete $this->{$_} if(exists $this->{$_});
Branch: 1 branch
BranchTrueFalseTotal
if exists $this->{$_} 176 0 176
7358 }
7359  
7360 44 $this;
7361 }
7362  
7363  
7364  
7365 ##############################
7366 # _printGnuplotPipe - output stuff to the pipe.
7367 #
7368 # Used for both commands and data.
7369 #
7370 sub _printGnuplotPipe
7371 703 ▶{
Subroutine _printGnuplotPipe: called CC=35 SCAR=63.6
7372 703 my $this = shift;
7373 703 my $suffix = shift;
7374 703 my $string = shift;
7375  
7376 0 ▶ local($SIG{PIPE}) = sub { _killGnuplot($this,undef,1); die "PDL::Graphics::Gnuplot: subproc died.\n";};
Subroutine __ANON__: not called CC=1 SCAR=2.6
7377  
7378 703 ▶ unless(defined($this->{"in-$suffix"})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $$this{"in-$suffix"}) 0 703 703
7379 0 _startGnuplot($this,$suffix);
7380 }
7381  
7382 # hashref
7383 # $flags->{data} if this is data, not a command;
7384 # $flags->{binary} if $string has binary data
7385 703 my $flags = shift;
7386 703 ▶ $flags = {} unless defined $flags;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $flags 614 89 703
7387  
7388 # Autodetect the dump option
7389 # If it gets set or unset, restart gnuplot
7390 703 ▶ if(($this->{options}{dump} && !$this->{dumping}) or
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"options"}{"dump"} and not $this->{"dumping"} or $this->{"dumping"} and not $this->{"options"}{"dump"}) 0 703 703
Condition33%3/9
$this->{"options"}{"dump"} and not $this->{"dumping"} or $this->{"dumping"} and not $this->{"options"}{"dump"}
l!l&&r!l&&!r
00703
$this->{"options"}{"dump"} and not $this->{"dumping"}
!ll&&!rl&&r
70300
$this->{"dumping"} and not $this->{"options"}{"dump"}
!ll&&!rl&&r
70300
MC/DC0%0/4
$this->{"options"}{"dump"} and not $this->{"dumping"} or $this->{"dumping"} and not $this->{"options"}{"dump"}
$this->{"options"}{"dump"} not $this->{"dumping"} $this->{"dumping"} not $this->{"options"}{"dump"}
Truth table14%1/7
A and not(B) or C and not(D)
A= $this->{"options"}{"dump"}B= not $this->{"dumping"}C= $this->{"dumping"}D= not $this->{"options"}{"dump"}
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
7391 ($this->{dumping} && !$this->{options}{dump})
7392 ) {
7393 0 $this->restart(1);
7394  
7395 0 ▶ if($this->{dumping}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'dumping'}) { } 0 0 0
7396 0 carp "(killed gnuplot)\n";
7397 } else {
7398 0 carp "(restarted gnuplot)\n";
7399 }
7400 }
7401  
7402 703 my $pipein = $this->{"in-$suffix"};
7403  
7404 703 ▶ unless($this->{dumping}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($this->{"dumping"}) 703 0 703
7405 # Feed the pipe robustly. Some platforms can only ship 640kB at a time, so keep sending chunks.
7406 703 my $int_flag = 0;
7407 703 my $of = 0;
7408 703 my $len;
7409 703 my $s = $SIG{INT};
7410 0 ▶ local $SIG{INT} = sub { $int_flag = 1; };
Subroutine __ANON__: not called CC=1 SCAR=1.2
7411  
7412 # Write out the string in 640kiB chunks to enable interruption
7413 703 my $pipeerr = $this->{"err-$suffix"};
7414 703 my $pipeselector = $this->{"errSelector-$suffix"};
7415  
7416 703 ▶ if($MS_io_braindamage) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PDL::Graphics::Gnuplot::MS_io_braindamage) { } 0 703 703
7417 0 my $chunksize= 655360;
7418  
7419 0 ▶ if(length($string)) { # Only write nonempty strings :-)
Branch: 1 branch
BranchTrueFalseTotal
if (length $string) 0 0 0
7420 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$of < length $string and not $int_flag and do { do { $len = syswrite($pipein, substr($string, $of), $chunksize); if (not defined $len or $len == 0) { my $err = defined $len ? "(No error but 0 bytes written)" : $! // "(Huh - no error code in \$!)"; barf('PDL::Graphics::Gnuplot: Error while writing ' . length($string) . " bytes to the gnuplot pipe.\nError was:\n\t$err"); } ; $of += $len } } 0 0 0
Condition0%0/3
$of < length $string and not $int_flag
!ll&&!rl&&r
000
MC/DC0%0/2
$of < length $string and not $int_flag
$of < length $string not $int_flag
Truth table0%0/3
A and not(B)
A= $of < length $stringB= not $int_flag
ABresult
0X0
100
111
7421 # Send the next block out.
7422 0 $len = syswrite($pipein,substr($string,$of),$chunksize);
7423 0 ▶ if(!defined($len) or $len==0) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $len or $len == 0) 0 0 0
Condition0%0/3
not defined $len or $len == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $len or $len == 0
not defined $len $len == 0
Truth table0%0/3
not(A) or B
A= not defined $lenB= $len == 0
ABresult
1X1
011
000
7424 0 ▶ my $err = defined($len) ? "(No error but 0 bytes written)" : $! // "(Huh - no error code in \$!)";
Branch: 1 branch
BranchTrueFalseTotal
defined $len ? : 0 0 0
Condition0%0/2
$! // "(Huh - no error code in \$!)"
l!l
00
MC/DC0%0/1
$! // "(Huh - no error code in \$!)"
$!
Truth table0%0/2
A
A= $!
Aresult
11
00
7425 0 barf "PDL::Graphics::Gnuplot: Error while writing ".
7426 length($string).
7427 " bytes to the gnuplot pipe.\nError was:\n\t$err";
7428 }
7429 0 $of += $len;
7430 } while $of < length($string) and !$int_flag;
7431  
7432 0 ▶ if($int_flag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($int_flag) 0 0 0
7433 # We were interrupted, which hoses up gnuplot. Restart gnuplot.
7434 0 _killGnuplot($this,undef,1);
7435 0 _startGnuplot($this,'main');
7436 0 ▶ _startGnuplot($this,'syntax') if($check_syntax);
Branch: 1 branch
BranchTrueFalseTotal
if $PDL::Graphics::Gnuplot::check_syntax 0 0 0
7437 0 my $str = "PDL::Graphics::Gnuplot: interrupted while sending data; restarted gnuplot.\n";
7438 0 ▶ if(ref($s) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $s eq "CODE") 0 0 0
7439 0 carp $str;
7440 0 &$s;
7441 }
7442 0 die $str;
7443 }
7444 }
7445 } else {
7446 703 $len = syswrite($pipein, $string);
7447 703 ▶ if( $int_flag ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($int_flag) 0 703 703
7448 0 _killGnuplot($this, undef, 1);
7449 0 _startGnuplot($this, 'main');
7450 0 ▶ _startGnuplot($this, 'syntax') if($check_syntax);
Branch: 1 branch
BranchTrueFalseTotal
if $PDL::Graphics::Gnuplot::check_syntax 0 0 0
7451 0 my $str = "PDL::Graphics::Gnuplot: interrupted while sending data; restarted gnuplot.\n";
7452 0 ▶ if(ref($s) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $s eq "CODE") 0 0 0
7453 0 carp $str;
7454 0 &$s;
7455 }
7456 0 die $str;
7457 }
7458 }
7459 }
7460  
7461 # Mockup for half-duplex pty and pty mockups (e.g. testing Windows support)
7462 703 ▶ if($debug_echo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PDL::Graphics::Gnuplot::debug_echo) 0 703 703
7463 0 my $k = "echobuffer-$suffix";
7464 0 ▶ $this->{$k} = "" unless(defined($this->{$k}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this->{$k} 0 0 0
7465 0 my $s = $string;
7466 0 ▶ $s =~ s/^/gnuplot> /msg unless($flags->{data});
Branch: 1 branch
BranchTrueFalseTotal
unless $flags->{"data"} 0 0 0
7467 0 $this->{$k} .= $s;
7468 }
7469  
7470 # Various debugging options.
7471 703 ▶ if( $this->{dumping} || $this->{options}{tee} )
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"dumping"} or $this->{"options"}{"tee"}) 0 703 703
Condition33%1/3
$this->{"dumping"} or $this->{"options"}{"tee"}
l!l&&r!l&&!r
00703
MC/DC0%0/2
$this->{"dumping"} or $this->{"options"}{"tee"}
$this->{"dumping"} $this->{"options"}{"tee"}
Truth table33%1/3
A or B
A= $this->{"dumping"}B= $this->{"options"}{"tee"}
ABresult
1X1
011
000
7472 {
7473 0 my $debug_display_string;
7474 0 ▶ if ( $flags->{binary} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($flags->{'binary'} and $this->{'options'}{'tee'} && $this->{'options'}{'tee'} eq 'nobinary' || $this->{'dumping'} && $this->{'dumping'} eq 'nobinary') { } 0 0 0
Condition0%0/12
$flags->{"binary"} and $this->{"options"}{"tee"} && $this->{"options"}{"tee"} eq "nobinary" || $this->{"dumping"} && $this->{"dumping"} eq "nobinary"
!ll&&!rl&&r
000
$this->{"options"}{"tee"} and $this->{"options"}{"tee"} eq "nobinary" or $this->{"dumping"} and $this->{"dumping"} eq "nobinary"
l!l&&r!l&&!r
000
$this->{"options"}{"tee"} and $this->{"options"}{"tee"} eq "nobinary"
!ll&&!rl&&r
000
$this->{"dumping"} and $this->{"dumping"} eq "nobinary"
!ll&&!rl&&r
000
MC/DC0%0/5
$flags->{"binary"} and $this->{"options"}{"tee"} && $this->{"options"}{"tee"} eq "nobinary" || $this->{"dumping"} && $this->{"dumping"} eq "nobinary"
$flags->{"binary"} $this->{"options"}{"tee"} $this->{"options"}{"tee"} eq "nobinary" $this->{"dumping"} $this->{"dumping"} eq "nobinary"
Truth table0%0/8
A and B and C or D and E
A= $flags->{"binary"}B= $this->{"options"}{"tee"}C= $this->{"options"}{"tee"} eq "nobinary"D= $this->{"dumping"}E= $this->{"dumping"} eq "nobinary"
ABCDEresult
0XXXX0
10X0X0
10X100
1100X0
110100
111XX1
10X111
110111
7475 (
7476 $this->{options}{tee} && $this->{options}{tee} eq 'nobinary' ||
7477 $this->{dumping} && $this->{dumping} eq 'nobinary'
7478 )
7479 )
7480 {
7481 0 $debug_display_string = sprintf('< %d bytes of binary data suppressed >',length($string));
7482 }
7483 else
7484 {
7485 0 $debug_display_string = $string;
7486 }
7487  
7488 0 ▶ if($this->{dumping}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"dumping"}) 0 0 0
7489 0 print $debug_display_string;
7490 }
7491  
7492 0 ▶ if( $this->{options}{tee} )
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"options"}{"tee"}) 0 0 0
7493 {
7494 0 my $len = length $string;
7495 0 _logEvent($this,
7496 "Sent to child process (suffix $suffix) $len bytes==========\n" . $debug_display_string . "\n=========================" );
7497 }
7498 }
7499  
7500 }
7501  
7502 ##############################
7503 # _checkpoint -- synchronize the child and parent processes. After
7504 # _checkpoint() returns, we know that we have read all the data from
7505 # the child. Extra data that represents errors is returned. Warnings
7506 # are explicitly stripped out
7507 3 our $cp_serial = 0;
7508  
7509 3 my $graphics_re = qr/^(?:qt\.|XType:|MESA:|QSocketNotifier:|glx:|failed to load).*/m;
7510 307 ▶sub _checkpoint {
Subroutine _checkpoint: called CC=44 SCAR=49.6
7511 307 my $this = shift;
7512 307 ▶ my $suffix = shift || "main";
Condition50%1/2
shift() || 'main'
l!l
3070
MC/DC0%0/1
shift() || 'main'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
7513 307 ▶ my $opt = shift() // {};
Condition100%2/2
shift() // {}
l!l
24859
MC/DC100%1/1
shift() // {}
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
7514 307 ▶ my $notimeout = $opt->{notimeout} // 0;
Condition50%1/2
$opt->{"notimeout"} // 0
l!l
0307
MC/DC0%0/1
$opt->{"notimeout"} // 0
$opt->{"notimeout"}
Truth table50%1/2
A
A= $opt->{"notimeout"}
Aresult
11
00
7515 307 ▶ my $printwarnings = $opt->{printwarnings} && !$this->{options}{silent};
Condition66%2/3
$opt->{'printwarnings'} && !$this->{'options'}{'silent'}
!ll&&!rl&&r
590248
MC/DC50%1/2
$opt->{'printwarnings'} && !$this->{'options'}{'silent'}
$opt->{'printwarnings'} !$this->{'options'}{'silent'}
Truth table66%2/3
A && not(B)
A= $opt->{'printwarnings'}B= !$this->{'options'}{'silent'}
ABresult
0X0
100
111
7516 307 ▶ my $ignore_errors = $opt->{ignore_errors} // 0;
Condition50%1/2
$opt->{"ignore_errors"} // 0
l!l
0307
MC/DC0%0/1
$opt->{"ignore_errors"} // 0
$opt->{"ignore_errors"}
Truth table50%1/2
A
A= $opt->{"ignore_errors"}
Aresult
11
00
7517  
7518 307 my $pipeerr = $this->{"err-$suffix"};
7519  
7520 # string containing various options to this function
7521 307 my $flags = shift;
7522  
7523 # I have no way of knowing if the child process has sent its error data
7524 # yet. It may be that an error has already occurred, but the message hasn't
7525 # yet arrived. I thus print out a checkpoint message and keep reading the
7526 # child's STDERR pipe until I get that message back. Any errors would have
7527 # been printed before this
7528 307 $cp_serial++;
7529 307 my $checkpoint = "xxxxxxx Synchronizing gnuplot i/o $cp_serial xxxxxxx";
7530  
7531 307 _printGnuplotPipe( $this, $suffix, "\n\nprint \"$checkpoint\"\n" );
7532  
7533  
7534 # if no error pipe exists, we can't check for errors, so we're done. Usually
7535 # happens if($dump)
7536 307 ▶ return "" unless defined $pipeerr;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pipeerr 0 307 307
7537  
7538 307 ▶ return "" if $this->{dumping}; # dumping - never generate an error.
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"dumping"} 0 307 307
7539  
7540 307 my $int = $SIG{INT};
7541 307 local $SIG{INT} = $int;
7542  
7543 # Queue up a SIGINT handler, with passthrough...
7544 307 ▶ unless($MS_io_braindamage) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDL::Graphics::Gnuplot::MS_io_braindamage) 307 0 307
7545 $SIG{INT} =
7546 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
7547 0 kill 'INT', $this->{"pid-$suffix"};
7548 0 ▶ if(ref $int eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $int eq "CODE") 0 0 0
7549 0 &$int;
7550 }
7551 0 die "^C received during PDL::Graphics::Gnuplot checkpoint operation\n";
7552 307 };
7553 }
7554  
7555 307 ▶ _logEvent($this, "Trying to read from gnuplot (suffix $suffix)") if $this->{options}{tee};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"options"}{"tee"} 0 307 307
7556  
7557 307 my $terminal = $this->{options}{terminal};
7558 307 ▶ my $delay = (($this->{wait} // 0) + 0) || 10;
Condition100%4/4
($this->{'wait'} // 0) + 0 || 10
l!l
2305
$this->{"wait"} // 0
l!l
2305
MC/DC100%1/1
($this->{'wait'} // 0) + 0 || 10
$this->{"wait"}
Truth table100%2/2
A
A= $this->{"wait"}
Aresult
11
00
7559 307 my $fromerr = '';
7560  
7561 307 ▶ if($this->{"echobuffer-$suffix"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$this{"echobuffer-$suffix"}) 0 307 307
7562 0 $fromerr = $this->{"echobuffer-$suffix"};
7563 0 $this->{"echobuffer-$suffix"} = "";
7564 }
7565  
7566 307 my $subproc_gone = 0 ;
7567  
7568 0 ▶ local($SIG{PIPE}) = sub { $subproc_gone = 1; };
Subroutine __ANON__: not called CC=1 SCAR=1.2
7569  
7570 do
7571 307 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
($fromerr =~ /^$checkpoint/ms or $subproc_gone) or do { do { if ($PDL::Graphics::Gnuplot::MS_io_braindamage or $$this{"errSelector-$suffix"}->can_read($notimeout ? undef : $delay)) { my $byte; sysread $pipeerr, $byte, $PDL::Graphics::Gnuplot::MS_io_braindamage ? 1 : 100; $fromerr .= $byte; if ($byte eq \4 or $byte eq \0 or not length $byte) { $subproc_gone = 1; } ; } else { _logEvent($this, "Gnuplot $suffix read timed out") if $this->{"options"}{"tee"}; $$this{"stuck-$suffix"} = 1; kill "INT", $$this{"pid-$suffix"}; barf(qq[Hmmm, my $suffix Gnuplot process didn't respond for $delay seconds.\nI've kicked it with an interrupt signal, which should help with the\nnext thing you try to do. If you expect slow response from gnuplot,\nyou can adjust the timeout with the "wait" terminal option.\n]); } } } 306 12 318
Condition66%2/3
$fromerr =~ /^$checkpoint/ms or $subproc_gone
l!l&&r!l&&!r
306012
MC/DC50%1/2
$fromerr =~ /^$checkpoint/ms or $subproc_gone
$fromerr =~ /^$checkpoint/ms $subproc_gone
Truth table66%2/3
A or B
A= $fromerr =~ /^$checkpoint/msB= $subproc_gone
ABresult
1X1
011
000
7572 # if no data received in a few seconds, the gnuplot
7573 # process is stuck. This usually happens if the gnuplot
7574 # process is not in a command mode, but in a
7575 # data-receiving mode. I'm careful to avoid this
7576 # situation, but bugs in this module and/or in gnuplot
7577 # itself can make this happen
7578 #
7579 # Note that the nice asynchronous part of this loop won't
7580 # work on Microsoft Windows, since that OS doesn't have a
7581 # working asynchronous read, and can_read doesn't work
7582 # either.
7583  
7584 319 ▶ if( $MS_io_braindamage or
Branch: 2 branches
BranchTrueFalseTotal
if ($PDL::Graphics::Gnuplot::MS_io_braindamage or $$this{"errSelector-$suffix"}->can_read($notimeout ? undef : $delay)) { } 318 1 319
$notimeout ? : 0 319 319
Condition66%2/3
$PDL::Graphics::Gnuplot::MS_io_braindamage or $$this{"errSelector-$suffix"}->can_read($notimeout ? undef : $delay)
l!l&&r!l&&!r
03181
MC/DC50%1/2
$PDL::Graphics::Gnuplot::MS_io_braindamage or $$this{"errSelector-$suffix"}->can_read($notimeout ? undef : $delay)
$PDL::Graphics::Gnuplot::MS_io_braindamage $$this{"errSelector-$suffix"}->can_read($notimeout ? undef : $delay)
Truth table66%2/3
A or B
A= $PDL::Graphics::Gnuplot::MS_io_braindamageB= $$this{"errSelector-$suffix"}->can_read($notimeout ? undef : $delay)
ABresult
1X1
011
000
7585 $this->{"errSelector-$suffix"}->can_read($notimeout ? undef : $delay )
7586 )
7587 {
7588 318 my $byte;
7589 318 ▶ sysread $pipeerr, $byte, ($MS_io_braindamage ? 1 : 100);
Branch: 1 branch
BranchTrueFalseTotal
$PDL::Graphics::Gnuplot::MS_io_braindamage ? : 0 318 318
7590 318 $fromerr .= $byte;
7591 318 ▶ if($byte eq \004 or $byte eq \000 or !length($byte)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($byte eq \4 or $byte eq \0 or not length $byte) 0 318 318
Condition33%2/6
$byte eq \4 or $byte eq \0 or not length $byte
l!l&&r!l&&!r
00318
$byte eq \4 or $byte eq \0
l!l&&r!l&&!r
00318
MC/DC0%0/3
$byte eq \4 or $byte eq \0 or not length $byte
$byte eq \4 $byte eq \0 not length $byte
Truth table25%1/4
A or B or not(C)
A= $byte eq \4B= $byte eq \0C= not length $byte
ABCresult
1XX1
01X1
0011
0000
7592 0 $subproc_gone = 1;
7593 }
7594 }
7595 else
7596 {
7597 1 ▶ _logEvent($this, "Gnuplot $suffix read timed out") if $this->{options}{tee};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"options"}{"tee"} 0 1 1
7598 1 $this->{"stuck-$suffix"} = 1;
7599 1 kill 'INT', $this->{"pid-$suffix"};
7600 1 barf <<"EOM";
7601 Hmmm, my $suffix Gnuplot process didn't respond for $delay seconds.
7602 I've kicked it with an interrupt signal, which should help with the
7603 next thing you try to do. If you expect slow response from gnuplot,
7604 you can adjust the timeout with the "wait" terminal option.
7605 EOM
7606 }
7607 } until ($fromerr =~ m/^$checkpoint/ms or $subproc_gone);
7608  
7609 306 ▶ if($MS_io_braindamage) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PDL::Graphics::Gnuplot::MS_io_braindamage) 0 306 306
7610 # Fix newline braindamage too
7611 0 $fromerr =~ s/\r\n/\n/g;
7612 }
7613  
7614 306 ▶ if($subproc_gone) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subproc_gone) 0 306 306
7615 0 _killGnuplot($this, undef, 1);
7616 0 barf "PDL::Graphics::Gnuplot: the gnuplot process seems to have died.\n";
7617 }
7618  
7619 306 ▶ _logEvent($this, "Read string '$fromerr' from gnuplot $suffix process") if $this->{options}{tee};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"options"}{"tee"} 0 306 306
7620  
7621 # Discard prompt-and-command lines up to the last prompt seen.
7622 # This is necessary for MS Windows support: MS Windows doesn't have
7623 # a notion of a tty versus other kind of pipe, so gnuplot always
7624 # prints prompts and echoes commands. Since there isn't much in the
7625 # way of error syntax, we might miss a few errors this way. Oh well.
7626 306 ▶ if($MS_io_braindamage) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PDL::Graphics::Gnuplot::MS_io_braindamage) 0 306 306
7627 0 $fromerr =~ s/[\s\n\r]*(gnu|multi)plot\>[^\n\r]*$//msg;
7628 0 $fromerr =~ s/[\s\n\r]*input data \(\'e\' ends\) \>[^\n\r]*$//msg;
7629 }
7630  
7631 # Strip the checkpoint message.
7632 306 $fromerr =~ s/\s*(.*?)\s*$checkpoint.*$/$1/ms;
7633  
7634 # Replace non-printable ASCII characters with '?'
7635 # (preserve ^I [tab], ^J [newline], and ^M [return])
7636 306 $fromerr =~ s/[\000-\010\013-\014\016-\037\200-\377]/\?/g;
7637  
7638 # Find, report, and strip warnings. This is complicated by the fact
7639 # that some warnings come with a line specifier and others don't.
7640  
7641 306 ▶ WARN: while( $fromerr =~ m/^(\s*(line \d+\:\s*)?[wW]arning\:.*)$/m or
Branch: 1 branch
BranchTrueFalseTotal
if ($fromerr =~ /^(\s*(line \d+\:\s*)?[wW]arning\:.*)$/m or $fromerr =~ /$graphics_re/ or $fromerr =~ /^Populating font family aliases took/m) 1 306 307
Condition66%4/6
$fromerr =~ /^(\s*(line \d+\:\s*)?[wW]arning\:.*)$/m or $fromerr =~ /$graphics_re/ or $fromerr =~ /^Populating font family aliases took/m
l!l&&r!l&&!r
10306
$fromerr =~ /^(\s*(line \d+\:\s*)?[wW]arning\:.*)$/m or $fromerr =~ /$graphics_re/
l!l&&r!l&&!r
10306
MC/DC33%1/3
$fromerr =~ /^(\s*(line \d+\:\s*)?[wW]arning\:.*)$/m or $fromerr =~ /$graphics_re/ or $fromerr =~ /^Populating font family aliases took/m
$fromerr =~ /^(\s*(line \d+\:\s*)?[wW]arning\:.*)$/m $fromerr =~ /$graphics_re/ $fromerr =~ /^Populating font family aliases took/m
Truth table50%2/4
A or B or C
A= $fromerr =~ /^(\s*(line \d+\:\s*)?[wW]arning\:.*)$/mB= $fromerr =~ /$graphics_re/C= $fromerr =~ /^Populating font family aliases took/m
ABCresult
1XX1
01X1
0011
0000
7642 $fromerr =~ m/$graphics_re/ or
7643 $fromerr =~ m/^Populating font family aliases took/m # CED - Quicktime on MacOS Catalina throws a warning marked as an error. Stupid.
7644 ) {
7645 1 ▶ if ($2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($2) { } 0 1 1
7646 # it's a warning with a line specifier. Break off two more lines before it.
7647 0 ▶ last WARN unless($fromerr =~ s/^((gnu|multi)plot\>.*\n\s*\^\s*\n\s*(line \d+\:\s*)?[wW]arning\:.*(\n|$))//m);
Branch: 1 branch
BranchTrueFalseTotal
unless $fromerr =~ s/^((gnu|multi)plot\>.*\n\s*\^\s*\n\s*(line \d+\:\s*)?[wW]arning\:.*(\n|$))//m 0 0 0
7648 0 my $a = $1;
7649 0 $a =~ s/^\s*line \d+\:/Gnuplot:/m;
7650 0 ▶ carp $a if($printwarnings);
Branch: 1 branch
BranchTrueFalseTotal
if $printwarnings 0 0 0
7651 } else {
7652 1 $fromerr =~ s/$graphics_re//;
7653 1 ▶ last WARN unless $fromerr =~ s/^(\s*(line \d+\:\s*)?[wW](arning\:.*(\n|$)))//m;
Branch: 1 branch
BranchTrueFalseTotal
unless $fromerr =~ s/^(\s*(line \d+\:\s*)?[wW](arning\:.*(\n|$)))//m 0 1 1
7654 1 ▶ carp "Gnuplot w$3\n" if($printwarnings);
Branch: 1 branch
BranchTrueFalseTotal
if $printwarnings 1 0 1
7655 }
7656  
7657 }
7658  
7659 # Anything else is an error -- except on Microsoft Windows where we
7660 # get additional chaff on the channel. Try to take it out.
7661 306 ▶ if($MS_io_braindamage) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PDL::Graphics::Gnuplot::MS_io_braindamage) { } 0 306 306
7662 0 $fromerr =~ s/^\s*Terminal type set to \'[^\']*\'.*Options are \'[^\']*\'//s;
7663 } else {
7664 # Hack to avoid spurious the pdfcairo errors in MacOS 10.5 - strip out obsolete-function errors.
7665 306 ▶ while( $fromerr =~ s/^.*obsolete\s*function.*system\s*performance.\s*//s or
Branch: 1 branch
BranchTrueFalseTotal
if ($fromerr =~ s/^.*obsolete\s*function.*system\s*performance.\s*//s or $fromerr =~ s/^.*Populating font family aliases took.*cost\.//s) 0 306 306
Condition33%1/3
$fromerr =~ s/^.*obsolete\s*function.*system\s*performance.\s*//s or $fromerr =~ s/^.*Populating font family aliases took.*cost\.//s
l!l&&r!l&&!r
00306
MC/DC0%0/2
$fromerr =~ s/^.*obsolete\s*function.*system\s*performance.\s*//s or $fromerr =~ s/^.*Populating font family aliases took.*cost\.//s
$fromerr =~ s/^.*obsolete\s*function.*system\s*performance.\s*//s $fromerr =~ s/^.*Populating font family aliases took.*cost\.//s
Truth table33%1/3
A or B
A= $fromerr =~ s/^.*obsolete\s*function.*system\s*performance.\s*//sB= $fromerr =~ s/^.*Populating font family aliases took.*cost\.//s
ABresult
1X1
011
000
7666 $fromerr =~ s/^.*Populating font family aliases took.*cost\.//s
7667 ) {
7668 # do nothing
7669 }
7670 }
7671  
7672 306 ▶ if((!$ignore_errors) and (($fromerr =~ m/^\s+\^\s*$/ms or $fromerr=~ m/^\s*line/ms) or
Branch: 1 branch
BranchTrueFalseTotal
if (not $ignore_errors and $fromerr =~ /^\s+\^\s*$/ms || $fromerr =~ /^\s*line/ms || $fromerr =~ /(fail(ed|s)?)|(error)|(expected \w+ driver)/io) 1 305 306
Condition66%6/9
not $ignore_errors and $fromerr =~ /^\s+\^\s*$/ms || $fromerr =~ /^\s*line/ms || $fromerr =~ /(fail(ed|s)?)|(error)|(expected \w+ driver)/io
!ll&&!rl&&r
03051
$fromerr =~ /^\s+\^\s*$/ms or $fromerr =~ /^\s*line/ms or $fromerr =~ /(fail(ed|s)?)|(error)|(expected \w+ driver)/io
l!l&&r!l&&!r
10305
$fromerr =~ /^\s+\^\s*$/ms or $fromerr =~ /^\s*line/ms
l!l&&r!l&&!r
10305
MC/DC25%1/4
not $ignore_errors and $fromerr =~ /^\s+\^\s*$/ms || $fromerr =~ /^\s*line/ms || $fromerr =~ /(fail(ed|s)?)|(error)|(expected \w+ driver)/io
not $ignore_errors $fromerr =~ /^\s+\^\s*$/ms $fromerr =~ /^\s*line/ms $fromerr =~ /(fail(ed|s)?)|(error)|(expected \w+ driver)/io
Truth table40%2/5
not(A) and B or C or D
A= not $ignore_errorsB= $fromerr =~ /^\s+\^\s*$/msC= $fromerr =~ /^\s*line/msD= $fromerr =~ /(fail(ed|s)?)|(error)|(expected \w+ driver)/io
ABCDresult
0XXX0
10000
11XX1
101X1
10011
7673 # This is really stupid -- many error messages from gnuplot aren't labeled as such, so we can't mark
7674 # them as errors. Try some common keywords for genuine error messages.
7675 $fromerr =~ m/(fail(ed|s)?)|(error)|(expected \w+ driver)/io
7676 )
7677 ) {
7678 1 ▶ if($this->{early_gnuplot}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($this->{'early_gnuplot'}) { } 0 1 1
elsif ($fromerr =~ /^line \d+: warning:/) { } 0 1 1
7679 0 barf "PDL::Graphics::Gnuplot: ERROR: the deprecated pre-v$gnuplot_dep_v gnuplot backend issued an error:\n$fromerr\n";
7680 } elsif ($fromerr =~ /^line \d+: warning:/) {
7681 0 warn "PDL::Graphics::Gnuplot: the gnuplot backend issued a warning:\n$fromerr\n";
7682 0 $fromerr = '';
7683 } else {
7684 1 barf "PDL::Graphics::Gnuplot: ERROR: the gnuplot backend issued an error:\n$fromerr\n";
7685 }
7686 }
7687  
7688 # strip whitespace
7689 305 $fromerr =~ s/^\s*//s;
7690 305 $fromerr =~ s/\s*$//s;
7691 305 return $fromerr;
7692 }
7693  
7694 ##############################
7695 # Get gnuplot to report its own supported feature-set.
7696 #
7697 # NOTE this needs to be fixed-up to just copy the featuresets from Alien::Gnuplot!
7698  
7699 sub _getGnuplotFeatures
7700 3 ▶{
Subroutine _getGnuplotFeatures: called CC=6 SCAR=18.3
7701 # I could use qx{} to talk to gnuplot here, but I don't want to use a
7702 # tty. gnuplot messes with the tty settings where it should NOT. For example
7703 # it turns on the local echo
7704  
7705 3 my %featureSet;
7706  
7707 # first, I run 'gnuplot --help' to extract all the cmdline options as features
7708 {
7709 3 my $in = '';
7710 3 my $out = '';
7711 3 my $err = '';
7712 3 eval{ IPC::Run::run([ $Alien::Gnuplot::executable, "--help"], \$in, \$out, \$err) };
7713 3 ▶ barf $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 3 3
7714  
7715 3 foreach ( "$out\n$err\n" =~ /--([a-zA-Z0-9_]+)/g )
7716 {
7717 15 $featureSet{$_} = 1;
7718 }
7719 }
7720  
7721 # then I try to set a square aspect ratio for 3D to see if it works
7722 {
7723 3 my $in = <<EOM;
7724 set view equal
7725 exit
7726 EOM
7727 3 my $out = '';
7728 3 my $err = '';
7729  
7730  
7731 3 eval{ IPC::Run::run([ $Alien::Gnuplot::executable ], \$in, \$out, \$err) };
7732 3 ▶ barf $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 3 3
7733  
7734 # no output if works; some output if error
7735 3 ▶ $featureSet{equal_3d} = 1 unless ($out || $err);
Branch: 1 branch
BranchTrueFalseTotal
unless $out or $err 0 3 3
Condition33%1/3
$out or $err
l!l&&r!l&&!r
030
MC/DC0%0/2
$out or $err
$out $err
Truth table33%1/3
A or B
A= $outB= $err
ABresult
1X1
011
000
7736 }
7737  
7738  
7739 3 return %featureSet;
7740 }
7741  
7742 sub _logEvent
7743 0 ▶{
Subroutine _logEvent: not called CC=2 SCAR=17.9
7744 0 my $this = shift;
7745 0 my $event = shift;
7746  
7747 0 ▶ return unless $this->{options}{tee}; # only log when asked.
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"options"}{"tee"} 0 0 0
7748  
7749 0 my $t1 = tv_interval( $this->{t0}, [gettimeofday] );
7750 0 printf STDERR "==== PDL::Graphics::Gnuplot t=%.4f: %s\n", $t1, $event;
7751 }
7752  
7753  
7754 ##############################
7755 # Helper routine detects method call vs. function call
7756 # syntax, and initializes the global object if necessary.
7757 #
7758 198 ▶sub _obj_or_global {
Subroutine _obj_or_global: called CC=3 SCAR=11.0
7759 198 my $arglist = shift;
7760 198 my $this;
7761 198 ▶ if( $arglist->[0]->$_isa("PDL::Graphics::Gnuplot") ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arglist->[0]->$PDL::Graphics::Gnuplot::_isa('PDL::Graphics::Gnuplot')) { } 193 5 198
7762 193 $this = shift @$arglist;
7763 } else {
7764 5 undef $@;
7765 5 ▶ unless( $globalPlot->$_isa("PDL::Graphics::Gnuplot") ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDL::Graphics::Gnuplot::globalPlot->$PDL::Graphics::Gnuplot::_isa("PDL::Graphics::Gnuplot")) 1 4 5
7766 1 undef $@;
7767 1 $globalPlot = new("PDL::Graphics::Gnuplot") ;
7768 }
7769 5 $globalPlot->{options}{globalPlot} = 1;
7770 5 $this = $globalPlot;
7771 }
7772 198 return $this;
7773 }
7774  
7775 ##############################
7776 ##############################
7777 ### Prefrobnicators - preprocess data before plotting, for custom plot styles
7778 ###
7779 ### Currently there is only one - used for FITS image plotting. It's
7780 ### necessary because FITS images often have nonlinear mappings
7781 ### between pixel and scientific coordinates.
7782  
7783 3 ▶sub _make_fits_hdr {
Subroutine _make_fits_hdr: called CC=1 SCAR=0.0
7784 3 my ($x, $y, $x_pix, $y_pix, $x_min, $y_min, $x_max, $y_max, $x_type, $y_type, $x_unit, $y_unit) = @_;
7785 {
7786 3 NAXIS=>2,
7787 NAXIS1=> $x, NAXIS2=> $y,
7788 CRPIX1=> $x_pix, CRPIX2=> $y_pix,
7789 CRVAL1=> $x_min, CRVAL2=> $y_min,
7790 CDELT1=> ($x_max-$x_min)/$x,
7791 CDELT2=> ($y_max-$y_min)/$y,
7792 CTYPE1=> $x_type, CTYPE2=> $y_type,
7793 CUNIT1=> $x_unit, CUNIT2=> $x_unit
7794 };
7795 }
7796  
7797 ##############################
7798 # _with_fits_prefrobnicator
7799 #
7800 # We support a "with fits" image style that produces output in scientific
7801 # coordinates from a FITS file. Ideally, we would simply produce an (x,y) grid
7802 # that supplies scientific coordinates for each pixel -- but that doesn't work
7803 # in the general case due to shortcomings with gnuplot itself: the three-element
7804 # tuple form of "with image" only works for affine transformations between
7805 # pixel coordinates and scientific plane coordinates.
7806 #
7807 6 ▶sub _with_fits_prefrobnicator {
Subroutine _with_fits_prefrobnicator: called CC=29 SCAR=38.9
7808 6 my ($with, $this, $chunk, @data ) = @_;
7809 6 ▶ eval "use PDL::Transform";
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
7810 6 ▶ barf "PDL::Graphics::Gnuplot: couldn't load PDL::Transform for 'with fits' option: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 6 6
7811 6 ▶ barf "PDL::Graphics::Gnuplot: 'with fits' special option requires a single FITS image\n" if @data != 1;
Branch: 1 branch
BranchTrueFalseTotal
if @data != 1 0 6 6
7812 6 my $data = $data[0];
7813 6 ▶ barf "PDL::Graphics::Gnuplot: 'with fits' needs an image, RGB triplet, or RGBA quad\n" unless $data->ndims==2 || ($data->ndims==3 && ($data->dim(2)==4 || $data->dim(2)==3 || $data->dim(2)==1));
Branch: 1 branch
BranchTrueFalseTotal
unless $data->ndims == 2 or $data->ndims == 3 and $data->dim(2) == 4 || $data->dim(2) == 3 || $data->dim(2) == 1 0 6 6
Condition41%5/12
$data->ndims == 2 or $data->ndims == 3 and $data->dim(2) == 4 || $data->dim(2) == 3 || $data->dim(2) == 1
l!l&&r!l&&!r
510
$data->ndims == 3 and $data->dim(2) == 4 || $data->dim(2) == 3 || $data->dim(2) == 1
!ll&&!rl&&r
001
$data->dim(2) == 4 or $data->dim(2) == 3 or $data->dim(2) == 1
l!l&&r!l&&!r
100
$data->dim(2) == 4 or $data->dim(2) == 3
l!l&&r!l&&!r
010
MC/DC0%0/5
$data->ndims == 2 or $data->ndims == 3 and $data->dim(2) == 4 || $data->dim(2) == 3 || $data->dim(2) == 1
$data->ndims == 2 $data->ndims == 3 $data->dim(2) == 4 $data->dim(2) == 3 $data->dim(2) == 1
Truth table33%2/6
A or B and C or D or E
A= $data->ndims == 2B= $data->ndims == 3C= $data->dim(2) == 4D= $data->dim(2) == 3E= $data->dim(2) == 1
ABCDEresult
1XXXX1
011XX1
0101X1
010011
00XXX0
010000
7814 6 my $h = $data->gethdr;
7815 barf "PDL::Graphics::Gnuplot: 'with fits' expected a FITS header\n"
7816 6 ▶ unless $h && ref $h eq 'HASH' && !grep !$h->{$_}, qw(NAXIS NAXIS1 NAXIS2);
Branch: 1 branch
BranchTrueFalseTotal
unless $h and ref $h eq "HASH" and not grep((!$h->{$_}), ("NAXIS", "NAXIS1", "NAXIS2")) 1 5 6
Condition66%4/6
$h and ref $h eq "HASH" and not grep((!$h->{$_}), ("NAXIS", "NAXIS1", "NAXIS2"))
!ll&&!rl&&r
105
$h and ref $h eq "HASH"
!ll&&!rl&&r
105
MC/DC33%1/3
$h and ref $h eq "HASH" and not grep((!$h->{$_}), ("NAXIS", "NAXIS1", "NAXIS2"))
$h ref $h eq "HASH" not grep((!$h->{$_}), ("NAXIS", "NAXIS1", "NAXIS2"))
Truth table50%2/4
A and B and not(C)
A= $hB= ref $h eq "HASH"C= not grep((!$h->{$_}), ("NAXIS", "NAXIS1", "NAXIS2"))
ABCresult
0XX0
10X0
1100
1111
7817 5 ▶ if (my $resample = $chunk->{options}{resample}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $resample = $chunk->{"options"}{"resample"}) 2 3 5
7818 # Now find the dataspace boundaries for the map, so we don't waste pixels.
7819 2 ▶ my ($xmin, $xmax) = @{$this->{options}{xrange}||[]};
Condition50%1/2
$this->{'options'}{'xrange'} || []
l!l
02
MC/DC0%0/1
$this->{'options'}{'xrange'} || []
$this->{'options'}{'xrange'}
Truth table50%1/2
A
A= $this->{'options'}{'xrange'}
Aresult
11
00
7820 2 ▶ my ($ymin, $ymax) = @{$this->{options}{yrange}||[]};
Condition50%1/2
$this->{'options'}{'yrange'} || []
l!l
02
MC/DC0%0/1
$this->{'options'}{'yrange'} || []
$this->{'options'}{'yrange'}
Truth table50%1/2
A
A= $this->{'options'}{'yrange'}
Aresult
11
00
7821 2 ▶ unless (defined($xmin) && defined($xmax) && defined($ymin) && defined($ymax)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $xmin and defined $xmax and defined $ymin and defined $ymax) 2 0 2
Condition33%3/9
defined $xmin and defined $xmax and defined $ymin and defined $ymax
!ll&&!rl&&r
200
defined $xmin and defined $xmax and defined $ymin
!ll&&!rl&&r
200
defined $xmin and defined $xmax
!ll&&!rl&&r
200
MC/DC0%0/4
defined $xmin and defined $xmax and defined $ymin and defined $ymax
defined $xmin defined $xmax defined $ymin defined $ymax
Truth table20%1/5
A and B and C and D
A= defined $xminB= defined $xmaxC= defined $yminD= defined $ymax
ABCDresult
0XXX0
10XX0
110X0
11100
11111
7822 2 my $pix_corners = pdl([0,0],[0,1],[1,0],[1,1]) * pdl($data->dim(0),$data->dim(1)) - 0.5;
7823 2 my $corners = $pix_corners->apply(t_fits($h));
7824 2 ▶ $xmin //= $corners->slice("(0)")->min;
Condition33%1/3
$xmin //= $corners->slice("(0)")->min
l!l&&r!l&&!r
020
MC/DC0%0/2
$xmin //= $corners->slice("(0)")->min
$xmin $corners->slice("(0)")->min
Truth table33%1/3
A //= B
A= $xminB= $corners->slice("(0)")->min
ABresult
1X1
011
000
7825 2 ▶ $xmax //= $corners->slice("(0)")->max;
Condition33%1/3
$xmax //= $corners->slice("(0)")->max
l!l&&r!l&&!r
020
MC/DC0%0/2
$xmax //= $corners->slice("(0)")->max
$xmax $corners->slice("(0)")->max
Truth table33%1/3
A //= B
A= $xmaxB= $corners->slice("(0)")->max
ABresult
1X1
011
000
7826 2 ▶ $ymin //= $corners->slice("(1)")->min;
Condition33%1/3
$ymin //= $corners->slice("(1)")->min
l!l&&r!l&&!r
020
MC/DC0%0/2
$ymin //= $corners->slice("(1)")->min
$ymin $corners->slice("(1)")->min
Truth table33%1/3
A //= B
A= $yminB= $corners->slice("(1)")->min
ABresult
1X1
011
000
7827 2 ▶ $ymax //= $corners->slice("(1)")->max;
Condition33%1/3
$ymax //= $corners->slice("(1)")->max
l!l&&r!l&&!r
020
MC/DC0%0/2
$ymax //= $corners->slice("(1)")->max
$ymax $corners->slice("(1)")->max
Truth table33%1/3
A //= B
A= $ymaxB= $corners->slice("(1)")->max
ABresult
1X1
011
000
7828 }
7829 2 ▶ ($xmin, $xmax) = ($xmax, $xmin) if $xmin > $xmax;
Branch: 1 branch
BranchTrueFalseTotal
if $xmin > $xmax 0 2 2
7830 2 ▶ ($ymin, $ymax) = ($ymax, $ymin) if $ymin > $ymax;
Branch: 1 branch
BranchTrueFalseTotal
if $ymin > $ymax 0 2 2
7831 2 my $d1 = $data->double;
7832 2 ▶ $d1->sethdr($h) if !$d1->gethdr; # ie converted and no hdrcpy
Branch: 1 branch
BranchTrueFalseTotal
unless $d1->gethdr 0 2 2
7833 2 $h = _make_fits_hdr(@$resample, 0.5, 0.5, $xmin, $ymin, $xmax, $ymax, @$h{qw(CTYPE1 CTYPE2 CUNIT1 CUNIT2)});
7834 2 $data = $d1->map( t_identity(), $h, {method=>'h'} ); # Rescale into coordinates proportional to the scientific ones
7835 }
7836 # Now update plot options to set the axis labels, if they haven't been updated already...
7837 5 for ([qw(xlabel CTYPE1 X CUNIT1 (pixels))],
7838 [qw(ylabel CTYPE2 Y CUNIT2 (pixels))],
7839 [qw(cblabel BTYPE Value BUNIT), ''],
7840 ) {
7841 15 my ($label, $type, $typel, $unit, $unitdef) = @$_;
7842 15 ▶ next if defined $this->{options}{$label};
Branch: 1 branch
BranchTrueFalseTotal
if defined $this->{"options"}{$label} 0 15 15
7843 $this->{tmp_options}{$label} = [join(" ",
7844 $h->{$type} || $typel,
7845 15 ▶ $h->{$unit} ? "($h->{$unit})" : $unitdef
Branch: 1 branch
BranchTrueFalseTotal
$h->{$unit} ? : 11 4 15
Condition66%2/3
$h->{$type} || $typel
l!l&&r!l&&!r
1050
MC/DC0%0/2
$h->{$type} || $typel
$h->{$type} $typel
Truth table66%2/3
A || B
A= $h->{$type}B= $typel
ABresult
1X1
011
000
7846 )];
7847 }
7848 5 $with->[0] = 'image';
7849 5 (ndcoords(map $data->dim($_), 0,1)->apply(t_fits($h, {ignore_rgb=>1}))->mv(0,-1)->dog, $data);
7850 }
7851  
7852 ##########
7853 # Helper routine to escape backslashes and such for gnuplot double-quote strings
7854 111 ▶sub quote_escape {
Subroutine quote_escape: called CC=1 SCAR=0.0
Pod undocumented
7855 111 my $s = shift;
7856 111 $s =~ s/\\/\\\\/g;
7857 111 $s =~ s/\"/\\\"/g;
7858 111 $s =~ s/\012/\\n/g;
7859 111 $s =~ s/\013/\\r/g;
7860 111 return $s;
7861 }
7862  
7863  
7864 =head1 COMPATIBILITY
7865  
7866 Everything should work on all platforms that support Gnuplot and Perl.
7867 Currently, MacOS, Fedora and Debian Linux, Cygwin, and Microsoft
7868 Windows (under both Active State Strawberry Perl) have been tested to
7869 work, although the interprocess control link is not as reliable under
7870 Microsoft Windows as under POSIX systems. Please report successes or
7871 failures on other platforms to the authors. A transcript of a failed
7872 run with {tee => 1} would be most helpful.
7873  
7874 =head1 REPOSITORY
7875  
7876 L<https://github.com/drzowie/PDL-Graphics-Gnuplot>
7877  
7878 =head1 AUTHOR
7879  
7880 Craig DeForest, C<< <craig@deforest.org> >> and Dima Kogan, C<< <dima@secretsauce.net> >>
7881  
7882 =head1 STILL TO DO
7883  
7884 =over 3
7885  
7886 =item some plot and curve options need better parsing:
7887  
7888 =over 3
7889  
7890 =item - labels need attention (plot option labels)
7891  
7892 They need to be handled as hashes, not just as array refs. Also, they don't seem to be working with timestamps.
7893 Further, deeply nested options (e.g. "at" for labels) need attention.
7894  
7895 =back
7896  
7897 =item - new plot styles
7898  
7899 The "boxplot" plot style (new to gnuplot 4.6?) requires a different using
7900 syntax and will require some hacking to support.
7901  
7902 =back
7903  
7904 =head1 LICENSE AND COPYRIGHT
7905  
7906 Copyright 2011-2013 Craig DeForest and Dima Kogan
7907  
7908 This program is free software; you can redistribute it and/or modify it
7909 under the terms of either: the GNU General Public License as published
7910 by the Free Software Foundation; or the Perl Artistic License included with
7911 the Perl language.
7912  
7913 See http://dev.perl.org/licenses/ for more information.
7914  
7915 =cut
7916  
7917 3 1;
↑ Summary Demos/Gnuplot.pm »