blib/lib/PDL/Graphics/PGPLOTOptions.pm

filter: Statementstmt 30.9% 13 / 42 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 60.0% 3 / 5 Podpod 50.0% 1 / 2 totaltotal 25.0% 17 / 68 CC 10 SCAR 33.6
CC
10
Cov
22%
set_pgplot_options
42.0
default_options
30.0
BEGIN
1.0
CRAP 28.9
« blib/lib/PDL/Demos/Gnuplot_demo.pm ↑ Summary blib/lib/PDL/Fit/LM.pm »
1 =head1 NAME
2  
3 PDL::Graphics::PGPLOTOptions - Setting PGPLOT options
4  
5 =head1 SYNOPSIS
6  
7 use PGPLOTOptions qw('default_options');
8  
9 =head1 DESCRIPTION
10  
11 This package contains one function (at present) which returns PDL::Option
12 objects for default settings for plot windows and plot commands. This
13 should be complemented by functions that could affect this such as
14 file reading commands etc.
15  
16 =head1 OPTIONS
17  
18 The following is a listing of options that are set in this file and what
19 they do and what their default value is
20  
21 =head2 Window specific options
22  
23 These options modify the appearance of windows and can also modify the
24 default settings for creation of plot axes etc.
25  
26 =over
27  
28 =item Device
29  
30 The default PGPLOT device to use. The default value is set to the PGPLOT_DEV
31 environment variable if set, otherwise to '?'.
32  
33 =item AxisColour
34  
35 The colour with which to draw axes. Default value=3 (Green)
36  
37 =item HardLW, HardCH, HardFont, HardAxisColour, HardColour
38  
39 The linewidth, character height, font and axis colour to use on hardcopy
40 devices. The default values are HardLW=1, HardCH=1.4, HardFont=2 (Roman),
41 HardAxisColour=1 (Black) and HardColour=1 as well. The latter is the default
42 plot colour to use on hardcopy devices.
43  
44 =item Axis
45  
46 The axis style to use. See the L<PDL::Graphics::PGPLOT::Window> documentation
47 for details. It defaults to 'Normal' which is a labelled box. Valid arguments
48 are 'Empty', 'Box', 'Normal', 'Axes', 'Grid', 'LogX', 'LogY', 'LogXY'.
49  
50 =item AspectRatio
51  
52 The aspect ratio of the output device. The default value is device dependent.
53  
54 =item WindowWidth
55  
56 The width of the output window in inches and defaults to as big as possible.
57  
58 =item WindowXSize and WindowYSize
59  
60 These are alternatives to AspectRatio and WindowWidth.
61  
62 =item WindowName
63  
64 The name of the window - can later be retrieved using name(). It defaults
65 to 'Window'+Window ID.
66  
67 =item NXPanel
68  
69 The number of panels in the X-direction - defaults to 1
70  
71 =item NYPanel
72  
73 The number of panels in the Y-direction - defaults to 1
74  
75 =item Justify
76  
77 A boolean value which, if true, causes both axes to drawn
78 to the same scale; see
79 the PGPLOT C<pgenv()> command for more information.
80  
81 =item TightLabels
82  
83 Boolean value which, if true, causes axis labels to be pulled
84 slightly closer to the main viewport than usual. That's handy
85 for making multi-panel plots. Undef (the default) is equivalent
86 to 0 for panels with NYPanels <= 1 and 1 for panels with NYPanels > 1.
87  
88 =item TitleSize
89  
90 The relative size of a plot or image title, compared to other annotations.
91 Defaults to 1.0 (original behavior) but can be set to, e.g., 1.5 to
92 emphasize graph titles in a multipanel plot.
93  
94 =item Border
95  
96 Adjust the spacing around the plot. See the documentation in
97 L<PDL::Graphics::PGPLOT::Window> for details.
98  
99 =item CharSize
100  
101 The default charsize for the plot - used when annotating the axes for
102 instance. It defaults to 1.
103  
104 =item PlotPosition
105  
106 The position of the plot in normalised coordinates.
107  
108 =item Erase
109  
110 Explicitly erase the plotting surface, normally required when making new
111 plots with PlotPosition.
112  
113 =back
114  
115 =head2 Plot specific options
116  
117  
118 For the moment see the C<PDL::Graphics::PGPLOT::Window> documentation for
119 these.
120  
121  
122 =cut
123  
124 package PDL::Graphics::PGPLOTOptions;
125  
126  
127 # use PDL::Core qw/:Func :Internal/;
128 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
129 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
130 1 ▶use vars qw(@ISA @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
131  
132 1 @ISA = ('Exporter');
133 1 @EXPORT_OK = qw(default_options set_pgplot_options);
134  
135 #
136 # To be able to set options outside of PGPLOT in the .perldlrc I will
137 # have to define these local variables.
138 #
139 1 my %options = (
140 Device => undef,
141 AxisColour => 3,
142 BackgroundColour => -1, # Text background colour
143 HardLW => 1,
144 HardCH => 1.4,
145 HardFont => 2,
146 HardAxisColour => 1,
147 HardColour => 1,
148 Axis => 'BCNST', # see kludge in Window::imag if you change this
149 AspectRatio => undef,
150 WindowWidth => undef,
151 WindowXSize => undef,
152 WindowYSize => undef,
153 Size => undef,
154 Unit=> undef,
155 WindowName => '',
156 NXPanel => 1,
157 NYPanel => 1,
158 Justify => 0, # Justification of boxes & axes
159 Scale=> undef, # device pixels per data pixel
160 Pitch=> undef, # Horizontal data pixels per <unit>
161 Unit => undef, # Unit for pitch
162 Pix => undef, # Pixel aspect ratio
163 Align => undef, # Alignment of viewport within plot area
164 DirAxis=> undef, # Default direction of axes
165 Border => 0,
166 CharSize => 1,
167 Symbol => 17,
168 Colour => 5,
169 ErrTerm => 1,
170 LineStyle => 1,
171 Font => 1,
172 Fill => 1,
173 ITF => 0,
174 Transform => undef,
175 LineWidth => 1,
176 XRange => undef,
177 YRange => undef,
178 Arrow => {FS => 1, Angle => 45.0, Vent => 0.3,
179 ArrowSize => undef},
180 Hatch => {Angle => 45.0, Separation => 1.0, Phase => 0.0},
181 XTitle => '',
182 YTitle => '',
183 Title => '',
184 );
185  
186  
187 sub default_options {
188  
189  
190 0 ▶ my $DEV=undef;
Subroutine default_options: not called CC=5 SCAR=34.0
Pod undocumented
191 # Use the standard PGPLOT environment variable.
192 0 ▶ $DEV = $ENV{"PGPLOT_DEV"} if defined $ENV{"PGPLOT_DEV"};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"PGPLOT_DEV"} 0 0 0
193 # However if the user has specified the Perl-ish variable use that.
194 0 ▶ $DEV = $options{Device} if defined($options{Device});
Branch: 1 branch
BranchTrueFalseTotal
if defined $options{"Device"} 0 0 0
195 0 ▶ $DEV = "?" if !defined($DEV) || $DEV eq ""; # Safe default
Branch: 1 branch
BranchTrueFalseTotal
if not defined $DEV or $DEV eq "" 0 0 0
Condition0%0/3
not defined $DEV or $DEV eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $DEV or $DEV eq ""
not defined $DEV $DEV eq ""
Truth table0%0/3
not(A) or B
A= not defined $DEVB= $DEV eq ""
ABresult
1X1
011
000
196  
197 # Options specific (primarily) to window creation
198 my $wo = {
199 Device => $DEV, ### Tidy this up.
200 AxisColour => $options{AxisColour}, # Axis colour
201 HardLW => $options{HardLW}, # Line width for hardcopy devices,
202 HardCH => $options{HardCH}, # Character height for hardcopy devices
203 HardFont => $options{HardFont}, # For for hardcopy devices
204 HardAxisColour => $options{HardAxisColour}, # Black colour as default on hardcopy devices.
205 HardColour => $options{HardColour}, # Black as default plot colour on hardcopy devices.
206 Axis => $options{Axis}, # The type of box
207 AspectRatio => $options{AspectRatio}, # The aspect ratio of the plot window.
208 WindowWidth => $options{WindowWidth}, # The width of the plot window in inches.
209 WindowXSize => $options{WindowXSize}, # The X&Y size of a window, these will be
210 WindowYSize => $options{WindowYSize}, # used to give the aspect ratio if defined.
211 Size => $options{Size}, # alternative window size spec
212 Unit => $options{Unit}, # Units for size spec
213 WindowName => $options{WindowName}, # The window name given
214 NXPanel => $options{NXPanel}, # The number of plotting panels
215 NYPanel => $options{NYPanel}, # Ditto.
216 TightLabels => undef,
217 TitleSize => 1.0,
218 Justify => $options{Justify}, # Justification of boxes & axes
219 Scale => $options{Justify}, # device pixels per data pixel
220 Pitch => $options{Pitch}, # Horizontal data pixels per unit
221 Unit => $options{Unit}, # PGPLOT unit for pitch
222 Pix => $options{Pix}, # Pixel aspect ratio
223 Align => $options{Align}, # Alignment of vp in plot area
224 DirAxis => $options{DirAxis}, # The default axis direction
225 Border => $options{Border},
226 CharSize => $options{CharSize}, # Character size for annotation
227 0 Erase => 0,
228 Recording => 0, # Off by default.
229 PlotPosition => 'Default' # The position of the plot on the page.
230 };
231  
232 # Options specific to plotting commands
233 my $o = {
234 Symbol => $options{Symbol}, # Symbol for points
235 Colour => $options{Colour}, # Colour for plots
236 CharSize => $options{CharSize}, # Character height
237 ErrTerm => $options{ErrTerm}, # Size of error-bar terminators
238 Erase => 0, # Whether to erase a panel when switching.
239 Panel => undef, # What panel to switch to.
240 LineStyle => $options{LineStyle}, # Solid linestyle
241 Font => $options{Font}, # Normal font
242 Fill => $options{Fill}, # Solid fill
243 ITF => $options{ITF}, # Linear ITF
244 Axis => $options{Axis}, # Standard axis-type
245  
246 Transform => $options{Transform}, # The transform used for plots.
247 Justify => $options{Justify}, # Justification of boxes & axes
248 Scale => $options{Justify}, # device pixels per data pixel
249 Pitch => $options{Pitch}, # Horizontal data pixels per unit
250 Unit => $options{Unit}, # PGPLOT unit for pitch
251 Pix => $options{Pix}, # Pixel aspect ratio
252 Align => $options{Align}, # Alignment of vp in plot area
253 DirAxis => $options{DirAxis}, # The default axis direction
254  
255 LineWidth => $options{LineWidth},
256 TightLabels => $options{TightLabels},
257 TitleSize => $options{TitleSize},
258 XRange => $options{XRange},
259 YRange => $options{YRange},
260 BackgroundColour => $options{BackgroundColour},
261 # The following two should really be implemented as an Options
262 # object, but that will make I/O of options somewhat difficult.
263 # Note that the arrowsize is implemented as a synonym for the
264 # charsize this should not cause any problems but might be worth
265 # noting...
266 # In addition to this the arrowsize below is also set to be undefined
267 # by default which will automatically use the character size.
268 # All these problems are historical..
269 Arrow => $options{Arrow},
270 Hatch => $options{Hatch},
271 XTitle => $options{XTitle}, # Label for X-axis
272 YTitle => $options{YTitle}, # Label for Y-axis
273 Title => $options{Title}, # Title for plot
274 0 };
275  
276  
277 # Now for the synonyms
278 0 my $s = {Color => 'Colour', 'Line-style' => 'LineStyle',
279 'Line-width' => 'LineWidth', 'Hatching' => 'Hatch',
280 FillType => 'Fill', 'ArrowSize' => 'CharSize',
281 AxisColor => 'AxisColour', HardAxisColor => 'HardAxisColour',
282 HardColor => 'HardColor', BackgroundColor => 'BackgroundColour'};
283 #
284 # And now for the lookup tables..
285 #
286 0 my $t = {
287 Colour => {
288 'White' => 0, 'Black' => 1, 'Red' => 2,
289 'Green' => 3, 'Blue' => 4, 'Cyan' => 5,
290 'Magenta' => 6, 'Yellow' => 7, 'Orange' => 8,
291 'DarkGray' => 14, 'DarkGrey' => 14,
292 'LightGray' => 15, 'LightGrey' => 15,
293 'CosmicSpectrum' => [0.269, 0.388, 0.342]
294 },
295 BackgroundColour => {
296 'White' => 0, 'Black' => 1, 'Red' => 2,
297 'Green' => 3, 'Blue' => 4, 'Cyan' => 5,
298 'Magenta' => 6, 'Yellow' => 7, 'Orange' => 8,
299 'DarkGray' => 14, 'DarkGrey' => 14,
300 'LightGray' => 15, 'LightGrey' => 15
301 },
302 Symbol => {
303 'Square' => 0, 'Dot' => 1, 'Plus' => 2,
304 'Asterisk' => 3, 'Circle' => 4, 'Cross' => 5,
305 'Triangle' => 7, 'Earth' => 8, 'Sun' => 9,
306 'Diamond' => 11, 'Star' => 12, Default => 17
307 },
308 ITF => {
309 'Linear' => 0, 'Log' => 1, 'Sqrt' => 2
310 },
311 LineStyle => {
312 'Solid' => 1, 'Dashed' => 2, 'Dot-Dash' => 3,
313 'Dotted' => 4, 'Dash-Dot-Dot' => 5,
314 '-' => 1, '--' => 2, '.-' => 3, '.' => 4,
315 '-..' => 5
316 },
317 Font => {
318 Normal => 1, Roman => 2,Italic => 3, Script => 4
319 },
320 Fill => {
321 Solid => 1, Outline => 2, Hatched => 3,
322 Cross_Hatched => 4, CrossHatched => 4
323 },
324 };
325  
326 0 my $wt = {
327 # valid values for axis parameter (eg env())
328 Axis => {
329 Empty => '', Box => 'BC', Normal => 'BCNST',
330 Axes => 'ABCNST', Grid => 'ABCGNST',
331 LogX => ['BCLNST', 'BCNST'],
332 LogY => ['BCNST', 'BCLNST'],
333 LogXY => ['BCLNST', 'BCLNST'],
334 '-2' => '', '-1' => 'BC', '0' => 'BCNST',
335 '1' => 'ABCNST', '2' => 'ABCGNST',
336 '10' => ['BCLNST', 'BCNST'],
337 '20' => ['BCNST', 'BCLNST'],
338 '30' => ['BCLNST', 'BCLNST']
339 },
340 AxisColour => {
341 'White' => 0, 'Black' => 1, 'Red' => 2,
342 'Green' => 3, 'Blue' => 4, 'Cyan' => 5,
343 'Magenta' => 6, 'Yellow' => 7, 'Orange' => 8,
344 'DarkGray' => 14, 'DarkGrey' => 14,
345 'LightGray' => 15, 'LightGrey' => 15
346 },
347 HardFont => {
348 Normal => 1, Roman => 2,Italic => 3, Script => 4
349 },
350 HardAxisColour => {
351 'White' => 0, 'Black' => 1, 'Red' => 2,
352 'Green' => 3, 'Blue' => 4, 'Cyan' => 5,
353 'Magenta' => 6, 'Yellow' => 7, 'Orange' => 8,
354 'DarkGray' => 14, 'DarkGrey' => 14,
355 'LightGray' => 15, 'LightGrey' => 15
356 }
357 };
358  
359  
360 # Set up the two primary sets of options for PGPLOT commands.
361 0 my $window_options = PDL::Options->new($wo);
362 0 $window_options->translation($wt);
363  
364 0 my $general_options = PDL::Options->new($o);
365 0 $general_options->translation($t);
366 0 $general_options->synonyms($s);
367  
368 0 return ($general_options, $window_options);
369  
370 }
371  
372  
373 =head2 set_pgplot_options
374  
375 This function allows the user to set the default PGPLOT options. It
376 is particularly useful in the C<.perldlrc> file since one can do
377  
378 use PDL::Graphics::PGPLOTOptions ('set_pgplot_options');
379 set_pgplot_options('Device' => '/xs', 'HardLW' => 3);
380  
381 for instance to set the default values. The main drawback is that the
382 routine is rather unflexible with no synonyms or case-insensitivity.
383  
384 =cut
385  
386 sub set_pgplot_options {
387 0 ▶ my %o;
Subroutine set_pgplot_options: not called CC=6 SCAR=37.4
Pod documented
388 0 ▶ if (ref($_[0]) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 0 0
389 0 %o = %{$_[0]};
390 } else {
391 0 %o = @_;
392 }
393  
394 0 foreach my $k (keys %o) {
395 0 ▶ if (exists($options{$k})) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $options{$k}) { } 0 0 0
elsif ($k =~ /Color/) { } 0 0 0
396 0 $options{$k} = $o{$k};
397 } elsif ($k =~ /Color/) {
398 0 my $knew = $k;
399 0 $knew =~ s/Color/Colour/;
400 0 ▶ if (!exists($options{$knew})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $options{$knew}) { } 0 0 0
401 0 warn "Option $k is not recognised!\n";
402 } else {
403 0 $options{$knew} = $o{$k};
404 }
405 } else {
406 0 warn "Option $k is not recognised!\n";
407 }
408 }
409  
410 }
411  
412  
413 1 1;
« blib/lib/PDL/Demos/Gnuplot_demo.pm ↑ Summary blib/lib/PDL/Fit/LM.pm »