Quiq/Gd/Component/ColorBar.pm

filter: Statementstmt 40.6% 13 / 32 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 66.6% 4 / 6 Podpod 100% 2 / 2 totaltotal 39.5% 19 / 48 CC 5 SCAR 27.5
CC
5
Cov
34%
render
30.0
new
2.0
BEGIN
1.0
CRAP 15.6
« Quiq/Time/RFC822.pm ↑ Summary Quiq/DataStructure.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::Gd::Component::ColorBar - Rechteck mit einem Farbverlauf
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 colors => \@colors (Default: [])
28  
29 Farben des Farbverlaufs.
30  
31 =back
32  
33 =head1 EXAMPLE
34  
35 Code:
36  
37 use Quiq::Gd::Image;
38 use Quiq::Gd::Component::ColorBar;
39
40 # Konfiguration
41
42 my $width = 300;
43 my $height = 25;
44 my $numColors = 512;
45
46 # Grafik-Objekt instantiieren
47
48 my $g = Quiq::Gd::Component::ColorBar->new(
49 width=>$width,
50 height=>$height,
51 );
52
53 # Bild-Objekt instantiieren
54 my $img = Quiq::Gd::Image->new($width,$height);
55
56 # Grafik auf Bild zeichnen
57
58 $g->render($img,0,0,
59 colors=>[$img->rainbowColors($numColors)],
60 );
61  
62 Grafik:
63  
64 [Nur im Browser sichtbar]
65  
66 =cut
67  
68 # -----------------------------------------------------------------------------
69  
70 package Quiq::Gd::Component::ColorBar;
71 1 ▶use base qw/Quiq::Gd::Component/;
Subroutine BEGIN: called CC=1 SCAR=0.0
72  
73 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
74 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
75 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
76  
77 1 our $VERSION = '1.240';
78  
79 # -----------------------------------------------------------------------------
80  
81 =head1 METHODS
82  
83 =head2 Konstruktor
84  
85 =head3 new() - Konstruktor
86  
87 =head4 Synopsis
88  
89 $g = $class->new(@keyVal);
90  
91 =head4 Description
92  
93 Instantiiere ein Grafik-Objekt mit den Eigenschaften @keyVal
94 (s. Abschnitt L<ATTRIBUTES|"ATTRIBUTES">) und liefere eine Referenz auf das Objekt
95 zurück.
96  
97 =cut
98  
99 # -----------------------------------------------------------------------------
100  
101 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
102 0 my $class = shift;
103 # @_: @keyVal
104  
105 0 my $self = $class->SUPER::new(
106 width => undef,
107 height => undef,
108 colors => [],
109 );
110 0 $self->set(@_);
111  
112 0 return $self;
113 }
114  
115 # -----------------------------------------------------------------------------
116  
117 =head2 Zeichnen
118  
119 =head3 render() - Zeichne Grafik
120  
121 =head4 Synopsis
122  
123 $g->render($img);
124 $g->render($img,$x,$y,@keyVal);
125 $class->render($img,$x,$y,@keyVal);
126  
127 =head4 Description
128  
129 Zeichne die Grafik in Bild $img an Position ($x,$y).
130 Die Methode liefert keinen Wert zurück.
131  
132 =cut
133  
134 # -----------------------------------------------------------------------------
135  
136 0 ▶sub render {
Subroutine render: not called CC=5 SCAR=34.0
Pod documented
137 0 my $this = shift;
138 0 my $img = shift;
139 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
140 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
141 # @_: @keyVal
142  
143 0 my $self = $this->self(@_);
144  
145 # Attribute
146  
147 0 my $width = $self->{'width'};
148 0 my $height = $self->{'height'};
149 0 my $colorA = $self->{'colors'};
150  
151 # Zeichnen
152  
153 0 ▶ if (!@$colorA) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$colorA) 0 0 0
154 # Keine Farben, nichts zu tun
155 0 return;
156 }
157  
158 0 my $w = $width/@$colorA;
159 0 for my $color (@$colorA) {
160 0 $img->filledRectangle($x,$y,$x+$w-1,$y+$height-1,$color);
161 0 $x += $w;
162 }
163  
164 0 return;
165 }
166  
167 # -----------------------------------------------------------------------------
168  
169 =head2 Objektmethoden
170  
171 siehe L<BASE CLASS|"BASE CLASS">
172  
173 =head1 VERSION
174  
175 1.240
176  
177 =head1 AUTHOR
178  
179 Frank Seitz, L<http://fseitz.de/>
180  
181 =head1 COPYRIGHT
182  
183 Copyright (C) 2026 Frank Seitz
184  
185 =head1 LICENSE
186  
187 This code is free software; you can redistribute it and/or modify
188 it under the same terms as Perl itself.
189  
190 =cut
191  
192 # -----------------------------------------------------------------------------
193  
194 1 1;
195  
196 # eof
« Quiq/Time/RFC822.pm ↑ Summary Quiq/DataStructure.pm »