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