Quiq/Gnuplot/Process.pm

filter: Statementstmt 13.5% 22 / 162 Branchbran 0.0% 0 / 76 Conditioncond 0.0% 0 / 19 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 70.0% 7 / 10 Podpod 100% 3 / 3 totaltotal 11.3% 32 / 282 CC 50 SCAR 76.2
CC
50
Cov
9%
render
2450.0
print
6.0
new
2.0
CRAP 2035.1
↑ Summary Quiq/Axis/Numeric.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::Gnuplot::Process - Gnuplot-Prozess
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Hash>
12  
13 =head1 DESCRIPTION
14  
15 Ein Objekt der Klasse repräsentiert einen Gnuplot-Prozess.
16 Ein Gnuplot-Prozess erzeugt Plots.
17  
18 =cut
19  
20 # -----------------------------------------------------------------------------
21  
22 package Quiq::Gnuplot::Process;
23 1 ▶use base qw/Quiq::Hash/;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 1 our $VERSION = '1.240';
30  
31 1 ▶use Quiq::Gnuplot::Plot;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 1 ▶use Quiq::FileHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 ▶use Quiq::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 # -----------------------------------------------------------------------------
36  
37 =head1 METHODS
38  
39 =head2 Konstruktor
40  
41 =head3 new() - Instantiiere Gnuplot-Prozess
42  
43 =head4 Synopsis
44  
45 $gnu = Quiq::Gnuplot::Process->new;
46  
47 =cut
48  
49 # -----------------------------------------------------------------------------
50  
51 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
52 0 my $class = shift;
53 # @_: @keyVal
54  
55 0 my $fh = Quiq::FileHandle->new('|-','gnuplot');
56 0 $fh->autoFlush;
57  
58 0 my $self = $class->SUPER::new(
59 debug => 0,
60 fh => $fh,
61 );
62 0 $self->set(@_);
63
64 0 return $self;
65 }
66  
67 # -----------------------------------------------------------------------------
68  
69 =head2 Objektmethoden
70  
71 =head3 render() - Rendere Plot
72  
73 =head4 Synopsis
74  
75 $gnu->render($plt);
76 $img = $gnu->render($plt); # funktioniert nicht
77  
78 =head4 Description
79  
80 Rendere den Plot und speichere ihn auf auf der angebenen Bilddatei
81 oder liefere die Bilddaten zurück. Werden die Bilddaten zurückgeliefert,
82 wird die Bilddatei automatisch gelöscht.
83  
84 =cut
85  
86 # -----------------------------------------------------------------------------
87  
88 0 ▶sub render {
Subroutine render: not called CC=49 SCAR=78.0
Pod documented
89 0 my ($self,$plt) = @_;
90  
91 0 my $fh = $self->fh;
92 0 my $timeSeries = $plt->timeSeries;
93  
94 0 ▶ if (my $terminal = $plt->terminal) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $terminal = $plt->terminal) 0 0 0
95 0 my $cmd = "set terminal $terminal";
96 0 my $width = $plt->width;
97 0 my $height = $plt->height;
98 0 ▶ if ($width && $height) {
Branch: 1 branch
BranchTrueFalseTotal
if ($width and $height) 0 0 0
Condition0%0/3
$width and $height
!ll&&!rl&&r
000
MC/DC0%0/2
$width and $height
$width $height
Truth table0%0/3
A and B
A= $widthB= $height
ABresult
0X0
100
111
99 0 $cmd .= " size $width, $height";
100 }
101 # $cmd .= ' small'; # globaler font s. S. 2006
102 0 $self->print("$cmd\n");
103 }
104 0 $self->print("set lmargin 12\n");
105 # $self->print("set size 0.5\n");
106 # $self->print("set origin 0.5,0.5\n");
107  
108 0 my $output = $plt->output;
109 0 ▶ if ($output) {
Branch: 1 branch
BranchTrueFalseTotal
if ($output) 0 0 0
110 0 $self->print("set output '$output'\n");
111 }
112  
113 0 ▶ if ($timeSeries) {
Branch: 1 branch
BranchTrueFalseTotal
if ($timeSeries) 0 0 0
114 0 $self->print("set xdata time\n");
115 # $self->print("unset autoscale x\n");
116 0 $self->print(qq|set timefmt "%Y-%m-%d %H:%M:%S"\n|);
117 0 ▶ if (my $formatX = $plt->formatX || '%H:%M') {
Branch: 1 branch
BranchTrueFalseTotal
if (my $formatX = $plt->formatX || "%H:%M") 0 0 0
Condition0%0/2
$plt->formatX || '%H:%M'
l!l
00
MC/DC0%0/1
$plt->formatX || '%H:%M'
$plt->formatX
Truth table0%0/2
A
A= $plt->formatX
Aresult
11
00
118 0 $self->print(qq|set format x "$formatX"\n|);
119 # $self->print("set format x '%H:%M'\n");
120 # $self->print("set format x '%Y-%m-%d %H:%M'\n");
121 }
122 }
123
124 0 my $xMin = $plt->xMin;
125 0 my $xMax = $plt->xMax;
126 0 ▶ if (defined $xMin || defined $xMax) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $xMin or defined $xMax) 0 0 0
Condition0%0/3
defined $xMin or defined $xMax
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $xMin or defined $xMax
defined $xMin defined $xMax
Truth table0%0/3
A or B
A= defined $xMinB= defined $xMax
ABresult
1X1
011
000
127 0 my $cmd = 'set xrange [';
128 0 ▶ if (defined $xMin) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $xMin) 0 0 0
129 0 $cmd .= "'$xMin'";
130 }
131 0 $cmd .= ':';
132 0 ▶ if (defined $xMax) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $xMax) 0 0 0
133 0 $cmd .= "'$xMax'";
134 }
135 0 $cmd .= ']';
136 0 $self->print("$cmd\n");
137 }
138  
139 0 my $yMin = $plt->yMin;
140 0 my $yMax = $plt->yMax;
141 0 ▶ if (defined $yMin || defined $yMax) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $yMin or defined $yMax) 0 0 0
Condition0%0/3
defined $yMin or defined $yMax
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $yMin or defined $yMax
defined $yMin defined $yMax
Truth table0%0/3
A or B
A= defined $yMinB= defined $yMax
ABresult
1X1
011
000
142 0 my $cmd = 'set yrange [';
143 0 ▶ if (defined $yMin) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $yMin) 0 0 0
144 0 $cmd .= $yMin;
145 }
146 0 $cmd .= ':';
147 0 ▶ if (defined $yMax) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $yMax) 0 0 0
148 0 $cmd .= $yMax;
149 }
150 0 $cmd .= ']';
151 0 $self->print("$cmd\n");
152 }
153
154 0 ▶ if (my $title = $plt->title) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $title = $plt->title) 0 0 0
155 0 my $cmd = qq|set title "$title"|;
156 0 ▶ if (my $titleFont = $plt->titleFont) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $titleFont = $plt->titleFont) 0 0 0
157 0 $cmd .= qq| font "$titleFont"|;
158 }
159 0 $self->print("$cmd\n");
160 }
161 0 ▶ if (my $xlabel = $plt->xlabel) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $xlabel = $plt->xlabel) 0 0 0
162 0 $self->print(qq|set xlabel "$xlabel"\n|);
163 }
164 0 ▶ if (my $ylabel = $plt->ylabel) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ylabel = $plt->ylabel) 0 0 0
165 0 $self->print(qq|set ylabel "$ylabel"\n|);
166 }
167  
168 0 ▶ if (my $ytics = $plt->ytics) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ytics = $plt->ytics) 0 0 0
169 0 $self->print("set ytics $ytics\n");
170 }
171
172 0 ▶ if ($plt->mxTics) {
Branch: 1 branch
BranchTrueFalseTotal
if ($plt->mxTics) 0 0 0
173 0 $self->print("set mxtics\n");
174 }
175 0 ▶ if ($plt->myTics) {
Branch: 1 branch
BranchTrueFalseTotal
if ($plt->myTics) 0 0 0
176 0 $self->print("set mytics\n");
177 }
178  
179 0 my $legendPos = $plt->legendPosition;
180 0 $self->print("set key $legendPos reverse Left box linetype 0\n");
181 0 $self->print("set grid xtics mxtics ytics mytics back\n");
182  
183 # Arrows
184
185 0 my $arwA = $plt->arrows;
186 0 ▶ if (@$arwA) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$arwA) 0 0 0
187 0 my $i = 1;
188 0 for my $arw (@$arwA) {
189 0 my $str = sprintf 'set arrow %d',$i++;
190 0 my $fromA = $arw->from;
191 0 ▶ if ($timeSeries) {
Branch: 1 branch
BranchTrueFalseTotal
if ($timeSeries) { } 0 0 0
192 0 $str .= sprintf " from '%s',%s",@$fromA;
193 }
194 else {
195 0 $str .= sprintf " from %s,%s",@$fromA;
196 }
197 0 my $toA = $arw->to;
198 0 ▶ if ($timeSeries) {
Branch: 1 branch
BranchTrueFalseTotal
if ($timeSeries) { } 0 0 0
199 0 $str .= sprintf " to '%s',%s",@$toA;
200 }
201 else {
202 0 $str .= sprintf " to %s,%s",@$toA;
203 }
204 0 ▶ if (my $heads = $arw->heads) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $heads = $arw->heads) 0 0 0
205 0 $str .= " $heads";
206 }
207 0 ▶ if (my $lineType = $arw->lineType) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $lineType = $arw->lineType) 0 0 0
208 0 $str .= " linetype $lineType";
209 }
210 0 ▶ if (my $lineWidth = $arw->lineWidth) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $lineWidth = $arw->lineWidth) 0 0 0
211 0 $str .= " linewidth $lineWidth";
212 }
213 0 ▶ if (my $lineStyle = $arw->lineStyle) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $lineStyle = $arw->lineStyle) 0 0 0
214 0 $str .= " linestyle $lineStyle";
215 }
216 0 $str .= "\n";
217 0 $self->print($str);
218 }
219 }
220  
221 # Labels
222  
223 0 my $labA = $plt->labels;
224 0 ▶ if (@$labA) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$labA) 0 0 0
225 0 my $i = 1;
226 0 for my $lab (@$labA) {
227 0 my $str = sprintf 'set label %d "%s"',$i++,$lab->text;
228 0 my $atA = $lab->at;
229 0 ▶ if ($timeSeries) {
Branch: 1 branch
BranchTrueFalseTotal
if ($timeSeries) { } 0 0 0
230 0 $str .= sprintf " at '%s',%s",@$atA;
231 }
232 else {
233 0 $str .= sprintf " at %s,%s",@$atA;
234 }
235 0 ▶ if (my $font = $lab->font) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $font = $lab->font) 0 0 0
236 0 $str .= " font '$font'";
237 }
238 0 ▶ if (my $textColor = $lab->textColor) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $textColor = $lab->textColor) 0 0 0
239 0 $str .= " tc $textColor";
240 }
241 0 $str .= "\n";
242 0 $self->print($str);
243 }
244 }
245  
246 # Graphen
247  
248 0 my $gphA = $plt->graphsWithData;
249 0 ▶ if (@$gphA) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$gphA) 0 0 0
250 0 my $str;
251 0 for my $gph (@$gphA) {
252 0 ▶ if ($str) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str) 0 0 0
253 0 $str .= ', ';
254 }
255 0 ▶ my $to = $timeSeries? 3: 2;
Branch: 1 branch
BranchTrueFalseTotal
$timeSeries ? : 0 0 0
256 0 $str .= "'-' using 1:$to";
257 0 ▶ if (my $title = $gph->title) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $title = $gph->title) { } 0 0 0
258 0 $str .= " title '$title'";
259 }
260 else {
261 0 $str .= ' notitle';
262 }
263 0 ▶ my $with = $gph->with || 'points';
Condition0%0/2
$gph->with || 'points'
l!l
00
MC/DC0%0/1
$gph->with || 'points'
$gph->with
Truth table0%0/2
A
A= $gph->with
Aresult
11
00
264 0 $str .= " with $with";
265 0 my $style = $gph->style;
266 0 ▶ if (defined $style) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $style) 0 0 0
267 0 $str .= " $style";
268 }
269 }
270 0 $self->print("plot $str\n");
271
272 0 for my $gph (@$gphA) {
273 0 my $dataA = $gph->data;
274 0 ▶ for (my $i = 0; $i < @$dataA; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$dataA) 0 0 0
275 0 my $x = $dataA->[$i];
276 0 ▶ if (!defined $x || $x eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $x or $x eq "") 0 0 0
Condition0%0/3
not defined $x or $x eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $x or $x eq ""
not defined $x $x eq ""
Truth table0%0/3
not(A) or B
A= not defined $xB= $x eq ""
ABresult
1X1
011
000
277 0 $x = 'NaN';
278 }
279 0 my $y = $dataA->[$i+1];
280 0 ▶ if (!defined $y || $y eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $y or $y eq "") 0 0 0
Condition0%0/3
not defined $y or $y eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $y or $y eq ""
not defined $y $y eq ""
Truth table0%0/3
not(A) or B
A= not defined $yB= $y eq ""
ABresult
1X1
011
000
281 0 $y = 'NaN';
282 }
283 0 $self->print("$x $y\n");
284 }
285 0 $self->print("e\n");
286 }
287 }
288  
289 0 $self->print("reset\n");
290  
291 # Forcieren, dass Gnuplot die Datei schreibt
292 0 $self->print("unset output\n");
293  
294 # Funktioniert nicht, da wir nicht wissen, wann Gnuplot die Datei
295 # zuende geschrieben hat
296  
297 #if (defined wantarray) {
298 # # Wir liefern die Bilddaten zurück und löschen die Datei
299 #
300 # my $img = Quiq::Path->read($output);
301 # Quiq::Path->delete($output);
302 # return $img;
303 #}
304  
305 # Wir liefern nichts zurück, die Bilddatei bleibt stehen
306 0 return;
307 }
308  
309 # -----------------------------------------------------------------------------
310  
311 =head3 print() - Übertrage Daten an den Gnuplot-Prozess
312  
313 =head4 Synopsis
314  
315 $gnu->print(@data);
316  
317 =cut
318  
319 # -----------------------------------------------------------------------------
320  
321 0 ▶sub print {
Subroutine print: not called CC=2 SCAR=17.9
Pod documented
322 0 my $self = shift;
323 # @_: @data
324  
325 0 my $fh = $self->fh;
326 0 $fh->print(@_);
327  
328 0 ▶ if (my $debug = $self->debug) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $debug = $self->debug) 0 0 0
329 0 warn @_;
330 }
331
332 0 return;
333 }
334  
335 # -----------------------------------------------------------------------------
336  
337 =head1 VERSION
338  
339 1.240
340  
341 =head1 AUTHOR
342  
343 Frank Seitz, L<http://fseitz.de/>
344  
345 =head1 COPYRIGHT
346  
347 Copyright (C) 2026 Frank Seitz
348  
349 =head1 LICENSE
350  
351 This code is free software; you can redistribute it and/or modify
352 it under the same terms as Perl itself.
353  
354 =cut
355  
356 # -----------------------------------------------------------------------------
357  
358 1 1;
359  
360 # eof
↑ Summary Quiq/Axis/Numeric.pm »