| 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_id | |||||||||||||||||||
| 14 | node_color_without_label 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.06; | |||||||||||||||||||
| 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 with id as label. | ||||||||||||||||||||
| 36 | sub node_color_id { | ||||||||||||||||||||
| 37 | 0 | ▶ | my ($obj, $node) = @_; | ||||||||||||||||||
|
Subroutine
node_color_id: 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' => $node->id, | ||||||||||||||||||||
| 41 | 'name' => $node->id, | ||||||||||||||||||||
| 42 | %params, | ||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||
| 44 | 0 | return; | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | # Create GraphViz color node without label. | ||||||||||||||||||||
| 48 | sub node_color_without_label { | ||||||||||||||||||||
| 49 | 0 | ▶ | my ($obj, $node) = @_; | ||||||||||||||||||
|
Subroutine
node_color_without_label: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 50 | 0 | my %params = _node_color_params($obj, $node); | |||||||||||||||||||
| 51 | 0 | $obj->{'g'}->add_node( | |||||||||||||||||||
| 52 | 'label' => '', | ||||||||||||||||||||
| 53 | 'name' => $node->id, | ||||||||||||||||||||
| 54 | %params, | ||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||
| 56 | 0 | return; | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | # Get line color. | ||||||||||||||||||||
| 60 | sub color_line { | ||||||||||||||||||||
| 61 | 0 | ▶ | my ($obj, $line) = @_; | ||||||||||||||||||
|
Subroutine
color_line: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||
| 62 | 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
| |||||||||||||||||||||
| 63 | 0 | ▶ | if (! exists $obj->{'_color_line'}->{$line_name}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | 0 | ▶ | if ($line->color) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 65 | 0 | $obj->{'_color_line'}->{$line_name} = $line->color; | |||||||||||||||||||
| 66 | } else { | ||||||||||||||||||||
| 67 | 0 | ▶ | if (! exists $obj->{'_color_index'}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 68 | 0 | $obj->{'_color_index'} = 0; | |||||||||||||||||||
| 69 | } else { | ||||||||||||||||||||
| 70 | 0 | $obj->{'_color_index'}++; | |||||||||||||||||||
| 71 | 0 | ▶ | if ($obj->{'_color_index'} > $#COLORS) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 72 | 0 | err "No color for line '$line'."; | |||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | 0 | my $rand_color = $COLORS[$obj->{'_color_index'}]; | |||||||||||||||||||
| 76 | 0 | $obj->{'_color_line'}->{$line_name} = $rand_color; | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | } | ||||||||||||||||||||
| 79 | 0 | return $obj->{'_color_line'}->{$line_name}; | |||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | # Get color node parameters. | ||||||||||||||||||||
| 83 | sub _node_color_params { | ||||||||||||||||||||
| 84 | 0 | ▶ | my ($obj, $node) = @_; | ||||||||||||||||||
|
Subroutine
_node_color_params: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 85 | 0 | my @node_lines = @{$node->line}; | |||||||||||||||||||
| 86 | 0 | my %params; | |||||||||||||||||||
| 87 | 0 | ▶ | if (@node_lines == 1) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 88 | 0 | %params = ( | |||||||||||||||||||
| 89 | 'style' => 'filled', | ||||||||||||||||||||
| 90 | 'fillcolor' => color_line($obj, $node_lines[0]), | ||||||||||||||||||||
| 91 | ); | ||||||||||||||||||||
| 92 | } else { | ||||||||||||||||||||
| 93 | %params = ( | ||||||||||||||||||||
| 94 | 'style' => 'wedged', | ||||||||||||||||||||
| 95 | 'fillcolor' => (join ':', map { | ||||||||||||||||||||
| 96 | 0 | color_line($obj, $_); | |||||||||||||||||||
| 97 | } @node_lines), | ||||||||||||||||||||
| 98 | ); | ||||||||||||||||||||
| 99 | } | ||||||||||||||||||||
| 100 | 0 | return %params; | |||||||||||||||||||
| 101 | } | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | 3 | 1; | |||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | __END__ | ||||||||||||||||||||