GraphViz/Utils.pm

filter: Statementstmt 38.7% 19 / 49 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 55.5% 5 / 9 Podpod 100% 3 / 3 totaltotal 35.5% 27 / 76 CC 7 SCAR 29.0
CC
7
Cov
31%
color_line
42.0
_node_color_params
6.0
node_color
2.0
CRAP 18.2
↑ Summary GraphViz.pm »
1 package Map::Tube::GraphViz::Utils;
2  
3 # Pragmas.
4 3 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # Modules.
9 3 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # Constants.
13 3 Readonly::Array our @EXPORT_OK => qw(node_color node_color_without_label
14 color_line);
15 3 Readonly::Array our @COLORS => qw(red green yellow cyan magenta blue grey
16 orange brown white greenyellow red4 violet tomato cadetblue aquamarine
17 lawngreen indigo deeppink darkslategrey khaki thistle peru darkgreen
18 );
19  
20 # Version.
21 3 our $VERSION = 0.05;
22  
23 # Create GraphViz color node.
24 sub node_color {
25 0 ▶ my ($obj, $node) = @_;
Subroutine node_color: not called CC=1 SCAR=6.9
Pod documented
26 0 my %params = _node_color_params($obj, $node);
27 0 $obj->{'g'}->add_node(
28 'label' => $node->name,
29 'name' => $node->id,
30 %params,
31 );
32 0 return;
33 }
34  
35 # Create GraphViz color node without label.
36 sub node_color_without_label {
37 0 ▶ my ($obj, $node) = @_;
Subroutine node_color_without_label: not called CC=1 SCAR=6.9
Pod documented
38 0 my %params = _node_color_params($obj, $node);
39 0 $obj->{'g'}->add_node(
40 'label' => '',
41 'name' => $node->id,
42 %params,
43 );
44 0 return;
45 }
46  
47 # Get line color.
48 sub color_line {
49 0 ▶ my ($obj, $line) = @_;
Subroutine color_line: not called CC=6 SCAR=37.4
Pod documented
50 0 ▶ my $line_name = $line->id || $line->name;
Condition0%0/3
$line->id || $line->name
l!l&&r!l&&!r
000
MC/DC0%0/2
$line->id || $line->name
$line->id $line->name
Truth table0%0/3
A || B
A= $line->idB= $line->name
ABresult
1X1
011
000
51 0 ▶ if (! exists $obj->{'_color_line'}->{$line_name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $obj->{"_color_line"}{$line_name}) 0 0 0
52 0 ▶ if ($line->color) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line->color) { } 0 0 0
53 0 $obj->{'_color_line'}->{$line_name} = $line->color;
54 } else {
55 0 ▶ if (! exists $obj->{'_color_index'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $obj->{'_color_index'}) { } 0 0 0
56 0 $obj->{'_color_index'} = 0;
57 } else {
58 0 $obj->{'_color_index'}++;
59 0 ▶ if ($obj->{'_color_index'} > $#COLORS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->{"_color_index"} > $#Map::Tube::GraphViz::Utils::COLORS) 0 0 0
60 0 err "No color for line '$line'.";
61 }
62 }
63 0 my $rand_color = $COLORS[$obj->{'_color_index'}];
64 0 $obj->{'_color_line'}->{$line_name} = $rand_color;
65 }
66 }
67 0 return $obj->{'_color_line'}->{$line_name};
68 }
69  
70 # Get color node parameters.
71 sub _node_color_params {
72 0 ▶ my ($obj, $node) = @_;
Subroutine _node_color_params: not called CC=2 SCAR=17.9
73 0 my @node_lines = @{$node->line};
74 0 my %params;
75 0 ▶ if (@node_lines == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@node_lines == 1) { } 0 0 0
76 0 %params = (
77 'style' => 'filled',
78 'fillcolor' => color_line($obj, $node_lines[0]),
79 );
80 } else {
81 %params = (
82 'style' => 'wedged',
83 'fillcolor' => (join ':', map {
84 0 color_line($obj, $_);
85 } @node_lines),
86 );
87 }
88 0 return %params;
89 }
90  
91 3 1;
92  
93 __END__
↑ Summary GraphViz.pm »