Label.pm

filter: Statementstmt 15.2% 14 / 92 Branchbran 0.0% 0 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 13.7% 4 / 29 Podpod 95.6% 22 / 23 totaltotal 24.6% 40 / 162 SCAR 48.3
CC
13
Cov
13%
getTextString
132.0
allInsets
12.0
new
2.0
CRAP 125.3
« Node.pm ↑ Summary Node/GenericNode.pm »
1 package yEd::Label;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use yEd::PropertyBasedObject;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 yEd::Label - Textlabels for Nodes and Edges
11  
12 =head1 DESCRIPTION
13  
14 This is the base class for Labels.
15 It may not be instanciated, instead use one of the specialized types:
16  
17 =over 4
18  
19 =item *
20  
21 L<yEd::Label::EdgeLabel> Label for Edges, see documentation for additional EdgeLabel properties
22  
23 =item *
24  
25 L<yEd::Label::NodeLabel> Label for Nodes, see documentation for additional NodeLabel properties
26  
27 =back
28  
29 =head1 SUPPORTED FEATURES
30  
31 Labels are supported for both, Nodes and Edges.
32 However there are some features which are currently not supported:
33  
34 =over 4
35  
36 =item *
37  
38 Smart Labels: Because they offer few advantages over the other types and are much more complex to implement.
39  
40 =item *
41  
42 configuration of the Preferred Placement Descriptors: As they seem to only have an effect on Smart Labels (and do only exist for Labels on Edges).
43  
44 =item *
45  
46 SVG content (icons) for Labels
47  
48 =back
49  
50 All other types and features of Labels (yEd Version 3.13) are supported.
51  
52 For the available types (positioning modells) see the documentation of the specialized Labels.
53  
54 Other than in yEd itself you may add more than one Label to a single Node or Edge, regardless of its type.
55 In fact some special Nodes in yEd have multiple Labels per default (e.g. tables), so yEd will handle this correctly.
56  
57 =head1 PROPERTIES
58  
59 =head2 text
60  
61 Type: anything
62  
63 Default: ... must be supplied
64  
65 The text to be displayed by the Label.
66  
67 If this is a blessed ref it will try to find a toString or to_string method with the fallback of standard perl stringification.
68  
69 If this is an array ref each entry will be treated as a line of text.
70  
71 If this is a hash ref its content will be formated like so:
72  
73 key1: value
74 key2: val2
75 another key: val3
76  
77 =head2 visible
78  
79 Type: bool
80  
81 Default: true
82  
83 Whether the Label is visible or not (rather useless).
84  
85 =head2 x
86  
87 Type: float
88  
89 Default: 0
90  
91 The x position of the Label (ignored in most positioning modells).
92  
93 =head2 y
94  
95 Type: float
96  
97 Default: 0
98  
99 The y position of the Label (ignored in most positioning modells).
100  
101 =head2 height
102  
103 Type: ufloat
104  
105 Default: 20
106  
107 The height of the Label (mostly ignored depending on autoSizePolicy).
108  
109 =head2 width
110  
111 Type: ufloat
112  
113 Default: 30
114  
115 The width of the Label (mostly ignored depending on autoSizePolicy).
116  
117 =head2 backgroundColor
118  
119 Type: '#0000fa' (rgb) or '#000000cc' (rgb + transparency) java.awt.Color hex form or 'none'
120  
121 Default: 'none'
122  
123 The background color of the Label.
124  
125 =head2 lineColor
126  
127 Type: '#0000fa' (rgb) or '#000000cc' (rgb + transparency) java.awt.Color hex form or 'none'
128  
129 Default: 'none'
130  
131 The border color of the Label.
132  
133 =head2 bottomInset
134  
135 Type: uint
136  
137 Default: 0
138  
139 The inset between Label border and text.
140  
141 =head2 topInset
142  
143 Type: uint
144  
145 Default: 0
146  
147 The inset between Label border and text.
148  
149 =head2 leftInset
150  
151 Type: uint
152  
153 Default: 0
154  
155 The inset between Label border and text.
156  
157 =head2 rightInset
158  
159 Type: uint
160  
161 Default: 0
162  
163 The inset between Label border and text.
164  
165 =head2 rotationAngle
166  
167 Type: float
168  
169 Default: 0
170  
171 Rotation of the whole Label.
172  
173 =head2 alignment
174  
175 Type: descrete values ( center | right | left )
176  
177 Default: 'center'
178  
179 The text alignment.
180  
181 =head2 fontFamily
182  
183 Type: Fontstring
184  
185 Default: 'Dialog'
186  
187 The font for the Label text.
188  
189 As fonts differs on systems and platforms, this is not a descrete values property, be sure to choose a proper value (e.g. look into a yEd created graphml).
190 The default font 'Dialog' seems to be always present.
191  
192 =head2 fontSize
193  
194 Type: uint
195  
196 Default: 12
197  
198 The font size.
199  
200 =head2 fontStyle
201  
202 Type: descrete values ( plain | bold | italic | bolditalic )
203  
204 Default: 'plain'
205  
206 The font style.
207  
208 =head2 textColor
209  
210 Type: '#0000fa' (rgb) or '#000000cc' (rgb + transparency) java.awt.Color hex form or 'none'
211  
212 Default: '#000000'
213  
214 The text color.
215  
216 =head2 underlinedText
217  
218 Type: bool
219  
220 Default: false
221  
222 Whether the text is underlined or not.
223  
224 =head1 SUBROUTINES/METHODS
225  
226 =cut
227  
228 sub new {
229 0 ▶ confess 'you may not instantiate a yEd::Label base class object';
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
230 }
231  
232 =head2 copy
233  
234 Creates a copy of this Label and returns it.
235  
236 You may optionally specify properties in the form 'property => value, ...' to change these properties for the returned copy.
237  
238 =cut
239  
240 sub copy {
241 0 ▶ my ($self, @p) = @_;
Subroutine copy: not called CC=1 SCAR=6.9
Pod documented
242 0 my $ref = ref $self;
243 0 my $o = $ref->new();
244 0 $o->setProperties($self->getProperties());
245 0 $o->setProperties(@p);
246 0 return $o;
247 }
248  
249 sub _init {
250 0 ▶ my ($self, $text, @properties) = @_;
Subroutine _init: not called CC=1 SCAR=6.9
251 0 $self->text($text);
252 # defaults
253 0 $self->x(0);
254 0 $self->y(0);
255 0 $self->height(20);
256 0 $self->width(30);
257 0 $self->alignment('center');
258 0 $self->fontFamily('Dialog');
259 0 $self->fontSize(12);
260 0 $self->fontStyle('plain');
261 0 $self->textColor('#000000');
262 0 $self->visible(1);
263 0 $self->backgroundColor('none');
264 0 $self->lineColor('none');
265 0 $self->underlinedText(0);
266 0 $self->allInsets(0);
267 0 $self->rotationAngle(0);
268 # user values
269 0 $self->setProperties(@properties);
270 0 return $self;
271 }
272  
273 sub text {
274 0 ▶ return _PROPERTY(0, @_);
Subroutine text: not called CC=1 SCAR=6.9
Pod documented
275 }
276  
277 =head2 getTextString
278  
279 While the 'text' property will return the set value (which may be a ref), this will return the text form of the property as it will be shown in yEd.
280  
281 Have a look at the 'text' property description for details.
282  
283 =cut
284  
285 1 my @knownStringifier = ('toString', 'to_String');
286 sub getTextString {
287 0 ▶ my $self = shift;
Subroutine getTextString: not called CC=11 SCAR=48.8
Pod documented
288 0 my $text = $self->text();
289 0 my $ref = ref $text;
290 0 ▶ if ($ref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref) 0 0 0
291 0 ▶ if ($ref eq 'ARRAY') {
Branch: 3 branches
BranchTrueFalseTotal
if ($ref eq 'ARRAY') { } 0 0 0
elsif (UNIVERSAL::isa($text, 'UNIVERSAL')) { } 0 0 0
elsif ($ref eq 'HASH') { } 0 0 0
292 0 return join "\n", @{$text};
293 } elsif (UNIVERSAL::isa($text,'UNIVERSAL')) {
294 0 foreach my $toStr (@knownStringifier) {
295 0 ▶ return $text->$toStr() if $text->can($toStr);
Branch: 1 branch
BranchTrueFalseTotal
if $text->can($toStr) 0 0 0
296 0 $toStr = lc $toStr;
297 0 ▶ return $text->$toStr() if $text->can($toStr);
Branch: 1 branch
BranchTrueFalseTotal
if $text->can($toStr) 0 0 0
298 }
299 } elsif ($ref eq 'HASH') {
300 0 my @keys = sort keys %{$text};
301 0 my $l = 0;
302 0 foreach my $k (@keys) {
303 0 $k =~ m/^(?:_\d+_)?(.*)$/;
304 0 ▶ $l = length($1) if (length($1) > $l);
Branch: 1 branch
BranchTrueFalseTotal
if length $1 > $l 0 0 0
305 }
306 0 $l++;
307 0 my $t = '';
308 0 foreach my $k (@keys) {
309 0 $k =~ m/^(?:_\d+_)?(.*)$/;
310 0 $t .= sprintf("%-${l}s %s\n", $1 . ':', $text->{$k});
311 }
312 0 return $t;
313 }
314 }
315 0 return "$text"; # stringify everthing else by using perl defaults
316 }
317  
318 # Labelarea
319 sub visible {
320 0 ▶ return _PROPERTY('bool', @_);
Subroutine visible: not called CC=1 SCAR=6.9
Pod documented
321 }
322 sub x {
323 0 ▶ return _PROPERTY($match{'float'}, @_);
Subroutine x: not called CC=1 SCAR=6.9
Pod documented
324 }
325 sub y {
326 0 ▶ return _PROPERTY($match{'float'}, @_);
Subroutine y: not called CC=1 SCAR=6.9
Pod documented
327 }
328 sub height {
329 0 ▶ return _PROPERTY($match{'ufloat'}, @_);
Subroutine height: not called CC=1 SCAR=6.9
Pod documented
330 }
331 sub width {
332 0 ▶ return _PROPERTY($match{'ufloat'}, @_);
Subroutine width: not called CC=1 SCAR=6.9
Pod documented
333 }
334 sub backgroundColor {
335 0 ▶ return _PROPERTY($match{'color'}, @_);
Subroutine backgroundColor: not called CC=1 SCAR=6.9
Pod documented
336 }
337 sub lineColor {
338 0 ▶ return _PROPERTY($match{'color'}, @_);
Subroutine lineColor: not called CC=1 SCAR=6.9
Pod documented
339 }
340 sub bottomInset {
341 0 ▶ return _PROPERTY($match{'uint'}, @_);
Subroutine bottomInset: not called CC=1 SCAR=6.9
Pod documented
342 }
343 sub leftInset {
344 0 ▶ return _PROPERTY($match{'uint'}, @_);
Subroutine leftInset: not called CC=1 SCAR=6.9
Pod documented
345 }
346 sub rightInset {
347 0 ▶ return _PROPERTY($match{'uint'}, @_);
Subroutine rightInset: not called CC=1 SCAR=6.9
Pod documented
348 }
349 sub topInset {
350 0 ▶ return _PROPERTY($match{'uint'}, @_);
Subroutine topInset: not called CC=1 SCAR=6.9
Pod documented
351 }
352  
353 =head2 allInsets
354  
355 This is an alternative setter for the inset properties.
356  
357 It takes one or two parameters, where the first one will set bottom and top (or all insets if there is no second parameter) and the second will set left and right.
358  
359 =cut
360  
361 sub allInsets {
362 0 ▶ my ($self, $i1, $i2) = @_;
Subroutine allInsets: not called CC=3 SCAR=24.8
Pod documented
363 0 ▶ confess 'allInsets will only set insets, specify 1 or 2 args (top/bottom , left/right)' unless (defined $i1);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $i1 0 0 0
364 0 ▶ $i2 = $i1 unless (defined $i2);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $i2 0 0 0
365 0 $self->bottomInset($i1);
366 0 $self->topInset($i1);
367 0 $self->rightInset($i2);
368 0 $self->leftInset($i2);
369 0 return;
370 }
371 sub rotationAngle {
372 0 ▶ return _PROPERTY($match{'float'}, @_);
Subroutine rotationAngle: not called CC=1 SCAR=6.9
Pod documented
373 }
374  
375 # Font
376 sub alignment {
377 0 ▶ return _PROPERTY($match{'alignment'}, @_);
Subroutine alignment: not called CC=1 SCAR=6.9
Pod documented
378 }
379 sub fontFamily {
380 0 ▶ return _PROPERTY(0, @_);
Subroutine fontFamily: not called CC=1 SCAR=6.9
Pod documented
381 }
382 sub fontSize {
383 0 ▶ return _PROPERTY($match{'uint'}, @_);
Subroutine fontSize: not called CC=1 SCAR=6.9
Pod documented
384 }
385 sub fontStyle {
386 0 ▶ return _PROPERTY($match{'fontstyle'}, @_);
Subroutine fontStyle: not called CC=1 SCAR=6.9
Pod documented
387 }
388 sub textColor {
389 0 ▶ return _PROPERTY($match{'color'}, @_);
Subroutine textColor: not called CC=1 SCAR=6.9
Pod documented
390 }
391 sub underlinedText {
392 0 ▶ return _PROPERTY('bool', @_);
Subroutine underlinedText: not called CC=1 SCAR=6.9
Pod documented
393 }
394  
395 sub _build {
396 0 ▶ confess 'you may not build a yEd::Label base class object, override this method in a specialized subclass';
Subroutine _build: not called CC=1 SCAR=6.9
397 }
398  
399 =head2 setProperties getProperties hasProperties
400  
401 As described at L<yEd::PropertyBasedObject>
402  
403 =head1 SEE ALSO
404  
405 L<yEd::Document> for further informations about the whole package
406  
407 L<yEd::PropertyBasedObject> for further basic information about properties and their additional functions
408  
409 L<yEd::Label::EdgeLabel> for information about specialized Label elements for Edges
410  
411 L<yEd::Label::NodeLabel> for information about specialized Label elements for Nodes
412  
413 =cut
414  
415  
416 1 1;
« Node.pm ↑ Summary Node/GenericNode.pm »