Quiq/Gd/Component/BlockDiagram.pm

filter: Statementstmt 27.5% 16 / 58 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 71.4% 5 / 7 Podpod 100% 2 / 2 totaltotal 28.4% 23 / 81 CC 8 SCAR 37.3
CC
8
Cov
23%
render
72.0
new
2.0
BEGIN
1.0
CRAP 41.6
« Quiq/Template.pm ↑ Summary Quiq/Database/Connection.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::Gd::Component::BlockDiagram - Farbige Blöcke in einer Fläche
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Gd::Component>
12  
13 =head1 ATTRIBUTES
14  
15 Fett hervorgehobene Attribute sind Pflichtangaben beim Konstruktor-Aufruf.
16  
17 =over 4
18  
19 =item B<< width => $int >> (Default: keiner)
20  
21 Breite der Grafik in Pixeln.
22  
23 =item B<< height => $int >> (Default: keiner)
24  
25 Höhe der Grafik in Pixeln.
26  
27 =item xMin => $f (Default: Minimum der X-Werte)
28  
29 Anfang des X-Wertebereichs (Weltkoodinate).
30  
31 =item xMax => $f (Default: Maximum der X-Werte)
32  
33 Ende des X-Wertebereichs (Weltkoodinate).
34  
35 =item yMin => $f (Default: Minimum der Y-Werte)
36  
37 Anfang des Y-Wertebereichs (Weltkoodinate).
38  
39 =item yMax => $f (Default: Maximum der Y-Werte)
40  
41 Ende des Y-Wertebereichs (Weltkoodinate).
42  
43 =item yReverse => $bool (Default: 0)
44  
45 Die Y-Achse geht von oben nach unten statt von unten nach oben,
46 d.h. die kleineren Werte sind oben.
47  
48 =item objects => \@objects (Default: [])
49  
50 Liste der Objekte, die die Blockinformation liefern.
51  
52 =item objectCallback => $sub
53  
54 Subroutine, die aus einem Objekt die Block-Information liefert.
55 Signatur:
56  
57 sub {
58 my $obj = shift;
59 ...
60 return ($x,$y,$width,$height,$color);
61 }
62  
63 =back
64  
65 =head1 EXAMPLE
66  
67 =begin html
68  
69 <p class="sdoc-fig-p">
70 <img class="sdoc-fig-img" src="https://raw.github.com/s31tz/Quiq/master/img/quiq-gd-component-blockdiagram.png" width="430" height="887" alt="" />
71 </p>
72  
73 =end html
74  
75 =cut
76  
77 # -----------------------------------------------------------------------------
78  
79 package Quiq::Gd::Component::BlockDiagram;
80 2 ▶use base qw/Quiq::Gd::Component/;
Subroutine BEGIN: called CC=1 SCAR=0.0
81  
82 2 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
83 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
84 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
85  
86 2 our $VERSION = '1.240';
87  
88 2 ▶use Quiq::Math;
Subroutine BEGIN: called CC=1 SCAR=0.0
89  
90 # -----------------------------------------------------------------------------
91  
92 =head1 METHODS
93  
94 =head2 Konstruktor
95  
96 =head3 new() - Konstruktor
97  
98 =head4 Synopsis
99  
100 $g = $class->new(@keyVal);
101  
102 =head4 Description
103  
104 Instantiiere ein Blockdiagramm-Objekt mit den Eigenschaften @keyVal
105 (s. Abschnitt L<ATTRIBUTES|"ATTRIBUTES">) und liefere eine Referenz auf das Objekt
106 zurück.
107  
108 =cut
109  
110 # -----------------------------------------------------------------------------
111  
112 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
113 0 my $class = shift;
114 # @_: @keyVal
115  
116 0 my $self = $class->SUPER::new(
117 width => undef,
118 height => undef,
119 xMin => undef,
120 xMax => undef,
121 yMin => undef,
122 yMax => undef,
123 yReverse => 0,
124 objects => [],
125 objectCallback => undef,
126 );
127 0 $self->set(@_);
128  
129 0 return $self;
130 }
131  
132 # -----------------------------------------------------------------------------
133  
134 =head2 Zeichnen
135  
136 =head3 render() - Zeichne Grafik
137  
138 =head4 Synopsis
139  
140 @blocks | $blockA = $g->render($img);
141 @blocks | $blockA = $g->render($img,$x,$y,@keyVal);
142 @blocks | $blockA = $class->render($img,$x,$y,@keyVal);
143  
144 =head4 Returns
145  
146 Liste der gezeichneten Blöcke. Im Skalarkontext eine Referenz auf
147 die Liste. Ein Listenelement hat die Komponenten:
148  
149 [$obj,$x1,$y1,$x2,$y2]
150  
151 Ein Element gibt zu jedem Objekt die Pixelkoordinaten des Blocks
152 im Bild $img an.
153  
154 =head4 Description
155  
156 Zeichne die Grafik in Bild $img an Position ($x,$y).
157  
158 =cut
159  
160 # -----------------------------------------------------------------------------
161  
162 0 ▶sub render {
Subroutine render: not called CC=8 SCAR=42.8
Pod documented
163 0 my $this = shift;
164 0 my $img = shift;
165 0 ▶ my $x = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
166 0 ▶ my $y = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
167 # @_: @keyVal
168  
169 0 my $self = $this->self(@_);
170  
171 # Attribute
172  
173 0 my $width = $self->{'width'};
174 0 my $height = $self->{'height'};
175 0 my $xMin = $self->{'xMin'};
176 0 my $xMax = $self->{'xMax'};
177 0 my $yMin = $self->{'yMin'};
178 0 my $yMax = $self->{'yMax'};
179 0 my $yReverse = $self->{'yReverse'};
180 0 my $objectA = $self->{'objects'};
181 0 my $objectCallback = $self->{'objectCallback'};
182  
183 # Zeichnen
184
185 0 my $m = Quiq::Math->new;
186  
187 0 my $xFactor = $m->valueToPixelFactor($width,$xMin,$xMax);
188 0 my $yFactor = $m->valueToPixelFactor($height,$yMin,$yMax);
189  
190 0 my @blocks;
191 0 my $black = $img->color('#000000');
192 0 for my $obj (@$objectA) {
193 0 my ($oX,$oY,$oW,$oH,$rgb,$border) = $objectCallback->($obj);
194  
195 0 my $color = $img->color($rgb);
196  
197 0 my $pX = $x+$m->valueToPixelX($width,$xMin,$xMax,$oX);
198 0 my $pY;
199 0 ▶ if ($yReverse) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yReverse) { } 0 0 0
200 0 $pY = $y+$m->valueToPixelYTop($height,$yMin,$yMax,$oY);
201 }
202 else {
203 0 $pY = $y+$m->valueToPixelY($height,$yMin,$yMax,$oY);
204 }
205 0 my $pW = $oW*$xFactor-1; # -1 -> 1 Pixel Lücke zw. den Blöcken
206 0 my $pH = $oH*$yFactor;
207  
208 0 my ($x1,$y1,$x2,$y2);
209 0 ▶ if ($yReverse) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yReverse) { } 0 0 0
210 0 ($x1,$y1,$x2,$y2) = (int($pX),int($pY),int($pX+$pW),int($pY+$pH));
211 }
212 else {
213 0 ($x1,$y1,$x2,$y2) = (int($pX),int($pY-$pH),int($pX+$pW),int($pY));
214 }
215  
216 0 $img->filledRectangle($x1,$y1,$x2,$y2,$color);
217 0 ▶ if ($border) {
Branch: 1 branch
BranchTrueFalseTotal
if ($border) 0 0 0
218 0 $img->rectangle($x1,$y1,$x2,$y2,$black);
219 }
220  
221 0 push @blocks,[$obj,$x1,$y1,$x2,$y2];
222 }
223  
224 0 ▶ return wantarray? @blocks: \@blocks;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
225 }
226  
227 # -----------------------------------------------------------------------------
228  
229 =head1 VERSION
230  
231 1.240
232  
233 =head1 AUTHOR
234  
235 Frank Seitz, L<http://fseitz.de/>
236  
237 =head1 COPYRIGHT
238  
239 Copyright (C) 2026 Frank Seitz
240  
241 =head1 LICENSE
242  
243 This code is free software; you can redistribute it and/or modify
244 it under the same terms as Perl itself.
245  
246 =cut
247  
248 # -----------------------------------------------------------------------------
249  
250 2 1;
251  
252 # eof
« Quiq/Template.pm ↑ Summary Quiq/Database/Connection.pm »