Quiq/AxisTick.pm

filter: Statementstmt 38.0% 19 / 50 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 6 / 12 Podpod 100% 6 / 6 totaltotal 43.0% 31 / 72 CC 3 SCAR 13.1
CC
3
Cov
35%
position
12.0
new
2.0
value
2.0
CRAP 3.7
« Quiq/Html/Form/Layout.pm ↑ Summary Quiq/System.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::AxisTick - Tick einer Plot-Achse
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Hash>
12  
13 =head1 DESCRIPTION
14  
15 Ein Tick-Objekt repräsentiert eine Postion auf einer Plot-Achse, an
16 der eine Markierung - mit oder ohne Label - gesetzt wird.
17 Das Tick-Objekt ist einem Achsen-Objekt zugeordnet.
18 Über das Tick-Objekt gelangt eine Klasse, die eine Plot-Achse zeichnet,
19 an alle Information, die zum Zeichnen des Tick nötig ist.
20  
21 =head1 ATTRIBUTES
22  
23 =over 4
24  
25 =item axis => $axis (Default: undef)
26  
27 Referenz auf das Achsen-Objekt.
28  
29 =item value => $val (Default: undef)
30  
31 Wert des Tick.
32  
33 =back
34  
35 =cut
36  
37 # -----------------------------------------------------------------------------
38  
39 package Quiq::AxisTick;
40 4 ▶use base qw/Quiq::Hash/;
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 4 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
45  
46 4 our $VERSION = '1.240';
47  
48 4 ▶use Quiq::Math;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 4 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
50  
51 # -----------------------------------------------------------------------------
52  
53 =head1 METHODS
54  
55 =head2 Konstruktor
56  
57 =head3 new() - Instantiiere Tick-Objekt
58  
59 =head4 Synopsis
60  
61 $tik = Quiq::AxisTick->new($axis,$val);
62  
63 =head4 Arguments
64  
65 =over 4
66  
67 =item $axis
68  
69 Referenz auf das Plot-Achsen-Objekt.
70  
71 =item $val
72  
73 Wert des Tick.
74  
75 =back
76  
77 =head4 Description
78  
79 Instantiiere ein Tick-Objekt und liefere eine Referenz auf dieses
80 Objekt zurück.
81  
82 =cut
83  
84 # -----------------------------------------------------------------------------
85  
86 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
87 0 my ($class,$axis,$val) = @_;
88  
89 0 return $class->SUPER::new(
90 axis => $axis,
91 value => $val,
92 );
93 }
94  
95 # -----------------------------------------------------------------------------
96  
97 =head2 Attributmethoden
98  
99 =head3 value() - Wert des Tick
100  
101 =head4 Synopsis
102  
103 $val = $tik->value;
104  
105 =head4 Description
106  
107 Liefere den Wert des Tick.
108  
109 =cut
110  
111 # -----------------------------------------------------------------------------
112  
113 0 ▶sub value {
Subroutine value: not called CC=1 SCAR=6.9
Pod documented
114 0 return shift->{'value'};
115 }
116  
117 # -----------------------------------------------------------------------------
118  
119 =head2 Objektmethoden
120  
121 =head3 position() - Pixel-Position auf der Achse
122  
123 =head4 Synopsis
124  
125 $pos = $tik->position;
126  
127 =head4 Description
128  
129 Liefere die Pixel-Position des Tick auf der Achse.
130  
131 =cut
132  
133 # -----------------------------------------------------------------------------
134  
135 0 ▶sub position {
Subroutine position: not called CC=3 SCAR=24.8
Pod documented
136 0 my $self = shift;
137  
138 # FIXME: optimieren
139  
140 0 my $ax = $self->{'axis'};
141 0 my $length = $ax->{'length'};
142 0 my $logarithmic = $ax->try('logarithmic'); # nur bei numerischer Achse
143 0 my $min = $ax->{'min'};
144 0 ▶ if ($logarithmic) {
Branch: 1 branch
BranchTrueFalseTotal
if ($logarithmic) 0 0 0
145 0 $min = POSIX::log10($min);
146 }
147 0 my $max = $ax->{'max'};
148 0 ▶ if ($logarithmic) {
Branch: 1 branch
BranchTrueFalseTotal
if ($logarithmic) 0 0 0
149 0 $max = POSIX::log10($max);
150 }
151 0 my $val = $self->{'value'};
152  
153 0 return Quiq::Math->valueToPixel($length,$min,$max,$val);
154 }
155  
156 # -----------------------------------------------------------------------------
157  
158 =head3 label() - Tick-Label
159  
160 =head4 Synopsis
161  
162 $label = $tik->label;
163  
164 =head4 Description
165  
166 Liefere das Tick-Label, also die Achsenbeschriftung.
167  
168 =cut
169  
170 # -----------------------------------------------------------------------------
171  
172 0 ▶sub label {
Subroutine label: not called CC=1 SCAR=6.9
Pod documented
173 0 my $self = shift;
174  
175 0 my $ax = $self->{'axis'};
176 0 my $val = $self->{'value'};
177  
178 0 return $ax->label($val);
179 }
180  
181 # -----------------------------------------------------------------------------
182  
183 =head3 width() - Breite des Tick
184  
185 =head4 Synopsis
186  
187 $width = $tik->width;
188  
189 =head4 Description
190  
191 Liefere die Breite des Tick. Bei einem Tick mit Label wird die Breite
192 des Tick von seinem Label bestimmt.
193  
194 =cut
195  
196 # -----------------------------------------------------------------------------
197  
198 0 ▶sub width {
Subroutine width: not called CC=1 SCAR=6.9
Pod documented
199 0 my $self = shift;
200  
201 0 my $ax = $self->{'axis'};
202 0 my $fnt = $ax->font;
203 0 my $val = $self->{'value'};
204 0 my $label = $ax->label($val);
205  
206 0 return $fnt->stringWidth($label)+1; # +1 für zusätzlichen Leerraum
207 }
208  
209 # -----------------------------------------------------------------------------
210  
211 =head3 height() - Höhe des Tick
212  
213 =head4 Synopsis
214  
215 $height = $tik->height;
216  
217 =head4 Description
218  
219 Liefere die Höhe des Tick. Bei einem Tick mit Label wird die Höhe
220 des Tick von seinem Label bestimmt.
221  
222 =cut
223  
224 # -----------------------------------------------------------------------------
225  
226 0 ▶sub height {
Subroutine height: not called CC=1 SCAR=6.9
Pod documented
227 0 my $self = shift;
228  
229 0 my $ax = $self->{'axis'};
230 0 my $fnt = $ax->font;
231 0 my $val = $self->{'value'};
232 0 my $label = $ax->label($val);
233  
234 0 return $fnt->stringHeight($label);
235 }
236  
237 # -----------------------------------------------------------------------------
238  
239 =head1 VERSION
240  
241 1.240
242  
243 =head1 AUTHOR
244  
245 Frank Seitz, L<http://fseitz.de/>
246  
247 =head1 COPYRIGHT
248  
249 Copyright (C) 2026 Frank Seitz
250  
251 =head1 LICENSE
252  
253 This code is free software; you can redistribute it and/or modify
254 it under the same terms as Perl itself.
255  
256 =cut
257  
258 # -----------------------------------------------------------------------------
259  
260 4 1;
261  
262 # eof
« Quiq/Html/Form/Layout.pm ↑ Summary Quiq/System.pm »