line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Map::Tube::GraphViz::Utils; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Pragmas. |
4
|
3
|
|
|
3
|
|
30094
|
use base qw(Exporter); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
288
|
|
5
|
3
|
|
|
3
|
|
15
|
use strict; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
81
|
|
6
|
3
|
|
|
3
|
|
11
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
78
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Modules. |
9
|
3
|
|
|
3
|
|
1318
|
use Error::Pure qw(err); |
|
3
|
|
|
|
|
27311
|
|
|
3
|
|
|
|
|
57
|
|
10
|
3
|
|
|
3
|
|
173
|
use Readonly; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
1384
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# Constants. |
13
|
|
|
|
|
|
|
Readonly::Array our @EXPORT_OK => qw(node_color node_color_id |
14
|
|
|
|
|
|
|
node_color_without_label color_line); |
15
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
our $VERSION = 0.06; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Create GraphViz color node. |
24
|
|
|
|
|
|
|
sub node_color { |
25
|
0
|
|
|
0
|
1
|
|
my ($obj, $node) = @_; |
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
|
|
|
0
|
1
|
|
my ($obj, $node) = @_; |
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
|
|
|
0
|
1
|
|
my ($obj, $node) = @_; |
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
|
|
|
0
|
1
|
|
my ($obj, $line) = @_; |
62
|
0
|
|
0
|
|
|
|
my $line_name = $line->id || $line->name; |
63
|
0
|
0
|
|
|
|
|
if (! exists $obj->{'_color_line'}->{$line_name}) { |
64
|
0
|
0
|
|
|
|
|
if ($line->color) { |
65
|
0
|
|
|
|
|
|
$obj->{'_color_line'}->{$line_name} = $line->color; |
66
|
|
|
|
|
|
|
} else { |
67
|
0
|
0
|
|
|
|
|
if (! exists $obj->{'_color_index'}) { |
68
|
0
|
|
|
|
|
|
$obj->{'_color_index'} = 0; |
69
|
|
|
|
|
|
|
} else { |
70
|
0
|
|
|
|
|
|
$obj->{'_color_index'}++; |
71
|
0
|
0
|
|
|
|
|
if ($obj->{'_color_index'} > $#COLORS) { |
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
|
|
|
0
|
|
|
my ($obj, $node) = @_; |
85
|
0
|
|
|
|
|
|
my @node_lines = @{$node->line}; |
|
0
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my %params; |
87
|
0
|
0
|
|
|
|
|
if (@node_lines == 1) { |
88
|
0
|
|
|
|
|
|
%params = ( |
89
|
|
|
|
|
|
|
'style' => 'filled', |
90
|
|
|
|
|
|
|
'fillcolor' => color_line($obj, $node_lines[0]), |
91
|
|
|
|
|
|
|
); |
92
|
|
|
|
|
|
|
} else { |
93
|
0
|
|
|
|
|
|
%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
|
|
|
|
|
|
|
1; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
__END__ |